SAP Ui5-resourse Bundle

Source: Internet
Author: User
Tags i18n

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.