Dynamic internationalization

Syntax

$input.internationalize(
    sourceLang: $sourceLang, 
    translate: $translate
)

Converts the text of the given language into an internationalized text.

{"en": $englishText, "de": $germanText}
    .internationalize(translate: $translate)

Combines texts in several languages into one internationalized text.

Parameters

Name Type Description Mandatory Default
input Text or dictionary with texts Either the text to be converted, or a dictionary mapping language abbreviations to texts in the respective language. yes
sourceLang String The language of the input string. Only relevant in the form with the single string as input. no The default language of the application
translate Truth value Whether to use the translation service to fill in the missing translations. If not all languages supported by the application have been specified for the construction of the internationalized string, and translation should not be used (or the translation service does not support all languages of the application) an internationalized string will be created, which will be displayed in the default language for some languages. no false

Return value

Type: Internationalized text

A value that can be displayed in the language of the logged in user. The input texts are combined to an internationalized text and optionally supplemented by generated translations of the translation service.

Examples

Internationalize single text

Make the English string "Hello world!" into an internationalized string (tl.model.i18n:I18NString). Populate the remaining languages supported by the application with translations generated by the translation service:

"Hello world".internationalize(lang:"en", translate: true)

Returns a value that would be rendered as "Hello world!" for a user with the language German.

Combine texts in multiple languages into one internationalized string.

{"en": "Hello world!", "de": "Hallo Welt!"}.internationalize()

Returns the same as the TL Script literal #("Hello world!"@en, "Hallo Welt!"@de) but can be used with dynamic values.