l10n.js
The l10n.js lib used in Gaia, extracted from mozilla-b2g/gaia.
Please refer to
- App localization - A detailed guide on FxOS app localization.
Gaia l10n derived a lot from original webL10n. There's also l20n, but it's rarely used (recommended from FxOS 2.5). Now l20n is also deprecated, the succeeded localization system Project Fluent is never used in B2G OS.
KaiOS
KaiOS still uses l10n.js
as its localization lib.
Quick Start
Here’s a quick way to get a multilingual HTML page:
- index.html - need these metas and link to properties file
- sample.{locale}.properties - key value pair
test = test button
It will get values for each 'data-l10n-id' and fill the translation to element's textContent. Use code below in browser console to switch language and check if it's successfully translated.
navigator.mozL10n.language.code = 'en-US'; // 'zh-CN'
The sample/
demo works on Firefox, not Chrome.
Check App localization code best practices at MDN for l10n best practices.