2014-03-12 2 views
0

i18next를 사용하여 문자열을 가져 오는 데 어려움이있었습니다. 나는i18next 버전 1.7.2가 null 오류의 'status'속성을 읽을 수 없습니다.

내 JSON 파일이 로케일/번역 - en.json에있는

, ... 등

i18next-1.7.2.js의 라인 1381에 널 (null) 오류의 '상태'속성을 읽을 수없는 데

내 초기화 코드는 다음과 같다 :

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

error.status 문제를 회피하고 jquery 라이브러리를 사용하지 않도록 i18next-1.7.2.js 코드를 변경했을 때 문제가 해결되었습니다. 시간 제한이 만료되자 마자 대답에 대한 자세한 설명을 게시 할 것입니다 (8 시간 정도 내 자신의 질문에 답변을 게시 할 수 없습니다) –

답변

0

i18next-1.7.2 소스 코드를 검사했을 때 : 1382 코드에 누락 된 null 검사가있는 것으로 보입니다. 오류가 null이고 error.status가 검사되고 있습니다. 그래서 간단한 null 확인을 추가했습니다. (원래 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은 주제에 대해 알고 있습니다.

관련 문제