Skip to content

Organize locale files

Roberto Prevato edited this page Oct 17, 2015 · 6 revisions

The I.js library has no opinion about how the regional settings are loaded. The only important thing, is that the I.regional object must be extended with the desired languages. The keys of the I.regional object must match the I.locale value. For example, if I.locale == "en-us"; when calling the translate function I.t, the resources are taken from I.regional["en-us"].

If not possible, I.js displays user friendly error messages.

Generally, the best approach is to organize the regional settings in different files, related to different cultures. For example: a file

  • /scripts/locale/en-us.js for EN-US
  • /scripts/locale/en-gb.js for EN-GB
// /scripts/locale/en-gb.js
_.extend(I.regional, {
  "en-gb": {
    "vocabulary": {
      "color": "colour"
    } 
  }
});

And in another file:

// /scripts/locale/en-us.js
_.extend(I.regional, {
  "en-us": {
    "vocabulary": {
      "color": "color"
    } 
  }
});

In order to ensure scalability, the server side should be designed to return only the texts in the required language to its clients.

Clone this wiki locally