2017-11-13 4 views
0

json 파일에서 번역 키를 사용하고 싶지 않습니다. 나는 내가 모든 로케일 파일에 대한 변환 키를 포함하지 않는다는 의미는, 파일은이 수준을 갖고 싶어 :en.json에서 번역 키를 제거하려면 어떻게해야합니까?

{ 
    "translation": { 
    "sidebar": { 
     "dashboard": "Dashboard", 
     "clients": "Clients", 
     "coaches": "Coaches", 
     "candidates": "Candidates", 
     "trackList": "Track List", 
     "reports": "Reports" 
    }, 
    "clients": { 
     "clients": "Clients", 
     "companyName": "Company Name", 
     "previous": "Previous", 
     "next": "Next" 
    } 
    } 
} 

이 i18next를 초기화 내 i18n.js 파일입니다.

import angular from 'angular'; 
import ngSanitize from 'angular-sanitize'; 
import i18next from 'i18next'; 
import ngI18next from 'ng-i18next'; 
import enLocale from './locales/en.json' 

const module = angular.module('app.i18n', [ngSanitize, ngI18next]); 

module 
    .config(function() { 

    window.i18next = i18next; 

    i18next.init({ 
     debug: true, 
     lng: 'en', 
     fallbackLng: false, 
     resources: { 
     en: enLocale 
     }, 
     useCookie: false, 
     useLocalStorage: false 
    }, function(err, t) { 
     console.log('i18next was initialized'); 
     console.log(t('global.clients')); 
     console.log(t('global.addNewClient')); 
    }); 

}); 
export default module.name; 

답변

0

Json에서 번역을 제거하고 시도하십시오. 기본적으로 작동해야합니다. 설정되지 않은 경우.

fallbackNS= false; 

정지가 작동하지 않는 경우. 새 Json 변수를 만들어 리소스에 전달합니다.

import enLocale from './locales/en.json' 
const enLocaleData = {"en":{"transalation":enLocale["en"] }}; 

i18next.init({ 
     debug: true, 
     lng: 'en', 
     resources: { 
     en: enLocaleData 
     }); 

이렇게하면 json을 두 단계로 전달할 수 있습니다.

{ 
"en": 
    { 
    "key":"keyValue", 
    "key2":"keyValue2", 
    } 
} 

는 도움이되기를 바랍니다 .. :)