Skip to content

kaios-design/gaia-l10n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published