Question

I had a difficulty in using i18next to get i18n'ed versions of strings. I am having cannot read property 'status' of null error on line 1381 of i18next-1.7.2.js

my json files are located in locales/translation-en.json,... etc.

My init code is like below:

i18n.init({ lng:"en" , resGetPath: "locales/__ns__-__lng__.json",  ns:"translation"},
function(t) {
text.nodeValue = i18n.t("app.name");
....
});

Cannot read property 'length' of null (javascript) didn't apply for my case.

Was it helpful?

Solution

When I inspected the source code of i18next-1.7.2 line:1382 It seems that there is a missing null check in the code. error is null and error.status is being checked. So I added a simple null check.

Here is the change in the code:

Old code (from original i18next-1.7.2.js) :

                    if (error.status == 200) {
                        // file loaded but invalid json, stop waste time !
                        f.log('There is a typo in: ' + url);
                    } else if (error.status == 404) {
                        f.log('Does not exist: ' + url);
                    } else {
                        f.log(error.status + ' when loading ' + url);
                    }
                    done(error, {});

proposed code:

                if (error == null){
                    done(error, {});
                }else{
                    if (error.status == 200) {
                        // file loaded but invalid json, stop waste time !
                        f.log('There is a typo in: ' + url);
                    } else if (error.status == 404) {
                        f.log('Does not exist: ' + url);
                    } else {
                        f.log(error.status + ' when loading ' + url);
                    }
                    done(error, {});
                }

When I changed the code like above, it didn't work. When I included jquery.js file it worked. Developer of i18next Jamuhl knows about the subject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top