0

使用 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",
4

1 回答 1

0

这似乎是一个android模拟器问题。在这里回答:https ://github.com/locize/i18next-locize-backend/issues/344

于 2022-01-06T13:32:18.473 回答