RhapsodyJS uses a fork of Consolidate build specially for support I18n, called Consolid8ion.

Due to the limitation of some template engines, if you want to use I18n you won't be able to choose any template engine Consolidate originally supports, but the best template engines will support it, don't worry, you'll see bellow! =)

Also, some logic-less template engines, like Mustache, won't support I18n in the view with all its power, but you will still be able to pass the internationalized to the view using Rhapsody.i18n.i18n(<arguments>).

To enable i18n in your app, you must change the enabled flag to true in your app/config/i18n.js file, set your locales, the default locale, and say to RhapsodyJS from where it will "discover" the user's locale.

The i18n.js file has the following spec:

module.exports = {
    enabled: true,
    locales: ['en'],
    defaultLocale: 'en',
    getLocaleFrom: 'query' //See bellow
};

getLocaleFrom

This will set from where RhapsodyJS will automatically gets the user's locale, this option must have one of the following values:

  • query The locale will come from "?locale=LOCALE_NAME" in the URL of the page.
  • cookies The locale will come from "locale" field on the user's cookies.
  • session The locale will come from "locale" field on the user's session.
  • subdomain The locale will come from the first subdomain of the page (e.g., in "en.wikipedia.org", "en" is the locale).
  • header The locale will come from the "accept-language" header field.

Locale files

All your locale files will live in app/locales folder.

As Consolid8ion uses I18Node inside of it, your locale files must be JSON files following the specification described in the I18Node README.

Using I18n in the view

The way you use I18n inside the views changes according ot the template engine you're using.

The template engines that support Consolid8ion with all its power are:

And you will have partially support to I18n using one of the following template engines:

You can view a little example of the usage of I18n with each one of the template engines in the Consolid8ion test views.