SAP UI5 - Localization


Advertisements

SAP UI5 supports localization concept based on Java platform.

Identifying the Language Code − For the identification of languages, the framework uses a language code of type string.

Resource Bundles − A resource bundle file is a Java properties file and contains key/value pairs where the values are language-dependent texts and the keys are language independent and used by the application to identify and access the corresponding values.

Resource bundles are a collection of *.properties files. All files are named with the same base name (prefix identifying the resource bundle), an optional suffix that identifies the language contained in each file, and the fixed .properties extension.

The language suffixes are formed according to the older JDK locale syntax. By convention, a file without a language suffix should exist and contain the raw untranslated texts in the developer's language. This file is used if no more suitable language can be found.

Resource bundle sap.ui.commons.message_bundle contains the following files −

  • sap.ui.commons.message_bundle.properties − This file carries the raw text from the developer and it determines the set of keys.

  • sap.ui.commons.message_bundle_en.properties − This file carries English text.

  • sap.ui.commons.message_bundle_en_US.properties − This file carries text in American English.

  • sap.ui.commons.message_bundle_en_UK.properties − This file carries text in British English.

Use of Localized Texts in Applications

SAPUI5 provides two options to use localized texts in applications – the jQuery.sap.resources module and data binding.

The following code is used to get resource bundle for a given language −

jQuery.sap.require(“jquery.sap.resources”);
var oBundle = jQuery.sap.resources({url ; sUrl, locale:sLocale});

The following code is used to access the text in resource bundle −

Var sText = oBundle.getText(sKey);

The following code is used to get URL of a resource −

Var sUrl = sap.ui.resource(“sap.ui.table”,”messagebundle.properties”);
Advertisements