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.

Revision 566355 of L10n.once

  • Revision slug: Web/API/L10n.once
  • Revision title: L10n.once
  • Revision id: 566355
  • Created:
  • Creator: stasm
  • Is current revision? No
  • Comment

Revision Content

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

Revision Source

<p>{{ non-standard_header() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>once</code> method is used to register a callback that will execute exactly once.&nbsp; If the <a href="/en-US/docs/Web/API/L10n">L10n</a> context is ready when <code>L10n.once()</code> is called, the callback will be invoked immediately on the next tick of the event loop. If the <a href="/en-US/docs/Web/API/L10n">L10n</a> context is not ready when <code>L10n.once()</code> is called (because the localization resources are still downloading), the callback will be invoked when the ready event of the L10n context fires.</p>
<p>Use <code>L10n.once()</code> to schedule initialization tasks for when the localization is ready to be used.</p>
<p>If you need to run some logic every time the language changes and/or when the <a href="/en-US/docs/Web/API/L10n">L10n</a> context first becomes ready (the 0th language change), use <a href="/en-US/docs/Web/API/L10n.ready"><code>L10n.ready</code></a> instead.</p>
<h2 id="Syntax">Syntax</h2>
<pre>
navigator.mozL10n.once(callback);</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
 <dt>
  <code>callback</code></dt>
 <dd>
  The function to be executed once when the <a href="/en-US/docs/Web/API/L10n">L10n</a> context is or becomes ready.</dd>
</dl>
<h2 id="Example">Example</h2>
<pre class="brush: js">
// mozL10n.once is the main entry point for the app.
navigator.mozL10n.once(function showBody() {
&nbsp; // &lt;body&gt; children are hidden until the UI is translated
&nbsp; document.body.classList.remove('hidden');

&nbsp; // load frame_script.js for preview mode and show loading background
&nbsp; if (!isPhone) {
&nbsp;&nbsp;&nbsp; loader.load('js/frame_scripts.js');
&nbsp; }

&nbsp; // Now initialize the rest of the app.
&nbsp; init();
});
</pre>
<h2 id="Specification" name="Specification">Specification</h2>
<p>Not part of any specification.</p>
<h2 id="See_also">See also</h2>
<ul>
 <li>{{domxref("L10n")}}</li>
 <li>{{domxref("L10n.ready")}}</li>
</ul>
Revert to this revision