2

Using Sails.js version 0.10.x and trying to get the i18n stuff to work.

I have the following in my config/locales/en.json

{
  "countries": {
    "au": {
      "name": "Australia",
      "fiatCurrency": "AUD",
      "subnationalDivisions": {
        "NSW": "New South Wales",
        "WA": "Western Australia",
        "VIC": "Victoria",
        "QLD": "Queensland",
        "TAS": "Tasmania",
        "SA": "South Australia",
        "NT": "Northern Territory",
        "ACT": "Australian Capital Territory"
      }
    }
  }
}

My config/i18n.js file looks like

module.exports.i18n = {

  // Which locales are supported?
  locales: ['en', 'es', 'fr', 'de'],

  objectNotation: true

};

In my controller I am trying to retrieve the correct subnationalDivision name via

res.i18n("countries." + country + ".subnationalDivisions." + state)

but that just gives me "countries.au.subnationalDivisions.ACT", not "Australian Capital Territory"

I've check with a trivial example:

Given en.json file containing { "bingo" : "sparky" }, res.i18n("bingo") outputs "sparky"

But examples using objectNotation don't work despite the instructions in the i18n-node documentation.

How should I get this to work?

Dave Sag
  • 13,266
  • 14
  • 86
  • 134
  • 1
    You can try out [l10ns](http://l10ns.org). It provides you with ICU's messageformat and it syncs your translation key for you. So you can manage your localization files more easily – einstein Oct 20 '14 at 23:46
  • I'll check it out. In the meantime the problem I described turned out to be a bug in Sails (which I fixed). – Dave Sag Oct 21 '14 at 03:41

1 Answers1

1

The problem tuned out to be a bug in Sails - it was using an older version of the i18n package. I found and fixed the error and sent a PR to the Sails team and it was incorporated into v 0.10.3 of Sails. (At current writing Sails is now on 0.10.5)

Dave Sag
  • 13,266
  • 14
  • 86
  • 134