Closed akzi11 closed 1 year ago
either set locale explicitly:
https://github.com/mashpie/i18n-node#i18nsetlocale
or by included middleware:
https://github.com/mashpie/i18n-node#middleware-in-expressjs
...what I get from your setup, you should check the simple example https://github.com/mashpie/i18n-node/blob/master/examples/singleton/index.js
Thanks for your answer. Even with setty locale explicity, __ return the key. Here the complete code:
const { I18n } = require('i18n');
const path = require('path')
this.i18n = new I18n( {
locales: ['en', 'fr'],
defaultLocale: 'fr',
directory: path.join(__dirname, 'locales'),
logWarnFn: function (msg) {
console.log('warn', msg)
},
logErrorFn: function (msg) {
console.log('error', msg)
},
})
this.i18n.setLocale('en');
const allo = this.i18n.__("Hello")
console.debug(allo)
I have a local folder, with two .json files (en, fr). In another file (.ts) I have: const { I18n } = require('i18n'); var i18n = new I18n( { locales: ['en', 'fr'], defaultLocale: 'fr', directory: 'locales',)} When I try i18n.getCatalog(), it return : { Hello: 'Hello', Hi: 'Hi' } But my fr.json contain : {"Hello": "Salut"} When i try i18n.__("Hello"), it return: "Hello"
How to acces to the json files?