{{ non-standard_header() }}
The get
method is used to retrieve translations from the localization resources, optionally interpolating them with additional variable data. If the translation is not found in the first supported locale, the L10n context will try the next locale in the fallback chain until it finds an available translation.
Translations may use the double brace syntax (\{{ placeable }}
) to introduce variables that will be resolved on runtime and interpolated into the final string return value. The variable values must be specified in the second argument to L20n.get()
and must be strings or numbers. If a variable fails to resolve, the final translation will contain the raw \{{ placeable }}
syntax.
When no translation is found, or, in rare cases, when the translation contains unrecoverable errors (e.g. a cyclic reference in a placeable), L10n.get()
will return an empty string. This behavior allows the developers to safely assume that the return value is always a string.
Syntax
var translation = navigator.mozL10n.get(identifier[, data]);
Parameters
-
identifier
- The string identifier of the translation to be retrieved.
-
data
- An object with variables to be interpolated into the translation. All members' values must be strings or numbers.
Returns
A translated string (in one of the supported locales) or an empty string if the translation was not found or contained errors.
Example
- dialer.en-US.properties:
-
from-contact = Missed call from \{{ contact }}
- dialer.js:
-
var _ = navigator.mozL10n.get; var body = _('from-contact', {contact: primaryInfo.toString()});
Specification
Not part of any specification.
See also
- {{domxref("L10n")}}