Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module falls back on key when no translation exists. #344

Open
Sven65 opened this issue Nov 30, 2017 · 3 comments
Open

Module falls back on key when no translation exists. #344

Sven65 opened this issue Nov 30, 2017 · 3 comments

Comments

@Sven65
Copy link

Sven65 commented Nov 30, 2017

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.

@ahallez
Copy link

ahallez commented Feb 13, 2021

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.

@axelpale
Copy link

axelpale commented Dec 2, 2021

@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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants