Hello,

I am currently using l20n for my project. And I would like to set the current 
locale depending on a query param 'locale' of the URL. I read 
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/L20n/L20n_Javascript_API
 and here is how I managed that (probaly not the best way to go) :

* I declared the manifest through `<link rel="localization" 
href="locales/manifest.json">` and this file contains :
```
{
  "locales": [ "en", "fr"],
  "default_locale": "en",
  "resources": ["{{locale}}/myFile.l20n"]
}
```
* I import the l20n.js script through <script type="text/javascript" 
src="js/lib/l20n-1.0.2.js" charset="UTF-8"/>

* Then I import some of my JS code, in order to set the locale :

```
var locale = localeQueryParam || navigator.language || 
navigator.browserLanguage // Assumes that 'localeQueryParam' is defined
var ctx = L20n.getContext();
var folder = locale.indexOf('fr') > -1 ? 'fr' : 'en';       // FIXME that could 
be nice if I can let l20n do the locale fallback
ctx.linkResource('./locales/' + folder + '/myFile.l20n');    // FIXME the path 
is also in 'manifest.json'
ctx.requestLocales();
```

This implementation is working properly, since we get the appropriate locale 
and the labels are found. However I do not like this because :

* The path to the bundles is defined in both the manifest.json file and my JS 
code. This is not convenient for defining new bundle files. I first tried to 
remove the link to the Manifest, but it leads to an error in the console, as 
l20n seems to depend on this file. On the other side, if I remove my JS code, I 
fear that the 'locale' query param would be ignored.
* A (poor) locale fallback mechanism is used in my JS code. I would like to let 
l20n cares about that.

Could you please give me an advice in order to set the 'locale' without the 
drawbacks that are previously mentioned ?
Perhaps there is some kind of `ctx.setCurrentLocale(locale)` method ?

Thanks in advance for your help,
Fabrice
_______________________________________________
tools-l10n mailing list
[email protected]
https://lists.mozilla.org/listinfo/tools-l10n

Reply via email to