How can get a non-trivial i18n translation to work using Sails.js?

Dave Sag

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

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to use Vue i18n translation in .js file?

Nuxt/Vue js - How do I synchronize path field to an i18n variable in router. I did a try but can't get to i18n

Rails I18n Cascading - how to get it to work

Sails.js: how to use i18n function in assets/js/files.js

How can i enable csrf for GET requests in SAILS js

How can I reuse i18n translation keys in Angular?

How can I specify Rails I18n locale an attribute translation common for all models?

How can I add expressive translation to KnockoutJS via i18n?

React-native: Translation with i18n How to get fallback value?

Can't get this trivial haskel program to work

I can't get populate() to work on my sails.js project

i18n routing in Next.js using graphql results in 404 for non default locale

using multiple translation files in aurelia i18N

Translation For Dynamic Data Using Rails I18n

How can I get a list of a specified field from a Sails JS Waterline collection?

How can i get the full related model in view in sails.js?

How to load i18n Property file using jQuery.i18n.properties.js + Spring 3 mvc

Vue.js how to get current locale in i18n language package

How to get the current user using jsonwebtoken in Sails.js?

JSF Complex validation formatting using h:messages: How to get I18N message and label?

Can't get Sails Socket to work

Get livereload to work with Sails.js

Sails js: How can I define two MySQL connections to two different databases in a single model in Sails js?

Sails.JS how to get a HTTP GET method in the controller to work properly with URL parameters

How can I use stored procedure call in sails js?

How can I filter populated values in sails.js?

How can I use Sails.js without Waterline?

how can I integrate sails.js with compass?

How do I get Sails.js to query an existing database?