Labs/Jetpack/Reboot/JEP/113

From MozillaWiki
< Labs‎ | Jetpack‎ | Reboot‎ | JEP
Jump to: navigation, search

JEP 113 - Localization

Proposal

Implement a set of API's allowing for jetpack localization

We're going to use double-approach:

  • common-pool solution for simple entities
  • l20n for more complex cases


Common pool example

If the jetpack uses just simple non-mutable entities like "OK", "Cancel", "Loading" it does make sense to use common pool.

var _ = require('l10n').get

console.info(_("Hello world!"))

Explanation:

  • Common pool is a pool of simple entities shared between multiple jetpacks.
  • The pool is cached by jetpack lib and available to all extensions
  • Localizers may overlay specific exceptions for given use of an entity in their language

L20n example

In case an entity is more complex (depends on a variable, plural forms, genders etc.) or developer expects that localizers may need more flexibility to make the best out of the entity, he should switch to l20n:

var ctx = require('l10n').createContext()

ctx.add('extension://locale/resource')

console.info(ctx.value("entityId"))

In this case, developer has to actually prepare the l20n resource that will be used, but it allows him to pass arguments to 'value' function so that localizers may be able to customize the string or use other features of l20n to generate best string.

Key Issues

  • How do we manage URLs to resources in l20n case?
  • How do we communicate with the common-pool resource
  • How do we cache common-pool?

Dependencies & Requirements

  • byte loading
  • local urls

API Methods

  • get(string) - simple gettext-like function
  • Context:
    • add(url) - adds a l10n file for a locale
    • value(l10n_id(, {params})) - loads an entity value
    • bindEntity(l10n_id, params) - (declarative) binds entity to a set of variables. Makes an entity value update when one of params changes
    • setLocale(ab-CD) - switch locale
    • more API may be hooked into other API's depending on what we want

Interdependencies