Multilingual support

Alexey Gordeyev edited this page Apr 17, 2015 · 20 revisions

Default language

Set your default language in config/configuration.js

module.exports = {
    debug: false,
    language: "en",
    ...
}

Dictionaries

Dictionaries located config/locales/*, writed in the YAML Format.

    .
    `-- config
        `-- locales
            |-- en.yml
            |-- ...
            `-- ru.yml

#t(key, [val])

Parameters:

  • key String - translation key (reqired)
  • val String - default value (optional)

Translation in the Controller

module.exports = {
    ...
    'index': function(req, res, next) {
         var title = res.locals.t('main.title');

    ...
    }
}

Translation in the View

   <h1><%- t('main.title') %></h1>

Switch language

 <a href="/?language=ru">RU</a>
 <a href="/?language=en">EN</a>