Module falls back on key when no translation exists.
Creating two files,
locales/en-us.json
{
"hello": "Hello!",
"user.name": "Username"
}
locales/sv-se.json
{
"hello": "Hej!"
}
Running these in a file like this one;
const i18n = require("i18n");
i18n.configure({
directory: __dirname+'/locales',
defaultLocale: 'en-us',
autoReload: true,
updateFiles: false,
fallbacks: {'sv-se': 'en-us'},
retryInDefaultLocale: true
})
console.log(i18n.__('hello'))
console.log(i18n.__('user.name'))
i18n.setLocale('sv-se')
console.log(i18n.__h('user.name'))
console.log(i18n.__('hello'))
console.log(i18n.__('user.name'))
I get the output
Hello!
Username
[ { 'en-us': 'Username' }, { 'sv-se': 'user.name' } ]
Hej!
user.name
As can be seen, the last string is outputted as the translation key, despite having set the fallbacks key in the configuration.
Having a global fallback would also be helpful.
I'm having the same issue. It seems like the fallback settings are used when setting the locale to an unsupported one. However, I would expect the fallback to be used for searching an alternative translation when a key is missing from the active locale.
@ahallez "I would expect the fallback to be used for searching an alternative translation"
I thought the same. There are a few issues where people have implemented this by rewriting the catalogs:
- #387
- #423
- #439
defaults as intended: https://github.com/mashpie/i18n-node/blob/master/test/i18n.missingPhrases.js#L27
hook for customization: https://github.com/mashpie/i18n-node/blob/master/test/i18n.missingPhrases.js#L42