通过在package.json中设置homepage变量,我的React应用程序从相对路径加载。但是,i18next-http-backend仍然尝试从http://localhost:3000/locales/en/translation.json而不是http://localhost:3000/myapp/locales/en/translation.json加载翻译。我甚至尝试了设置loadPath选项(虽然不确定语法),但不起作用。如下所示:
i18n
.use(Backend)
.use(initReactI18next)
.init({
fallbackLng: 'en',
debug: true,
loadPath: `${process.env.PUBLIC_URL}/locales/{{lng}}/{{ns}}.json`,
interpolation: {
escapeValue: false // not needed for react as it escapes by default
}
})我怎么才能让它工作呢?
发布于 2020-10-20 00:33:23
loadPath需要作为Backend初始化的一部分进行设置,因此您需要执行以下操作...
i18n
.use(Backend)
.use(initReactI18next)
.init({
fallbackLng: 'en',
debug: true,
backend: {
loadPath: `${process.env.PUBLIC_URL}/locales/{{lng}}/{{ns}}.json`,
}
interpolation: {
escapeValue: false // not needed for react as it escapes by default
}
})https://stackoverflow.com/questions/64408497
复制相似问题