module.exports = { t(key){ console.log('i18n',this); if(this.locales[key]){ if(this.lang){ if(this.locales[key][this.lang]){ return this.locales[key][this.lang]; }else{ this.log(`Key "${key}" does not exists for language ${this.lang}`); } }else if(this.locales[key][this.fallback]){ return this.locales[key][this.fallback]; }else{ this.log(`Key "${key}" does not exists for fallback language ${this.fallback}`); } }else{ this.log(`Key "${key}" does not exists.`); } // if(this.lang){ // if(this.locales[key][this.lang]){ // // key exists in current language // return this.locales[key][this.lang]; // }else{ // console.log('Key ${key} does not exists for language ${this.lang}'); // } // }else if(this.locales[key][this.fallback]){ // // key exists in fallback language // return this.locales[key][this.fallback]; // } return key; }, setLang(l){ this.lang = l }, log(msg){ console.log(`i18n : ${msg}`); }, fallback:'en', lang: null, locales:{ 'Parts':{ 'en':'Parts', 'fr':'Parties', 'bra':'Peças', 'lat':'Pars' }, 'Mode':{ 'en':'Mode', 'fr':'Mode', 'bra':'Modo', 'lat':'Modus' }, 'Language':{ 'en':'Language', 'fr':'Langue', 'bra':'Língua', 'lat':'Lingua' }, 'Text':{ 'en':'Text', 'fr':'Texte', 'bra':'Texto', 'lat':'Illud' }, 'Conexions':{ 'en':'Conexions', 'fr':'Connections', 'bra':'Conexões', 'lat':'Hospites' }, } }