- text = tr(id)
- text = tr(message[, disambiguation|nil[, context|nil[, numerus]]])
SYNOPSIS
DESCRIPTION
This function supports translations of user visible text for multiple languages. The first form is uses Numeric Mode (see there), while the second form uses Contextual Mode.
In contextual mode, a few optional parameters help resolving disambiguities that occur when the same phrase in the source language needs to translate differently depending on its usage context. (For example, None in english might translate into Kein or Nichts in german.) To disambiguate between several uses of one phrase, pass a disambiguation comment as the disambiguation parameter.
The optional parameter context helps grouping translation phrases. When not given, the system uses the filename of the Lua source file as the name of the context, with the path and the file extension removed. The context name shows up in left hand panel of the Qt Linguist translation tool.
Some languages are quite complex when it comes to distinctions between singular, plural (and more, for some languages.) In order to support this, a number must be passed as the numerus parameter. Inside the message string, put %n at the place where the number needs to be inserted. The translation subsystem will do all the necessary magic for you.
The function asks all translators installed into the table tr.translators for a translation until a match is found. Translators are installed into the table by calling tr:installTranslator().
RETURN VALUE
If the lookup into the translation tables was successful, returns the translated text in UTF8 encoding, if not, returns the original string.
In both cases the replacement of %n by the numerus value is done.
NOTES
To pass a value for numerus, you might need to pass nil for disambiguation and context.
The number in "Found 42 matches." is a numerus, while the number in "Please pay $12.34" is not.
EXAMPLE
Numeric mode:
Contextual mode (note the singular form):