Search code examples
ioscordovawkwebviewi18next

i18next doesn't translate on Cordova iOS 6.1.0


I've had v1.10.x working for years on both iOS and Android but with the new migration to wkwebview i18next (including 1.11.2) just returns the key. I'm curious if anyone uses i18next successfully with Cordova iOS 6.1.0, Cordova 9.0.0, and if anyone can spot my error.

[EDIT] With debug on, I get this error, it's a bit unhelpful though

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

[/EDIT]

Here's my i18next init code, the min package is loaded by index.html. I added the resources object to the init option to see if perhaps there was an issue with my translation.json file but the explicit resource doesn't translate either. This init works fine on 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——the timeout is a magic number 1000ms to allow i18n to initialize) );


Solution

  • Install this one plugin (cordova-ios 6+)

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

    then set

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