Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to i18n model within XML view

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.

like image 311
z00bs Avatar asked Dec 04 '14 13:12

z00bs


1 Answers

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.

like image 68
Tristan Storch Avatar answered Oct 11 '22 19:10

Tristan Storch