Labs/Jetpack/Reboot/JEP/113: Difference between revisions

From MozillaWiki
< Labs‎ | Jetpack‎ | Reboot‎ | JEP
Jump to navigation Jump to search
(Created page with '== JEP 113 - Localization == * Champion: Zbigniew Braniecki - gandalf@mozilla.com * Type: ? * Bug Ticket: * Status: ? === Proposal === Implement a set of API's allowing for je…')
 
No edit summary
 
(8 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 ===
* Is L10n part of a core?
* How do we manage URLs to resources in l20n case?
* How do we load/store files?
* How do we communicate with the common-pool resource
* Do we hook l10n into other API's or do we provide separate methods only?
* How do we cache common-pool?
* can we bind variables?


=== Dependencies & Requirements ===
=== Dependencies & Requirements ===
Line 20: Line 52:
* local urls
* local urls


=== API Methods ===


=== Internal 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


=== API Methods ===
=== Interdependencies ===


* addReference(url) - adds a l10n file for a locale
* [[Labs/Jetpack/Reboot/JEP/102|JEP 102 - Single UI Element]]
* getValue(l10n_id(, {params})) - loads an entity value
* [[Labs/Jetpack/Reboot/JEP/103|JEP 103 - Panel]]
* bindEntity(l10n_id, params) - binds entity to a set of variables. Makes an entity value update when one of params changes
* [[Labs/Jetpack/Reboot/JEP/107|JEP 107 - Page Mods]]
* more API may be hooked into other API's depending on what we want
* [[Labs/Jetpack/Reboot/JEP/112|JEP 112 - Context Menu]]
* locale(ab-CD) - switch locale
* [[Labs/Jetpack/Reboot/JEP/118|JEP 118 - JetpackID]]

Latest revision as of 21:13, 23 March 2010

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