-
Notifications
You must be signed in to change notification settings - Fork 17
_y.T
Kerri Shotts edited this page Jan 29, 2014
·
1 revision
(part of _y)
Parameters:
-
key
- the lookup key -
parms
- optional, a dictionary of replacement variables -
locale
- optional, a specific locale
Returns: translated text, including replacement variables
Looks up key
in the translation matrix, and them calls template to fill in the replacement variables. The locale
, if specified overrides getUserLocale.
If the key
does not exist in the translation matrix, the region is first eliminated, in hopes that the language itself has a translation. If the translation is not found, en-US
is searched. If en-US
does not have a translation, en
is searched. If no translation is found, the key
is returned (with replacement variables replaced).
_y.addTranslation ( "en", "HELLO", "Hello" );
var text = _y.T("HELLO"); // Hello
_y.addTranslation ( "en-US", "HELLO_%NAME%", "Hello, %NAME%" );
_y.addTranslation ( "es", "HELLO_%NAME%", "Hola %NAME%" );
text = _y.T("HELLO_%NAME%", { "NAME": "Mary" }); // Hello, Mary
text = _y.T("HELLO_%NAME%", { "NAME": "Mary" }, "es-ES"); // Hola Mary
text = _y.T("GOODBYE_%NAME%", { "NAME": "Mary" }); // GOODBYE_Mary