我正在尝试使用Node上的i18next库从JSON文件加载翻译。JSON文件的路径指向正确的位置。
我收到以下错误:i18next::translator: missingKey en translation test test
import i18next from 'i18next';
import Backend from 'i18next-fs-backend';
const instance = i18next.use(Backend).createInstance({
lng: config.language,
debug: true,
fallbackLng: 'en',
initImmediate: false,
backend: {
loadPath: join(__dirname, `${config.language}.json`),
},
}, (error, t) => {
console.log(t('foo'));
});JSON文件:
{
"foo": "bar"
}使用resources属性直接在createInstance中指定翻译效果很好。
我试了我能想到的所有方法,都没有成功。
发布于 2021-07-16 15:55:13
找到解决方案了!
import i18next from 'i18next';
import Backend from 'i18next-fs-backend';
const instance = i18next.use(Backend).createInstance();
instance.init({
lng: config.language,
debug: true,
fallbackLng: 'en',
initImmediate: false,
backend: {
loadPath: join(__dirname, `${config.language}.json`),
},
}, (error, t) => {
console.log(t('foo'));
});https://stackoverflow.com/questions/68392912
复制相似问题