Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localization(i18n) in sapui5 for fragment.xml file in not appearing

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>
like image 437
arunk Avatar asked Sep 03 '14 05:09

arunk


3 Answers

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.

like image 77
qmacro Avatar answered Oct 20 '22 15:10

qmacro


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();
}
like image 37
Haojie Avatar answered Oct 20 '22 17:10

Haojie


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.

like image 1
cschuff Avatar answered Oct 20 '22 16:10

cschuff