【问题标题】:i18next version 1.7.2 cannot read property 'status' of null errori18next 1.7.2 版无法读取 null 错误的属性“状态”
【发布时间】:2014-03-12 09:32:19
【问题描述】:

我在使用 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");
....
});

Cannot read property 'length' of null (javascript) 没有申请我的案子。

【问题讨论】:

  • 当我更改 i18next-1.7.2.js 代码以规避 error.status 问题并使用 jquery 库时,我的问题得到了解决。一旦时间限制到期,我将发布详细解释作为答案(不允许我在 8 小时左右发布我自己的问题的答案)

标签: i18next


【解决方案1】:

当我查看 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 的开发者知道这个主题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 2022-01-24
    • 2017-06-07
    相关资源
    最近更新 更多