Using in SAP UI5 (View, Controller, Adding comment in i18n)

Preface – This post is part of the UI5 Programs series.

i18n, which stands for internationalization, are Translatable Texts, all in a single place. It means a developer should keep all the texts of their app within i18n so that, in case it is required to have another version of the app with a different language, then all together, a copy of i18n can be made, and those texts can be converted into another language at once.

Suppose you have only one version that too in English; then you just need a single i18n file. In case you have multiple languages like English (Britsh and US separate), German and French. Then you will need to have these i18n files:

  • [default]
  • [for English – British]
  • [for English – US]
  • [for German]
  • [for French]

Once you create these files, you need to add them in Manifest as a resource bundle. Then, within a controller, you need to use them as per the language of the browser. You can also provide your own language switcher drop-down like this:

Language Switcher

In case the app is deployed over Fiori, and then you can take the language set within Fiori:

Fiori Language Settings

Guidelines of writing i18n

You can write the entire i18n file in the form of key= value as shown below, where the key will be then added overview and controller, and the value will be the one shown over UI.

title=Admin Panel
appTitle=Admin Panel
appDescription=Admin Panel for SAP
id=User ID
version=Ver 2.3.0

Which will look like this in the code editor:

i18n sample

But, SAP UI5 suggests the following as the guidelines for writing i18n in a correct and standardized way:

  1. All the keys should be written in a lowercase
  2. The values of i18n can contain parameters like {0}, {1}, {2}, … [This can be used for special dynamic conditions]
  3. For special characters, use Unicode escape sequences
  4. Add comments using ‘#’ before sets of texts that are for certain category like:
    #XMSG: title of App
    title=Admin App
    appTitle=Admin App
    appDescription=Admin App
    #XMSG: App Version for Local Use
    appVersion=Version 2.0.14
    #XMSG: Not Found texts
    NotFound=Not Found
    NotFound.text=Sorry, but the requested resource is not available.
    NotFound.description=Please check the URL and try again.
    noDataDescriptiont=No data found. Try adjusting the filter settings or check your service.
    #XFLD: Form Texts
    ServiceType=Service Type
    GroupID=Group ID


Adding i18n in Manifest File

Majorly, i18n is preconfigured within the manifest file. Anyhow, you can configure like shown below [it will be within “sap.ui5” object]:

"models": {
    "i18n": {
        "type": "sap.ui.model.resource.ResourceModel",
        "settings": {
            "bundleName": "YRR.YRR.i18n.i18n"


Using i18n in View

To use i18n in UI5 View (once it is already set as above in the manifest file), you need to just specify the value in the i18n file and use it for texts using the named model call, i.e. {i18n>text} where text is the key in i18n file with a value against it, like text = This is a text.

To understand better, we will specify everything in different sections and showcase the output:

i18n Content

title=Admin Panel
appDescription=App Description
id=User ID
fieldsMandatory=All the fields are mandatory.
version=Ver 2.3.0

View Content

<Button id="sideNavigationToggleButton" icon="sap-icon://menu2" type="Transparent" press="onCollapseExpandPress">
<OverflowToolbarLayoutData priority="NeverOverflow"/>
<core:Icon src="sap-icon://vehicle-repair"></core:Icon>
<Text text="{i18n>title}" wrapping="false">
<OverflowToolbarLayoutData priority="Disappear"/>
<Button text="Download User Excel" icon="sap-icon://excel-attachment" type="Transparent" press="onSelectExtendedUser"/>
<Text text="{i18n>version}" wrapping="false"/>
<!--<Button icon="sap-icon://bell" press="handleMessagePopoverPress"/>-->


i18n Example

As you can see, we have binded the title and version with i18n, but the button text ‘Download Excel’ is hardcoded.

Using i18n in Controller

To get i18n data in View, you can use the global model that was specified within the manifest. For Controller too, we fetch the same model. You can either fetch everytime you need it, or make it global for that controller by specifying the following within onInit function:

// Bundle for i18n 
this.oBundle = this.getOwnerComponent().getModel("i18n").getResourceBundle();

Once you have specified the above

Showing Message from i18n in MessageBox

Now, we will use the above bundle to fetch a text from our i18n:

// read msg from i18n model
sMsg = that.oBundle.getText("fieldsMandatory");

Now, the MessageBox will load the message from i18n, and you don’t have to hardcode the text within the controller.

Messagebox message from i18n



  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.