translate

Typefunction
Dictionarylibrary.i18n
Libraryi18n library
Syntax
translate <pStringID>, [<pPluralisation>], [<pFormattingArray>], [<pContextArray>], [<pDefaultText>], [<pLocaleID>]
Associationscom.livecode.library.i18n
Summary

get a text string from the i18n package.

Parameters
NameTypeDescription
pStringID

It is the translation tag. These cannot vary from one package to another.

pPluralisation

A number that is used to look up the corresponding pluralization within the current i18n packet.

pFormattingArray

Sometimes you want to mix variables in the text you are translating. Well, this parameter is what allows us to do this. It is an array with the format key value. Where the key is the text that is searched for in the string resolved by the translate function before returning it. The value of each key will be replaced in the string by %{ key }.

pContextArray

The context of the translation. This array has a defined structure, so it must be passed with it or it will be ignored. This structure is as follows:

Must be an ordered array, so all first level keys must be an integer. Each element of the array is another array with two keys, with the following structure: - matches: It is an array of a single key, with the structure . What will be the condition that must be met for the translation to have this context. - values: The values that the translation tags will have in this context.

pDefaultText

The string to return if a string cannot be resolved one for the passed parameters.

pLocaleID

The id of the language pack.

Example
on mouseUp
   answer translate("Due in %n days", -2)   //  -> Due 2 days ago
end mouseUp
on mouseUp
   local tFormattingArray

   put "John" into tFormattingArray["name"]
   put translate("Welcome %{name}", tFormattingArray) // -> Welcome John
end mouseUp
on mouseUp
   local tFormattingArray, tContextArray

   put "John" into tFormattingArray["name"]
   put "male" into tContextArray["gender"]

   # John updated his profile
   put translate("%{name} updated their profile", tFormattingArray, tContextArray)

   put "Jane" into tFormattingArray["name"]
   put "female" into tContextArray["gender"]

   # Jane updated her profile
   put translate("%{name} updated their profile", tFormattingArray, tContextArray)
end mouseUp
on mouseUp
   local tFormattingArray, tContextArray

   put "John" into tFormattingArray["name"]
   put "Buck's Night" into tFormattingArray["album"]
   put "male" into tContextArray["gender"]

   #  John uploaded 1 photo to his Buck's Night album
   put translate("%{name} uploaded %n photos to their %{album} album", 1, tFormattingArray, tContextArray)

   put "Jane" into tFormattingArray["name"]
   put "Hen's Night" into tFormattingArray["album"]
   put "female" into tContextArray["gender"]

   #  Jane uploaded 4 photos to her Hen's Night album
   put translate("%{name} uploaded %n photos to their %{album} album", 4, tFormattingArray, tContextArray)
end mouseUp
Description

Use the translate function to get the string corresponding to a translation tag in the current i18n package.

Tagsinternationalization,i18n,translation,languages,locale