languageService.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. declare var iLMparameters: any; // Tell Typescript iLMparameters is a global
  2. import Lexers from "./../../grammar/";
  3. import line_i18n from "line-i18n";
  4. import { Config } from "./../util/config";
  5. import {
  6. IVProgLexer,
  7. I18N_LANG_FUNCS,
  8. I18N_LANG_LIBS,
  9. } from "../../grammar/lexer";
  10. class LanguageServiceExtended extends line_i18n.LanguageServiceNoLS {
  11. constructor() {
  12. super(
  13. typeof iLMparameters === "undefined"
  14. ? Config.default_lang
  15. : iLMparameters.lang
  16. );
  17. }
  18. getDefaultLang(): string {
  19. return "en";
  20. }
  21. getCurrentLexer(): IVProgLexer {
  22. const langLexer = Lexers[this.getLang()];
  23. if (langLexer === null || langLexer === undefined) {
  24. return Lexers[this.getDefaultLang()];
  25. } else {
  26. return langLexer;
  27. }
  28. }
  29. getCurrentLangFuncs(): I18N_LANG_FUNCS {
  30. const langInfo = Lexers[this.getLang()];
  31. if (langInfo === null || langInfo === undefined) {
  32. return Lexers[this.getDefaultLang()].getLangFuncs();
  33. } else {
  34. return langInfo.getLangFuncs();
  35. }
  36. }
  37. getCurrentLangLibs(): I18N_LANG_LIBS {
  38. const langInfo = Lexers[this.getLang()];
  39. if (langInfo === null || langInfo === undefined) {
  40. return Lexers[this.getDefaultLang()].getLangLibs();
  41. }
  42. return langInfo.getLangLibs();
  43. }
  44. }
  45. export const LanguageService = new LanguageServiceExtended();