{{ non-standard_header() }}
Summary
The once
method is used to register a callback that will execute exactly once. If the L10n context is ready when L10n.once()
is called, the callback will be invoked immediately on the next tick of the event loop. If the L10n context is not ready when L10n.once()
is called (because the localization resources are still downloading), the callback will be invoked when the ready event of the L10n context fires.
Use L10n.once()
to schedule initialization tasks for when the localization is ready to be used.
If you need to run some logic every time the language changes or the L10n context is first created, use L10n.ready
instead.
Syntax
navigator.mozL10n.once(callback);
Parameters
-
callback
- The function to be executed once when the L10n context is or becomes ready.
Example
// mozL10n.once is the main entry point for the app. navigator.mozL10n.once(function showBody() { // <body> children are hidden until the UI is translated document.body.classList.remove('hidden'); // load frame_script.js for preview mode and show loading background if (!isPhone) { loader.load('js/frame_scripts.js'); } // Now initialize the rest of the app. init(); });
Specification
Not part of any specification.
See also
- {{domxref("L10n")}}
- {{domxref("L10n.ready")}}