i18n.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. module.exports = {
  2. t(key){
  3. if(this.locales[key]){
  4. if(this.lang){
  5. if(this.locales[key][this.lang]){
  6. return this.locales[key][this.lang];// key for current language
  7. }else{this.log(`Key "${key}" does not exists for language ${this.lang}`);}
  8. }else if(this.locales[key][this.fallback]){
  9. return this.locales[key][this.fallback];// key for fallback language
  10. }else{this.log(`Key "${key}" does not exists for fallback language ${this.fallback}`);}
  11. }else{this.log(`Key "${key}" does not exists.`);}
  12. return key;// if nothing else retrn key it self
  13. },
  14. setLang(l){
  15. this.lang = l
  16. },
  17. log(msg){
  18. console.log(`i18n : ${msg}`);
  19. },
  20. fallback:'en',
  21. lang: null,
  22. locales:{
  23. 'Parts':{
  24. 'en':'Parts',
  25. 'fr':'Parties',
  26. 'bra':'Peças',
  27. 'lat':'Pars'
  28. },
  29. 'Mode':{
  30. 'en':'Mode',
  31. 'fr':'Mode',
  32. 'bra':'Modo',
  33. 'lat':'Modus'
  34. },
  35. 'Language':{
  36. 'en':'Language',
  37. 'fr':'Langue',
  38. 'bra':'Língua',
  39. 'lat':'Lingua'
  40. },
  41. 'Text':{
  42. 'en':'Text',
  43. 'fr':'Texte',
  44. 'bra':'Texto',
  45. 'lat':'Illud'
  46. },
  47. 'Connections':{
  48. 'en':'Connections',
  49. 'fr':'Connections',
  50. 'bra':'Conexões',
  51. 'lat':'Hospites'
  52. },
  53. }
  54. }