languageService.js 952 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import Lexers from './../../grammar/';
  2. const DEFAULT_LANG = "pt";
  3. export const LanguageService = Object.freeze({
  4. getLang: () => {
  5. const lang = localStorage.getItem('ivprog.lang');
  6. if (lang === null || lang === undefined) {
  7. console.warn("Internal Error. User language information has not been set. Returning default...");
  8. return LanguageService.getDefaultLang();
  9. }
  10. return lang;
  11. },
  12. getDefaultLang: () => {
  13. return DEFAULT_LANG;
  14. },
  15. getCurrentLexer: () => {
  16. const langInfo = Lexers[LanguageService.getLang()];
  17. if(langInfo === null || langInfo === undefined) {
  18. return Lexers[DEFAULT_LANG].lexer;
  19. } else {
  20. return langInfo.lexer;
  21. }
  22. },
  23. getCurrentLangFuncs: () => {
  24. const langInfo = Lexers[LanguageService.getLang()];
  25. if(langInfo === null || langInfo === undefined) {
  26. return Lexers[DEFAULT_LANG].langFuncs;
  27. } else {
  28. return langInfo.langFuncs;
  29. }
  30. }
  31. });