Show TOC

Use of Localized Texts in ApplicationsLocate this document in the navigation structure

SAPUI5 provides two options to use localized texts in applications: The module and data binding.


You can use the JavaScript module to access localized texts. The module contains APIs to load a resource bundle file from a given URL and for a given locale.

To make sure that the module is loaded, you have to require it as follows:"");

You can then use the function to load the resource bundle from the given URL, that is, the bundle name, and for a given locale. When no locale is specified, a default locale (en) is used. The following code snippet shows the use of the function to return a

var oBundle ={url : sUrl, locale: sLocale});

For more information, see in the API Reference.

The resource bundle provides access to the localized texts that are contained in the resource bundle. You can use the getText method to access the texts in the loaded bundle by means of their key. This is shown in the following code snippet:

var sText = oBundle.getText(sKey);	
Localization Test Page

The test suite provides a test page that shows how to use localized texts. This section only provides a short overview how the module is used there.

For a localized Web page you need the .html page itself and the .properties files of the required languages, in this example English and German.

The resource bundle is the English fallback version, which is the default version.

welcome=Welcome {0}. Please enter a new contact:
lastname=Last Name:
firstname=First Name:

The resource bundle contains the texts in German. The following code snippet shows the content of this file:

welcome=Willkommen {0}. Bitte geben Sie einen neuen Kontakt ein:

The localization test page uses these texts to display a welcome message and a form to enter the address of a person. The coding of the test page looks as follows:"");
var sLocale = sap.ui.getCore().getConfiguration().getLanguage();
var oBundle ={url : "res/", locale: sLocale});
var oMatrixLayout = new sap.ui.commons.layout.MatrixLayout();
  new sap.ui.commons.TextView({text: oBundle.getText("welcome", ["Administrator"])}) 
  new sap.ui.commons.Label({text: oBundle.getText("lastname")}), 
  new sap.ui.commons.TextField()
  new sap.ui.commons.Label({text: oBundle.getText("firstname")}), 
  new sap.ui.commons.TextField()
  new sap.ui.commons.Label({text: oBundle.getText("street")}), 
  new sap.ui.commons.Label({text: oBundle.getText("zip")}), 
  new sap.ui.commons.TextField()
  new sap.ui.commons.Label({text: oBundle.getText("city")}), 
  new sap.ui.commons.TextField()

With regard to localization, the code above defines the following procedure:

  1. Require the module
  2. Determine the language
  3. Load the resource bundle
  4. Access the text using the welcome key and pass the value for the placeholder ({0}) via an array
  5. Access the text using the lastname key and set it as text for the Label
Data Binding

You can also use data binding to access localized texts. The ResourceModel is a wrapper for resource bundles that exposes the localized texts as a model for data binding. You use the ResourceModel to bind texts for control properties to language dependent resource bundle properties. You can instantiate the ResourceModel either with bundleName (name of a resource bundle that equals a SAPUI5 module name within the require/declare concept), or a bundleUrl, which points to a resource bundle. When you use the bundle name, make sure that the file has a .properties suffix. If no locale is defined, the current language is used.

var oModel = new sap.ui.model.resource.ResourceModel({bundleName:"myBundle",bundleLocale:"en"});
var oControl = new sap.ui.commons.Button( {
    id : "myButton",
    text : "{i18n>MY_BUTTON_TEXT}"
// attach the resource model with the symbolic name "i18n"
oControl.setModel(oModel, "i18n");
Note The current data binding implementation does not allow to pass parameters to your texts in the resource bundle. If you have to pass parameters, you must do this on your own. You can, however, access the resource bundle directly from the model instead of loading it:
var myBundle = oModel.getResourceBundle()

After the instance has been created, you have a model containing the resource bundle texts as data.

For a complete overview of available methods and parameters, see ResourceModel in the API Reference in the Demo Kit