Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

L10n.get

Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

Non-standard
This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

Deprecated synchronous method for retrieving localization strings from app's resources. This function should be used only when direct manipulation on the strings is needed (etc. date/time formatting) and in all other UI related cases should be replaced with DOM attributes setting or L10n.setAttributes().

This method has also potential to generate race conditions. Please the asynchronous L10n.formatValue() method or manually make sure that any code that uses this method is not fired before l10n resources are loaded using L10n.once() or L10n.ready().

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 (synchronously!) 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

Document Tags and Contributors

 Contributors to this page: gandalf, stasm, chrisdavidmills
 Last updated by: gandalf,