Hello,

Is it possible to retrieve locale-file synchronously (right after the manifest 
file has been loaded)?


Here is my use-case:
1. I include the library as the last script in the head.
<script src="l20n.js"></script>

2. I include the localization manifest file.
<link rel="localization" href="browser.json">
{
  "locales": [
    "en",
    "ru"
  ],
  "resources": [
    "../locales/{{locale}}/website.l20n"
  ]
}

3. File "../locales/en/website.l20n":
```html
<happy[$user.gender] {
male: "He is happy!",
female: "She is happy!"
}>
```
File "../locales/ru/website.l20n":
```html
<happy[$user.gender] {
male: "Он счастлив!",
female: "Она счастлива!"
}>
```

4. I use Handlebars.js template engine to render pages:

File "message.hbs":
```html
<div class="message">{{localaze "happy" user}}</div>
```
Where ```user``` is Object passed to Handlebars.js before rendering. 

```localize``` is Handelbars helper function that translates text while 
rendering:
```js
Handlebars.registerHelper('l20n', function(msg, user){                
                    var localizedText = document.l10n.getSync(msg, user);
                    return new Handlebars.SafeString(localizedText);            
        
                });
```

Here is the point: Handlebars.js needs that website.l20n file has been loaded 
before rendering "message.hbs", because it uses "getSync" method of l20n.js 
while rendering "message.hbs".

Thank you.




_______________________________________________
tools-l10n mailing list
[email protected]
https://lists.mozilla.org/listinfo/tools-l10n

Reply via email to