Passing parameters to i18n model within XML view

z00bs picture z00bs · Dec 4, 2014 · Viewed 11.7k times · Source

How can we pass parameters to the i18n model from within a XML view?

Without parameters

<Label text="{i18n>myKey}"/>

works but how can we pass a parameter in that expression?

The only piece of information I've found so far is http://scn.sap.com/thread/3586754. I really hope that this is not the proper way to do it since this looks more like a (ugly) hack to me.

Answer

Tristan Storch picture Tristan Storch · Jun 12, 2016

The trick is to use the formatter jQuery.sap.formatMessage like this

<Label text="{parts:['i18n>myKey', 'someModel>/someProperty'], 
                    formatter: 'jQuery.sap.formatMessage'}"/>

This will take the value /someProperty in the model someModel and just stick it in myKey of your i18n resource bundle.

Edit 2020-05-19: jQuery.sap.formatMessage is deprecated as of UI5 version 1.58. Please use sap/base/strings/formatMessage. See this answer on usage instructions.