Confirmed users
1,016
edits
No edit summary |
No edit summary |
||
(7 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
* Champion: Zbigniew Braniecki - gandalf@mozilla.com | * Champion: Zbigniew Braniecki - gandalf@mozilla.com | ||
* Type: ? | * Type: ? | ||
* Bug Ticket: | * Bug Ticket: https://bugzilla.mozilla.org/show_bug.cgi?id=549315 | ||
* Status: | * Status: In works | ||
=== Proposal === | === Proposal === | ||
Implement a set of API's allowing for jetpack localization | 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. | |||
<pre class="brush:js"> | |||
var _ = require('l10n').get | |||
console.info(_("Hello world!")) | |||
</pre> | |||
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: | |||
<pre class="brush:js"> | |||
var ctx = require('l10n').createContext() | |||
ctx.add('extension://locale/resource') | |||
console.info(ctx.value("entityId")) | |||
</pre> | |||
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 === | === Key Issues === | ||
* How do we manage URLs to resources in l20n case? | |||
* How do we | * How do we communicate with the common-pool resource | ||
* | * How do we cache common-pool? | ||
* | |||
=== Dependencies & Requirements === | === Dependencies & Requirements === | ||
* byte loading | * byte loading | ||
* local urls | * local urls | ||
=== API Methods === | === API Methods === | ||
* | * get(string) - simple gettext-like function | ||
* | * Context: | ||
* bindEntity(l10n_id, params) - binds entity to a set of variables. Makes an entity value update when one of params changes | ** add(url) - adds a l10n file for a locale | ||
* more API may be hooked into other API's depending on what we want | ** 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 === | === Interdependencies === | ||
Line 39: | Line 68: | ||
* [[Labs/Jetpack/Reboot/JEP/107|JEP 107 - Page Mods]] | * [[Labs/Jetpack/Reboot/JEP/107|JEP 107 - Page Mods]] | ||
* [[Labs/Jetpack/Reboot/JEP/112|JEP 112 - Context Menu]] | * [[Labs/Jetpack/Reboot/JEP/112|JEP 112 - Context Menu]] | ||
* [[Labs/Jetpack/Reboot/JEP/118|JEP 118 - JetpackID]] |