kaios-gaia-l10n

0.0.1 • Public • Published

l10n.js

The l10n.js lib used in Gaia, extracted from mozilla-b2g/gaia.

Please refer to

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
<head>
  <meta name="defaultLanguage" content="en-US" />
  <meta name="availableLanguages" content="en-US, zh-CN" />
  <link rel="localization" href="./locales/sample.{locale}.properties" />
  <script defer src="./l10n.js"></script> 
</head>
<body>
  <button data-l10n-id="test" title="click me!"></button>
</body>
  • 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.

Readme

Keywords

none

Package Sidebar

Install

npm i kaios-gaia-l10n

Weekly Downloads

7

Version

0.0.1

License

Apache 2.0

Unpacked Size

72.2 kB

Total Files

7

Last publish

Collaborators

  • jzhangs