L20n.js

L20n implementation in JavaScript

View on GitHub

The JavaScript implementation of L20n. The parser, the compiler, the L20n context, plus HTML bindings to make them work on the web.

With L20n, we want to reinvent the way we're doing software localization. Users should be able to benefit from the entire expressive power of their languages.

L20n keeps simple things simple, and at the same time makes complex things possible.

A straight-forward example in English:

<brandName "Firefox">
<about "About {{ brandName }}">

And the same thing in Polish:

<brandName {
  nominative: "Firefox",
  genitive: "Firefoksa",
  dative: "Firefoksowi",
  accusative: "Firefoksa",
  instrumental: "Firefoksem",
  locative: "Firefoksie"
}>
<about "O {{ brandName.locative }}">

The API:

var ctx = L20n.getContext();
ctx.addResource('./locales/en-US/strings.lol');
ctx.freeze();

And lastly:

document.addEventListener('LocalizationReady', function() {
  var msg = ctx.get('about');
  alert(msg);
});

Or...

ctx.get('about', null, function(msg) {
  // `msg` is the value of the string returned by the context 
  // when all the LOL resources have been downloaded
  alert(msg);
}, 'Default fallback');

Documentation and tests