-
Notifications
You must be signed in to change notification settings - Fork 8
Internacionalization
To make internacionalization(i18n) works, just edit the package.json file, all you have to do is add an object i18n with a key languages that will be an array of languages code to support by your project, for example:
{
"settings": {
...
"i18n": {
"languages": [
"en",
"es"
],
...
},
...
},
...
}
Now let's extract the strings on files js, hbs and html:
$ wonkajs i18n
This will generate one file for each language code defined on package.json, wonka by default load the original string and if there's any value for this string, then load the value assigned on the language file.
Let's edit the file languages/es.json, isn't necessary translate the file languages/en.json, because our default language is "en" and the string that we wrote are english too.
{
"Science books": "Libros de ciencia"
"This is the section for science books": "Sección para los libros de ciencia"
}
Save the file and run the server. Now to test it, you'll need the browser console, if you are using Firefox F12, if you're using Chrome CTRL+ALT+i or their equivalent on mac CMD+ALT+i and write:
setLanguage('es'); location.reload(true)
Now you'll read the page in spanish, write the same with code 'en':
setLanguage('en'); location.reload(true)
And now is in english again.