In multi-language considerations, control names need to be translated according to different languages, so in UI5 they are generally uniformly placed in a file, i18n.properties.
Try to bind this file today, all of the following code is in Display.view.js
1Createcontent:function(ocontroller) {2 varOmodel =NewSap.ui.model.resource.ResourceModel (3 {4Bundlename: "i18n",5Bundlelocale: "EN",6 }7 );8 varMybundle =Omodel.getresourcebundle ();9 Ten varObutton =NewSap.ui.commons.Button ({ OneID: "B1",//Sap.ui.core.ID A //text: "Tttttt", -Text:myBundle.getText ("Button_name")//string - }); the returnObutton; -}
The Omodel declared here is a resourcemodel,bundlename corresponding file name, Bundlelocale corresponding language,
The UI5 core Library automatically searches for files with path/resourece/i18n_zn.properties based on these two parameters.
Create a new text in this file:
Button_name=my BUTTON
When using Omodel.getresourcebundle (). GetText ("Button_name"), the corresponding string is automatically fetched in this file.
This is my BUTTON.
The effect is as follows:
This side of the file path defaults to/resource, a little less flexible, looking at the UI5 API, found that there is another parameter can be set
Bundleurl: The path filled in here is relative to the entire project
Create a i18n folder under WebContent, and put in the i18n_zh.properties file that you just
Resourcemodel is defined as follows:
1 varnew Sap.ui.model.resource.ResourceModel (2 {3 bundleurl: "./ I18n/i18n.properties ",4 bundlelocale:" zh ",5 }6 );
Test, success.
SAP Ui5-resourse Bundle