0

我在使用 i18next 获取 i18n 版本的字符串时遇到了困难。我在 i18next-1.7.2.js 的第 1381 行无法读取属性“状态”的空错误

我的 json 文件位于 locales/translation-en.json,... 等。

我的初始化代码如下:

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

无法读取 null (javascript) 的属性“长度”不适用于我的案例。

4

1 回答 1

0

当我检查 i18next-1.7.2 line:1382 的源代码时,似乎代码中缺少空检查。error 为 null 并且正在检查 error.status。所以我添加了一个简单的空检查。

这是代码中的更改:

旧代码(来自原始 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, {});

建议的代码:

                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, {});
                }

当我像上面那样更改代码时,它不起作用。当我包含 jquery.js 文件时,它起作用了。i18next Jamuhl 的开发人员知道这个主题。

于 2014-03-13T11:07:51.920 回答