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?
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)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments