6

I have a button (create Application) if i click on a button a fragmented dialog will be appearing . here am able to show fragmented dialog .but internalization(i18n) is not appearing for the fields. (For xml files able to show i18n but for fragment.xml file not able to show i18n/)

component.js:

createContent : function() {

        // create root view
        var oView = sap.ui.view({
            id : "app",
            viewName : "sap.gss.program.view.App",
            type : "JS",
            viewData : { component : this }
        });

        var i18nModel = new sap.ui.model.resource.ResourceModel({
            bundleUrl : "i18n/appTexts_fr.properties"
            });

        oView.setModel(i18nModel, "i18n");      
        return oView;
    }

Controller.js:

createApplication: function (oEvent) {

    if (!this.oDialogFragment) {
         this.oDialogFragment = sap.ui.xmlfragment("sap.gss.program.view.myFragment",
                                                   this);       
    }        
    this.oDialogFragment.open(); 

}

fragment.xml:

<core:FragmentDefinition
  xmlns="sap.m"
  xmlns:core="sap.ui.core"
  xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1">
  <Dialog
    title="{i18n>Title}"
    class="sapUiPopupWithPadding" >   
    <HBox> 
      <Text  text="{i18n>Description_TEXT}" > </Text>       
    </HBox>  
    <beginButton>
      <Button text="{i18n>Ok}"  press="DialogButton" />
    </beginButton>
    <endButton>
      <Button text="{i18n>Cancel}"  press="CloseButton" />
    </endButton>
  </Dialog>
</core:FragmentDefinition>
Markus W Mahlberg
  • 19,711
  • 6
  • 65
  • 89
arunk
  • 185
  • 2
  • 4
  • 14

4 Answers4

18

You can use the dependents aggregation, to connect up the dialog to the view; you don't need to set any models explicitly.

So in your case you would do this:

createApplication: function (oEvent) {
    if (!this.oDialogFragment) {
        this.oDialogFragment = sap.ui.xmlfragment("sap.gss.program.view.myFragment", this);
    }
    this.getView().addDependent(oDialogFragment); // <--
    this.oDialogFragment.open();
}

See my answer to 'What is the usage of "dependents" aggregation in SAPUI5?' for more details.

Community
  • 1
  • 1
qmacro
  • 3,025
  • 23
  • 33
3

you should set the i18n resource model for the dialog fragment as well.

createApplication: function(oEvent) {

    if (!this.oDialogFragment) {

        this.oDialogFragment = sap.ui.xmlfragment("sap.gss.program.view.myFragment", this);     
        var i18nModel = new sap.ui.model.resource.ResourceModel({
                            bundleUrl : "i18n/appTexts_fr.properties"
                        });
        this.oDialogFragment.setModel(i18nModel, "i18n");      

    }

   this.oDialogFragment.open();
}
Haojie
  • 5,665
  • 1
  • 15
  • 14
1

Its often the easiest way esp. for a ResourceModel to just set it globally:

sap.ui.getCore().setModel(i18nModel, "i18n");

Now you can reference it from everywhere in your application and bind to it like you did, no need to ever set it again on view- or even control-level.

cschuff
  • 5,502
  • 7
  • 36
  • 52
  • 1
    When you work in the Fiori Launchpad, you should NOT do this as it conflicts with other apps. – hirse May 10 '16 at 13:36
1

I had same problem, so setup model in Component globally and locally. It is working correctly.

sap.ui.getCore().setModel(i18nModel, "i18n");
this.setModel(i18nModel, "i18n");
hirse
  • 2,394
  • 1
  • 22
  • 24
  • This is fine as long as there are no Components involved. Otherwise, please avoid setting models on the Core. More: https://stackoverflow.com/a/42251431/ – Boghyon Hoffmann Jun 13 '18 at 12:08