Link Search Menu Expand Document

Advanced Features in i18n

Placeholder in XML Views

It is also possible to use the parameters directly in the XML view. There are several things to be aware of here. When getText("title", [parameter]) is called in the controller to the RessourceModel, the method sap/base/strings/formatMessage is used to implement the parameter. Since formatter can be used in certain UI5 controls, we can use this method in XML view as well. However, in order to call the method in the control, it must be declared beforehand.

Since version 1.69 this is possible directly in the XML view, before that the declaration must still be made in the controller. The Documentation for this is found here: Require Modules in XML View and Fragment

Usage in 1.69 and above

Instead of a custom formatter, the standard formatMessage is used here.

The xmlns="sap.m" and xmlns:core="sap.ui.core" can also be decleared in the mcv:View directly.

<Title xmlns="sap.m" xmlns:core="sap.ui.core"
  core:require="{ formatMessage: 'sap/base/strings/formatMessage' }"
  text="{
    parts: [
      'i18n>testString',
      'i18n>testString2'
    ],
    formatter: 'formatMessage'
  }"
/>

Usage in 1.68 and below

Here you have to point the formatter to the Controller where you point to the required formatMessage module.

<Title text="{
  parts: [
    'i18n>testString',
    'i18n>testString2'
  ],
  formatter: '.formatMessage'
}"/>
sap.ui.define([
  "sap/ui/core/mvc/Controller",
  "sap/base/strings/formatMessage",
  // ...
], function(Controller, formatMessage/*, ...*/) {
  "use strict";

  return Controller.extend("...", {
    formatMessage: formatMessage,
    // ...
  });
})

Result

Usage of Placeholder in i18n in XML Views
Usage of Placeholder in i18n in XML Views
Usage of Placeholder in i18n in XML Views
Screenshot of Placeholder in i18n in XML Views

Ressoures:

supportedLocales and fallbackLocale

To avoid unwanted requests for unavailable translation files, since UI5 version 1.77, you can provide supportedLocales and fallbackLocale in your app´s manifest.

For more information you can look at the official documentation or this awesome blog post: UI5 Documentation: Supported Locales and Fallback

UI5ers Buzz #54: I18n with supportedLocales and fallbackLocale configuration

Example from the blog post:

{
 "_version": "1.21.0",
 "sap.app": {
  "id": "sap.ui.demo.todo",
  "type": "application",
        "i18n": {
            "bundleUrl": "i18n/i18n.properties",
            "supportedLocales": ["en", "de"],
            "fallbackLocale": "en"
        },
        "title": ""
 },
 "sap.ui5": {
  "models": {
   "i18n": {
    "type": "sap.ui.model.resource.ResourceModel",
    "settings": {
     "bundleUrl": "i18n/i18n.properties",
     "supportedLocales": ["en", "de"],
     "fallbackLocale": "en"
    }
   }
  }
 }
}

ui5 tooling tasks

At the time of this writing, there are a couple of open source ui5-tooling tasks available that help with translation/internationlization efforts: