Skip to content

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

@Sven65

Description

@Sven65

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions