EE/ng-l20n — pull request #1 by stasm (2013-08-15 21:24:03+00:00)
Title: Language negotiation

I landed a number of changes to L20n post-beta-3 related to language negotiation that I thought you might want to use in ng-l20n. The most important change is that when using the manifest, L20n will negotiate the fallback chain of user-preferred languages on its own so you don't need to do it in ng-l20n anymore. Other changes are summarized below:

- `ctx.registerLocales` now takes two arguments: the default locale for the context and a list of all available locales,
- `ctx.requestLocales` is a new method which triggers language negotiation between the available locales, inluding the default locale (as defined via `ctx.registerLocales`), and the locales passed as arguments.
- `ctx.freeze` has been removed; it is replaced by `ctx.requestLocales`,
- `ctx.supportedLocales` is a new read-only property which holds the result of the language negotiation (i.e. the current fallback chain of locales).

In the pull request, I look at the first element of `ctx.supportedLocales` which is the language negotiated by L2n against user's navigator.language. If the value stored in localStorage is different, I use it by passing it to `requestLocales`. This method recreates the resources in the context, which is suboptimal. Ideally, we'd check localStorage before document.l10n is ready for the first time. The following bug tracks this idea in L20n:

* Bug [905586](https://bugzil.la/905586) - Allow developers to tap into language negotiation with a stored user's preference

See the following bugs for references of API changes:

- Bug [897862](https://bugzil.la/897862) - Context::registerLocales should take the default language as the first argument (added Context::requestLocales)
- Bug [904618](https://bugzil.la/904618) - Remove Contex::freeze in favor of requestLocales
- Bug [897865](https://bugzil.la/897865) - Ctxdata should have an API for setting and unsetting values
- Bug [904207](https://bugzil.la/904207) - Add ctx.supportedLocales