使用 Locize 后端初始化 i18next 时,在 android 设备上存在问题,其中 Locize 后端插件i18next::backendConnector: loading namespace translation for language en failed [TypeError: Network request failed]
在加载时返回,但在 IOS 设备上正确加载翻译。
这是我用来在应用加载时初始化翻译的代码:
import i18n, { type Translate } from 'i18next';
import LocizeBackend from "i18next-locize-backend";
...
export const loadTranslations = () => {
if(!i18next.isInitialized) {
i18n
.use(initReactI18next)
.use(LocizeBackend)
.init({
debug: true,
// needed because of flat json translations
keySeparator: false,
backend: {
projectId: config.locize.projectId,
apiKey: config.locize.apiKey,
version: 'latest',
refLng: 'en',
},
interpolation: {
escapeValue: false
},
fallbackLng: 'en',
// don't save missing translations in non-dev env
saveMissing: true,
});
}
};
包.json
"react-native": "0.66.3",
"i18next": "^19.0.0",
"i18next-locize-backend": "^4.2.3",