localizedStringsService.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import line_i18n from "line-i18n";
  2. import { LanguageService } from "./languageService";
  3. import { LanguageDefinedFunction } from "./../processor/definedFunctions";
  4. import Langs from "./../../i18n";
  5. import { Operators } from "./../ast/operators";
  6. class IVProgLocalizedStrings extends line_i18n.LocalizedStrings {
  7. constructor (langService, langsJsons, shouldListenToChange = false) {
  8. super(langService, langsJsons, shouldListenToChange);
  9. }
  10. translateType (type, dim) {
  11. const type_string = this.getUI(`type_${type}`);
  12. switch (dim) {
  13. case 0:
  14. return type_string;
  15. default:
  16. if (dim > 1) return this.getUI("matrix_info_string", [type_string]);
  17. else return this.getUI("vector_info_string", [type_string]);
  18. }
  19. }
  20. translateOp (op) {
  21. switch (op.ord) {
  22. case Operators.AND.ord:
  23. case Operators.OR.ord:
  24. case Operators.NOT.ord:
  25. return this.getUI(`logic_operator_${op.value}`);
  26. default:
  27. return op.value;
  28. }
  29. }
  30. translateInternalFunction (name, category = null) {
  31. if (category == null) {
  32. return LanguageDefinedFunction.getLocalName(name);
  33. } else {
  34. return LanguageDefinedFunction.getLocalName(`${category}.${name}`);
  35. }
  36. }
  37. }
  38. export const LocalizedStrings = Object.freeze(
  39. new IVProgLocalizedStrings(LanguageService, Langs, true)
  40. );
  41. let _instance = null;
  42. export function getInstance () {
  43. if (_instance == null) {
  44. _instance = new IVProgLocalizedStrings(LanguageService, Langs);
  45. }
  46. return _instance;
  47. }