Question

I am using the i18next script in my jQuery Mobile page in Cordova/PhoneGap app.

I have the below scripts included in the bottom of HTML page.

<script src="js/jquery-1.8.3.min.js"></script>               
<script src="js/jquery.mobile-1.3.2.min.js"></script>   
<script src="js/i18next-1.7.1.min.js"></script>         
<script src="js/main.js"></script>  

The main.js file has some logic which will be included in all pages of my app.

main.js File:

function doBootstrap() {
    i18n.init({lng: "en", fallbackLng: 'en'});

    var header = "some tags";
    header += '<h1>' + i18n.t("app.title") + '</h1>';

    // other functions
}

I will be using the script to get the translated values across the page in different sections

The above function is called in Cordova devideready function which is placed beow the above mentioned includes. .

document.addEventListener("deviceready", onDeviceReady, true);

function onDeviceReady() {
    doBootstrap();
}

With all the above setup I get the below error in i18next-1.7.1.min.js file.

Uncaught TypeError: Cannot read property 'defaultValue' of undefined 

The .json file is present in \locales\en\translation.json and the content of it is below. No error or warning is displayed in console.

{
   "app": {
     "title": "Title"
   }
}

What I am missing with the plugin setup?

Was it helpful?

Solution

Finally, I have made it to work. It was a bug in the code and the developer fixed it within minutes of reporting it. Great job..

Here is the link for the issue.

https://github.com/jamuhl/i18next/issues/166

Also as per the developer of plugin, I did the following changes.

function doBootstrap() {
    var opts = {
       getAsync: true, lng: "en", fallbackLng: 'en'
    };

    i18n.init(opts).done(doBootstrapMain);
}

function doBootstrapMain() {
   // my regular functions
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top