localizedStringsService.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { LanguageService } from "./languageService";
  2. import line_i18n from 'line-i18n';
  3. import Langs from './../../i18n';
  4. import { Operators } from "./../ast/operators";
  5. class IVProgLocalizedStrings extends line_i18n.LocalizedStrings {
  6. constructor(langService, langsJsons, shouldListenToChange = false) {
  7. super(langService, langsJsons, shouldListenToChange);
  8. }
  9. translateType (type, dim) {
  10. switch (dim) {
  11. case 0:
  12. return this.getUI(type);
  13. default:
  14. const transType = this.getUI(type);
  15. if(dim === 1)
  16. return this.getUI("vector_string", [transType])
  17. else
  18. return this.getUI("matrix_string", [transType])
  19. }
  20. }
  21. translateOp (op) {
  22. switch(op.ord) {
  23. case Operators.AND.ord:
  24. case Operators.OR.ord:
  25. case Operators.NOT.ord:
  26. return this.getUI(op.value);
  27. default:
  28. return op.value;
  29. }
  30. }
  31. }
  32. export const LocalizedStrings = Object.freeze(new IVProgLocalizedStrings(LanguageService, Langs, true));
  33. let _instance = null;
  34. export function getInstance () {
  35. if(_instance == null) {
  36. _instance = new IVProgLocalizedStrings(LanguageService, Langs);
  37. }
  38. return _instance;
  39. }