Skip to Content

Implementing labels using the i18n (internationalization) features of SAPUI5

Previous

Implementing labels using the i18n (internationalization) features of SAPUI5

By akula86

Utilize the i18n framework in SAPUi5 to extract "hard-coded" strings in your app and maintain them in a single file.

You will learn

In the previous tutorials you added some labels to the details view by inserting a title=���xxx��� XML snippet into an ObjectAttribute element. In this tutorial, you will extract those strings to the messageBundle.properties file (which you just used to insert the currency symbol) and insert a reference to them in place of the string literals in your app. The appearance of the app will not change, but having the strings in one place will make the app easier to maintain, and will enable the support of different languages and locales (which you will do as part of this series). The three labels you will work with in this tutorial are:

Details

  • Product ID
  • Units In Stock
  • Units On Order

  1. To begin, open the northwind > i18n > messageBundle.properties file and insert the three lines below.

    label_ProductID=Product ID
    label_UnitsInStock=Units In Stock
    label_UnitsOnOrder=Units On Order
    
    messageBundle.properties
  2. Following the same pattern used for the currency example: {i18n>key}, the three references you will use are in the Detail.view.xml file are:

    • {i18n>label_ProductID}
    • {i18n>label_UnitsInStock}
    • {i18n>label_UnitsOnOrder}

    Edit the Detail.view.xml file to replace the hard-coded title strings with the references above. Your file should look like this:

    Modified Detail.view.xml file

  3. Save your changes and reload the preview tab or run the app. The app should look the same, but the implementation is will simplify the support of other languages.

    Modified Detail.view.xml file

Next Step:

Updated 12/08/2016

Time to Complete

< 5 min

Beginner

Prerequisites

Next
Back to top