我有与这里描述的相同的问题(堆栈溢出问题),除了我的两个项目都配置正确。
我的 i18n.js 配置设置如下。
import i18n from 'i18next';
import Backend from 'i18next-xhr-backend';
import { reactI18nextModule } from 'react-i18next';
i18n
.use(Backend)
.use(reactI18nextModule)
.init({
interpolation: {
// React already does escaping
escapeValue: false
},
lng: 'en',
fallbackLng: 'en',
backend: {
loadPath: '/locales/{{lng}}/translation.json',
allowMultiLoading: true
},
debug: true,
react: {
wait: true
}
});
export default i18n;
我收到此错误i18next::backendConnector: loading namespace translation for language en failed failed parsing locales/en/translation.json to json
我确保我的locales
目录在我的public
目录中。我还验证了 postnpm run build
目录locales
是否已复制到build
目录中。
在我的暂存环境中,我打开 Chrome 开发工具上的网络选项卡并translations.json
在新选项卡中打开。我被带到正确的 urlhttps://example.com/locales/en/translation.json
但是我被重定向到我的 index.html