polyglot-editor.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. define([
  3. "vwf/view/lib/polyglot/polyglot.min",
  4. ], function (polyglot) {
  5. var self;
  6. class Lang {
  7. constructor() {
  8. console.log("lang constructor");
  9. this.polyglot = polyglot;
  10. if (localStorage.getItem('krestianstvo_locale')) {
  11. } else {
  12. localStorage.setItem('krestianstvo_locale', 'en');
  13. }
  14. this.locale = localStorage.getItem('krestianstvo_locale');
  15. this.setLanguage(this.locale);
  16. }
  17. async getLang(langID) {
  18. let response = await fetch("/web/locale/" + langID + ".json");
  19. let data = await response.json();
  20. return data
  21. }
  22. setLanguage(langID) {
  23. this.getLang(langID).then(phrases => {
  24. this.language = new polyglot({ phrases });
  25. });
  26. }
  27. setLocale(langID){
  28. localStorage.setItem('krestianstvo_locale', langID);
  29. this.locale = langID;
  30. }
  31. changeLanguageTo(langID){
  32. this.setLocale(langID);
  33. this.setLanguage(langID);
  34. }
  35. }
  36. return new Lang;
  37. })