{{ non-standard_header() }}
Summary
The ready
method is used to register a callback that will execute at least once. The callback is registered as a listener to the ready
event of the L10n context. Additionally, if the L10n context is ready when L10n.ready()
is called, the callback will be invoked immediately on the next tick of the event loop.
Using L10n.ready()
is safer than registering a listener of the window's localized
event because it also works when the localized
event has already fired. This helps prevent intermittent race conditions which would be otherwise hard to debug.
L10n.ready()
is useful for executing code every time the language changes and/or when the L10n context first becomes ready (the 0th language change).
In order to schedule initialization tasks for when the localization is ready to be used for the first time and this time only, use L10n.once()
.
Syntax
navigator.mozL10n.ready(callback);
Parameters
-
callback
- The function to be executed everytime the L10n context is or becomes ready.
Example
navigator.mozL10n.ready(function showLanguageDescription() { var lang = navigator.mozL10n.language.code // display the current locale in the main panel Settings.getSupportedLanguages(function displayLang(languages) { document.getElementById('language-desc').textContent = languages[lang]; │ }); });
Specification
Not part of any specification.
See also
- {{domxref("L10n")}}
- {{domxref("L10n.once")}}