繁体   English   中英

React-i18next 无法仅在 iOS 上加载翻译

[英]React-i18next fails to load translations only on iOS

我正在运行一个带有 react-i18next 和后端插件的 React 本机应用程序。 该应用程序在 Android 和 Web 上运行和加载翻译非常好,但在 iOS 上它根本无法加载翻译。

当 i18n 初始化时,会出现以下错误。 我不确定非法操作错误是否是原因,但似乎很有可能。

i18next::backendConnector: loading namespace translation for language en failed, [TypeError: Network request failed]

. . .

Error: EISDIR: illegal operation on a directory, read
    at Object.readSync (fs.js:614:3)
    at tryReadSync (fs.js:383:20)
    at Object.readFileSync (fs.js:420:19)

react-native 的某处是否有配置让 iOS 从public读取?

我的 i18n.js:

import * as Localization from 'expo-localization'
import i18n from 'i18next'
import Backend from 'i18next-http-backend'
import { initReactI18next } from 'react-i18next'

i18n
  .use(Backend)
  .use(initReactI18next)
  .init({
    compatibilityJSON: 'v3',
    debug: true,
    fallbackLng: 'en-US',
    interpolation: { escapeValue: false },
  })

i18n.changeLanguage(Localization.locale)

export default i18n

和我的翻译文件,位于public/locales/en-US/translation.json

{
  "outOfStock": "Out of Stock"
}

我怀疑 expo,例如 react-native 没有托管翻译,因此可以通过 i18next-http-backend 获取它们。 所以我建议你在没有 i18next-http-backend 的情况下加载翻译。 作为初始化资源: https://www.i18next.com/how-to/add-or-load-translations#add-on-init或在 i18next-resources-to-backend 的帮助下: https://www .i18next.com/how-to/add-or-load-translations#lazy-load-in-memory-translations

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM