Reputation: 3520
i have this:
I18N =
detectLngQS: "lang"
resGetPath: "locales/__lng__/__ns__.json"
ns: { namespaces: ['ns.common', 'ns.layout', 'ns.forms', 'ns.msg'], defaultNs: 'ns.common'}
ignoreRoutes: ["images/", "public/", "css/"]
extension:".json"
debug: false
in my node-express application and my locales is as follows:
☺ tree -L 2 locales ruby-2.0.0-p195 master 02bd09a ✗""
locales
├── README.md
├── cs-CZ
│ ├── ns.common.json
│ ├── ns.forms.json
│ ├── ns.layout.json
│ └── ns.msg.json
├── dev
│ ├── ns.common.json
│ ├── ns.forms.json
│ ├── ns.layout.json
│ └── ns.msg.json
├── en-UK
│ ├── ns.common.json
│ ├── ns.layout.json
│ └── ns.msg.json
├── fr-FR
│ ├── ns.common.json
│ ├── ns.forms.json
│ ├── ns.layout.json
│ └── ns.msg.json
└── sk-SK
├── ns.common.json
├── ns.forms.json
├── ns.layout.json
└── ns.msg.json
i keep getting ENOENT
messages in my console such as:
currentLng set to: fr-FR
loaded file: locales/fr-FR/ns.common.json
loaded file: locales/fr-FR/ns.layout.json
loaded file: locales/fr-FR/ns.forms.json
loaded file: locales/fr-FR/ns.msg.json
[ { [Error: ENOENT, open 'locales/fr/ns.common.json'] errno: 34, code: 'ENOENT', path: 'locales/fr/ns.common.json' },
{ [Error: ENOENT, open 'locales/fr/ns.layout.json'] errno: 34, code: 'ENOENT', path: 'locales/fr/ns.layout.json' },
{ [Error: ENOENT, open 'locales/fr/ns.forms.json'] errno: 34, code: 'ENOENT', path: 'locales/fr/ns.forms.json' },
{ [Error: ENOENT, open 'locales/fr/ns.msg.json'] errno: 34, code: 'ENOENT', path: 'locales/fr/ns.msg.json' } ]
what am i missing?
also, in some cases, i just want to use the fallback file, so for example en-UK, i don't have the ns.forms.json
file so i get
locales en-UK
loaded file: locales/en-UK/ns.common.json
loaded file: locales/en-UK/ns.layout.json
loaded file: locales/en-UK/ns.msg.json
[ { [Error: ENOENT, open 'locales/en/ns.common.json'] errno: 34, code: 'ENOENT', path: 'locales/en/ns.common.json' },
{ [Error: ENOENT, open 'locales/en/ns.layout.json'] errno: 34, code: 'ENOENT', path: 'locales/en/ns.layout.json' },
{ [Error: ENOENT, open 'locales/en-UK/ns.forms.json']
errno: 34,
code: 'ENOENT',
path: 'locales/en-UK/ns.forms.json' },
what is the correct way to fix this?
any advise much appreciated
Upvotes: 0
Views: 973
Reputation: 11
Since there is still no fix for this in the Thread and yet one of the top Google hits to the Problem here the Solution:
var options = {
preload: ['en-US','de-DE'],
fallbackLng: 'en-US',
cookieName: 'lng',
saveMissing: true,
debug: true,
resGetPath: 'locales/__lng__/__ns__.json',
lng: 'en-US',
/*this is the important part*/
load: 'current',
languages: ['en-US','de-DE'],
ns: {
namespaces: ['app','buttons'],
defaultNs: 'app'
}
};
i18n.init(options, function (t) {/*loaded*/});
If load option is set to current i18next will load the current set language (this could be a specific (en-US) or unspecific (en) resource file).
Hint: to prevent loading the fallbackLng's resource file set fallbackLng to false.
Upvotes: 1
Reputation: 3520
my mistake, as i was setting the code at https://github.com/nkhine/node-blade-boiler-template/blob/master/public/js/locale.js#L15 to just take the first argument, so when i change the language from the client, it was setting it as en
instead of en-UK
as an example.
Upvotes: 0