Rather than manually concatenating variables to localized strings, the i18next library has support for variable replacement.
For example, a welcome message using the user’s first name can be defined in a resource, such as, Welcome __userName__
. Then, in the display template, the translation can be invoked using a knockout object to set the userName
variable, such as:
<span data-bind="widgetLocaleText : {value:'welcome', attr:'innerText', params: {userName: firstName()}}"></span>
Note that in the JSON resource, a __doubleUnderscore__
notation marks the variables but, when the resource is invoked in HTML or JavaScript, the underscores are omitted. The i18Next library provides other mechanisms such as support for plurals. Refer to the i18next section for more information.