In this part we will explain how the translation system works in a Nodea application and then how to add and modify a language and make it available to users.
When you arrive on the application the 1st thing happens in relation to the language that will be used and to check if you already have a language entered in a session linked to you.
If no session is found then by default you will be assigned the default language of the application (lang key, see: application.json)
Then the user's language is supplied to dust.js for rendering via the variable {lang_user} and the translation is done via the locals function __ (See: Dust Helpers)
The locals function is based on the user's session lang as well as the key provided, it will then look for the requested key in the locales.json file corresponding to the language.
The locales files are located in app/locales (Default files are: en-EN.json, fr-FR.json, enum_radio.json)
You can change the language of your session in the settings menu of your account:
As you can see in the app/locales folder there is a file named enum_radio.json. The purpose of this file is to allow the translation of enum (list of values) and radio (HTML Radio buttons) type fields.
The principle is simple, you will find by entity a list of fields concerned by the translations (therefore the fields of type enum and radio) and then for each value the translation according to the language.
Example:
"e_action": {
"f_execution": [
{
"value": "immediate",
"translations": {
"fr-FR": "Immédiate",
"en-EN": "Instant"
}
},
{
"value": "differee",
"translations": {
"fr-FR": "Différée",
"en-EN": "Deferred"
}
}
]
}
Adding support for a new language in a Nodea application is very easy. We will take as an example the way of adding Italian in your application.
The first thing to do is to create the it-IT.json file in app/locales/. Then just import the contents of en-FR.json (or fr-FR.json) into your it-IT.json file and start translating the whole file into Italian.
Finally we must add the button allowing users to choose their language in the user settings menu, for this we must add the following code after the other buttons of language in the file
app/views/e_user/settings.dust:
<a data-lang="it-IT" class='chooseLanguage btn {@eq key=lang_user value="it-IT"}btn-primary{:else}btn-default{/eq}'>
Italian
</a>