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.

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.

Using L10n.once() is safer than registering a self-deregistering 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 hard to debug.

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 and/or when the L10n context first becomes ready (the 0th language change), use L10n.ready instead.




The function to be executed once when the L10n context is or becomes ready.


// mozL10n.once is the main entry point for the app.
navigator.mozL10n.once(function showBody() {
  // <body> children are hidden until the UI is translated

  // load frame_script.js for preview mode and show loading background
  if (!isPhone) {

  // Now initialize the rest of the app.


Not part of any specification.

See also

Document Tags and Contributors

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