localizedStringsService.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. switch (dim) {
  12. case 0:
  13. return this.getUI(`type_${type}`);
  14. default:
  15. const transType = this.getUI(`type_${type}`);
  16. if(dim === 1)
  17. return this.getUI("matrix_info_string", [transType])
  18. else
  19. return this.getUI("vector_info_string", [transType])
  20. }
  21. }
  22. translateOp (op) {
  23. switch(op.ord) {
  24. case Operators.AND.ord:
  25. case Operators.OR.ord:
  26. case Operators.NOT.ord:
  27. return this.getUI(`logic_operator_${op.value}`);
  28. default:
  29. return op.value;
  30. }
  31. }
  32. translateInternalFunction (name, category = null) {
  33. if (category == null) {
  34. return LanguageDefinedFunction.getLocalName(name);
  35. } else {
  36. return LanguageDefinedFunction.getLocalName(`${category}.${name}`);
  37. }
  38. }
  39. }
  40. export const LocalizedStrings = Object.freeze(new IVProgLocalizedStrings(LanguageService, Langs, true));
  41. let _instance = null;
  42. export function getInstance () {
  43. if(_instance == null) {
  44. _instance = new IVProgLocalizedStrings(LanguageService, Langs);
  45. }
  46. return _instance;
  47. }