2014-03-12 37 views
0

我在使用i18next獲取i18n'ed版本的字符串時遇到困難。 我有不能i18next-1.7.2.js的1381線讀取屬性零誤差的「狀態」i18next版本1.7.2無法讀取屬性'null'的空錯誤

我的JSON文件都位於區域設置/翻譯-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)沒有申請我的情況。

+0

github中的相關問題:https://github.com/jamuhl/i18next/issues/214 –

+0

當我更改i18next-1.7.2.js代碼來繞過error.status問題並使用jquery庫時,我的問題已解決。只要時限到期,我會盡快發佈詳細解釋(不允許我在8個小時左右的時間內回答我自己的問題) –

回答

0

當我檢查i18next-1.7.2行的源代碼:1382 似乎有在代碼中缺少空檢查。 錯誤爲空,正在檢查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的開發人員知道這個問題。

相關問題