tr()

The function translates the given combination (text, comment) into the requested language or the UI language if the lang argument is not given.

Synopsis

string tr(string sourceTerm, string comment = "" [, int|string|OaLanguage lang]);

Parameters

Parameter Description
sourceTerm The used term in the source/ Param language
comment A comment that modifies the translation. The default is an empty string.
lang An optional parameter for specifying a translation language to be used.

Error

The function throws an exception in case of errors (e.g.: invalid lang parameter).

Description

The function uses the sourceTerm to mark the text as translatable and retrieve the translation for it. The translation is taken from the translation files created with the Translator.

The translation can be made more precise by adding a comment. This enables the use of multiple translations for one source term, depending on which comment is added.

Note: The text and comment given should be a literal string (not an expression or variable) so that the step is able to extract given text and comment combination as translatable text.
Note: This function can be used to add translations if a lang string interface is not available.
Note: This function acts as a functional replacement for getCatStr() in conjunction with the use of the new Translator.

Making a dyn_string with a normal string and a translated string:

makeDynString("$1:" + tr("The target path on the Backup tab is empty!\nYour changes will not be saved!")));

Adding a translated tooltip:

cmdStartCtrlDbg.toolTipText = tr(\"Start Manager for Debugging and break new threads\");

Adding a label, but the translation remains only german:

string deText = tr("Update Translation", "", OaLanguage::de_AT);
Label1.text(deText);

Translating a string and substituting some placeholders via "subst" (string::subst):

DebugN(tr("The file $1 could not be read due to error $2").subst(fileName, eror));

With this, the constant string literal in the tr() function call can be extracted by projectTranslationUpdate() and during runtime the translated text will be shown with the $-Parameters replaced with given arguments.

Assignment

Multi-language capability

Availability

CTRL