首页 > 解决方案 > i18next 不能在 Cordova iOS 6.1.0 上翻译

问题描述

我已经在 iOS 和 Android 上使用了多年的 v1.10.x,但是随着新迁移到 wkwebview i18next(包括 1.11.2),它只返回了密钥。我很好奇是否有人在 Cordova iOS 6.1.0、Cordova 9.0.0 中成功使用 i18next,以及是否有人能发现我的错误。

[编辑] 调试时,我收到此错误,但它有点无用

2020-07-15 11:08:29.649177-0700 myapp[15438:5134539] error when loading /src/locales/en/translation.json

[/编辑]

这是我的 i18next 初始化代码,min 包由 index.html 加载。我将资源对象添加到 init 选项中,以查看我的 translation.json 文件是否存在问题,但显式资源也没有翻译。此初始化在 Cordova Android 9.0 上运行良好。

      /* ******************* internationalization and go **************** */
  // initialize i18n, launch react in the callback so we're able to localize
  i18n.init(
    {
      fallbackLng: "en",
      debug: true,
      resources: {
        en: {
          translation: {
            "clf_js_Username": "Who ARE you?"
          }
        }
      }
    },
    function(err, t) {
      if (typeof err !== "undefined") {
        console.log("LH.iLE - initialization returned error >" + err + "<");
      }
      setTimeout(() => {
        console.log(
          "********** i.i18init is complete - starting react **********"
        );

        // setup the action groups for 'special' notifications
        // addKatzerActionGroups();

        //************** launch React+Redux **********

(blah blah blah——超时是一个幻数 1000ms 以允许 i18n 初始化) );

标签: ioscordovawkwebviewi18next

解决方案


安装这个插件(cordova-ios 6+)

  cordova plugin add https://github.com/globules-io/cordova-plugin-ios-xhr

然后设置

  <preference name="AllowUntrustedCerts"  value="true" />
  <preference name="InterceptRemoteRequests" value="all" />
  <preference name="allowFileAccessFromFileURLs" value="true" />
  <preference name="allowUniversalAccessFromFileURLs" value="true" />

推荐阅读