Localization (i18n) in sapui5 for fragment.xml file not displaying

I have a button (create an application), if I click on the button, a fragmented dialog will appear. here I can show a fragmented dialog. but internalization (i18n) does not appear for fields. (For xml files that can show i18n , but for a fragment.xml file that i18n / cannot show)

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> 
+6
source share
4 answers

you must set the i18n resource model for the dialog fragment.

 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(); } 
+3
source

You can use aggregation dependents to associate a dialog with a view; you do not need to explicitly specify any models.

So, in your case, you will 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 use of dependency aggregation in SAPUI5? "for more details.

+12
source

This is most often the easiest way, especially. for a ResourceModel just install it globally:

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

Now you can refer to it everywhere in your application and bind to it just like you, you don’t need to ever set it again at the viewing level or even at the control level.

+1
source

I had the same problem, so setting up the model in the component globally and locally. It is working correctly.

 sap.ui.getCore().setModel(i18nModel, "i18n"); this.setModel(i18nModel, "i18n"); 
+1
source

Source: https://habr.com/ru/post/974727/


All Articles