-
Notifications
You must be signed in to change notification settings - Fork 7
Translation system
Translation is provided by the (i18n-node)[https://github.com/mashpie/i18n-node] module which integrates into Iris. It allows text strings to be altered when they are displayed to a user depending on context such as the user's language.
Language doesn't have to mean a national language. It can be anything that changes the format of how text is written out. A site might want to, for example, change the tone of a system message using the translation system.
i18n is attached to the authPass object which should be available in all page callbacks and hooks (req.authPass in callbacks, thisHook.authPass in hooks). You would set the 'locale' of the current request to what ever logic determines the language of the current user.
To change this depending on circumstance use hook_auth_authpass
to set the user's language for a session (page request etc).
iris.modules.mymodule.registerHook('hook_auth_authpass', 0, function(thisHook, authPass){
if(thisHook.context.req.url.indexOf("/cz/") !== -1){
authpass.setLocale("cz");
}
thisHook.pass(authPass);
})
Simply by wrapping text in the below, i18n will automatically output all translated text to files in the configurations directory (eg, /configurations/locales/de.json). Altering these files with the appropriate translation text will feed through the the display.
iris.modules.myModule.registerHook("hook_myCustom_hook", 0, function (thisHook, data) {
var ap = thisHook.authPass;
// You can use placeholder parameters.
ap.t('Hello {{name}}', {name: 'John'});
});
If the locale for this request had been set to 'fr' and in the /configurations/locales/fr.json the line:
"Hello {{name}}": "Hello {{name}}"
Is replaced with:
"Hello {{name}}": "Bonjour {{name}}"
The rendered page would should "Bonjour John".
The i18n module currently doesn't support adding translations via code, only by editing the translation files manually. However, we have added a pull request to the i18n module to provide this functionality (https://github.com/mashpie/i18n-node/pull/221).
When this is merged in, the process of adding translation via code will be as such:
var cat = thisHook.authPass.getCatalog([lang code]); //eg, 'fr'
cat['Hello {{name}}'] = 'Bonjour {{name}}';
thisHook.authPass.setCatalog([lang code]);
- Setting up an Iris site
- Folder structure
- Module system
- Restarting the server after code changes
- Hook system
- Entity system
- Theme and template system
- Form system
- Text filters
- Message system
- Routing system
- Sessions, authentication, user and permission systems
- Configuration system
- Menu system
- Translation system
- Triggers
- Websocket system
- Logs
- Adding tags (meta, css, javascript) to templates dynamically
- Block and region system