eservices-core 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,14 @@ interface IUserInformation {
13
13
  export declare type ApplicationType = 'front' | 'back';
14
14
  declare class ApplicationManager extends EventEmitter {
15
15
  #private;
16
+ static DEFAULT_LANGUAGE: string;
17
+ static LOCALSTORAGE_LANGUAGE_KEY: string;
18
+ set language(lang: string);
19
+ get language(): string;
20
+ /**
21
+ * @description Проверяет находится ли язык в local-storage
22
+ * */
23
+ checkLanguageInStorage(): boolean;
16
24
  static EVENT_CONTEXT_UPDATE: string;
17
25
  static EVENT_READY_UPDATE: string;
18
26
  static EVENT_DATA_UPDATE: string;
@@ -15,6 +15,7 @@ import { MetadataStore, ComputedMetadata, prettifyValueByMetadata } from "./clas
15
15
  import { NotificationType } from "./classes/NotificationSystem";
16
16
  import { Metadata, MetadataField, MetadataResponse } from "./../../backend/src/types/main";
17
17
  export { Metadata, MetadataResponse, MetadataField, MasterEntity, MasterEntities };
18
+ import internationalizationService from "./services/internationalization-service";
18
19
  import t from "./internationalization/translate";
19
20
  export { t, newImport, testTypes, MetadataStore, ComputedMetadata, prettifyValueByMetadata, NotificationType, clientService };
20
21
  import { ICustomerContext, ApplicationType } from "./classes/ApplicationManager";
@@ -79,7 +80,7 @@ import { List, useListRead, useListState, useListOrder, useListFilter, useListCo
79
80
  import { useWizard } from "./hooks/use-wizard";
80
81
  import equipmentService from "./services/equipment-service";
81
82
  import { SYMBOL_ROW } from "./classes/table/Table";
82
- export { IListSettings, debounce, billingService, documentsService, configurationService, INotificationConfig,
83
+ export { IListSettings, debounce, billingService, documentsService, configurationService, INotificationConfig, internationalizationService,
83
84
  /**
84
85
  * @deprecated
85
86
  * */
@@ -1,16 +1,14 @@
1
1
  declare type Vocabulary = Record<string, string | object>;
2
- declare type ReturnTranslate = typeof t;
3
2
  /**
4
3
  * @description Функция принимает метку и возвращает либо нужно значение их хранилища,
5
4
  * либо новую функцию от этой метки.
6
5
  * */
7
- declare function t(label: string): ReturnTranslate;
8
- /**
9
- * @description Функция задаёт словарь из которого нужно взять метку, а также метку и возвращает либо нужно значение их
10
- * хранилища, либо новую функцию от этой метки и переданного словаря.
11
- * */
12
- declare function t(vocabulary: Vocabulary, label: string): ReturnTranslate;
6
+ declare function t(this: {
7
+ vocabulary: any;
8
+ } | void, label: string): string;
13
9
  declare namespace t {
14
- var setStore: (newStore: Vocabulary) => void;
10
+ var setGlobalVocabulary: (newStore: Vocabulary) => void;
11
+ var getScope: (scopeName: string) => any;
12
+ var setVocabulary: (scope: any) => any;
15
13
  }
16
14
  export default t;
@@ -4,7 +4,7 @@ export default class clientService {
4
4
  /**
5
5
  * @description Получение навигационного меню для текущего контекста.
6
6
  * */
7
- static getNavigation(): Promise<INavigation>;
7
+ static getNavigation(): Promise<INavigation[]>;
8
8
  }
9
9
  export interface IClientContentData {
10
10
  id: number;
@@ -0,0 +1,6 @@
1
+ export default class internationalizationService {
2
+ /**
3
+ * @description Загрузка словаря для определённого языка.
4
+ * */
5
+ static getDictionary(lang: string): Promise<unknown>;
6
+ }
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * eservices-core v1.1.1
2
+ * eservices-core v1.1.3
3
3
  * (c) 2023 ESERVICES
4
4
  */
5
5
  'use strict';
@@ -2085,6 +2085,18 @@ class ApplicationManager extends EventEmitter {
2085
2085
  */
2086
2086
  _ApplicationManager_ready.set(this, false);
2087
2087
  }
2088
+ set language(lang) {
2089
+ localStorage.setItem(ApplicationManager.LOCALSTORAGE_LANGUAGE_KEY, lang);
2090
+ }
2091
+ get language() {
2092
+ return localStorage.getItem(ApplicationManager.LOCALSTORAGE_LANGUAGE_KEY) || ApplicationManager.DEFAULT_LANGUAGE;
2093
+ }
2094
+ /**
2095
+ * @description Проверяет находится ли язык в local-storage
2096
+ * */
2097
+ checkLanguageInStorage() {
2098
+ return !!localStorage.getItem(ApplicationManager.LOCALSTORAGE_LANGUAGE_KEY);
2099
+ }
2088
2100
  get contextType() {
2089
2101
  var _a;
2090
2102
  if (!this.contextId)
@@ -2213,6 +2225,8 @@ class ApplicationManager extends EventEmitter {
2213
2225
  }
2214
2226
  }
2215
2227
  _ApplicationManager_router = new WeakMap(), _ApplicationManager_type = new WeakMap(), _ApplicationManager_ready = new WeakMap();
2228
+ ApplicationManager.DEFAULT_LANGUAGE = 'en';
2229
+ ApplicationManager.LOCALSTORAGE_LANGUAGE_KEY = 'CurrentLanguage';
2216
2230
  ApplicationManager.EVENT_CONTEXT_UPDATE = 'event:context-update';
2217
2231
  ApplicationManager.EVENT_READY_UPDATE = 'event:ready-update';
2218
2232
  ApplicationManager.EVENT_DATA_UPDATE = 'event:data-update';
@@ -3989,35 +4003,53 @@ function prettifyValueByMetadata(value, metadataField) {
3989
4003
  return value;
3990
4004
  }
3991
4005
 
3992
- let store = {};
3993
- function t(arg1, arg2) {
3994
- const [vocabulary, label] = getTarget(arg1, arg2);
3995
- const value = jenesiusVueForm.utils.getPropFromObject(vocabulary, label);
3996
- if (typeof value === undefined) {
3997
- console.warn(`Translation for label "${label}" is not founded.`);
4006
+ class internationalizationService {
4007
+ /**
4008
+ * @description Загрузка словаря для определённого языка.
4009
+ * */
4010
+ static getDictionary(lang) {
4011
+ if (!lang)
4012
+ throw new Error(`Can't get dictionary for ${lang}.`);
4013
+ return Request(`/open-api/internationalization/language/${lang}`);
3998
4014
  }
4015
+ }
4016
+
4017
+ let store = {};
4018
+ /**
4019
+ * @description Функция принимает метку и возвращает либо нужно значение их хранилища,
4020
+ * либо новую функцию от этой метки.
4021
+ * */
4022
+ function t(label) {
4023
+ // @ts-ignore
4024
+ const value = jenesiusVueForm.utils.getPropFromObject((this === null || this === void 0 ? void 0 : this.vocabulary) || store, label);
3999
4025
  if (typeof value === 'string')
4000
4026
  return value;
4001
- return t.bind(null, jenesiusVueForm.utils.getPropFromObject(vocabulary, label));
4027
+ // Not found in current scope
4028
+ // Checking root scope
4029
+ // @ts-ignore
4030
+ const rootValue = jenesiusVueForm.utils.getPropFromObject(store === null || store === void 0 ? void 0 : store.root, label);
4031
+ if (typeof rootValue === 'string')
4032
+ return rootValue;
4033
+ if (typeof value === undefined)
4034
+ console.warn(`Translation for label "${label}" is not founded.`);
4035
+ return label;
4002
4036
  }
4003
4037
  // Устанавливает новый глобальный словарь
4004
- t.setStore = function setStore(newStore) {
4038
+ t.setGlobalVocabulary = function (newStore) {
4005
4039
  store = newStore;
4006
4040
  };
4007
- // Возвращает словарь и метку
4008
- function getTarget(arg1, arg2) {
4009
- let vocabulary = store;
4010
- let label = arg2;
4011
- if (typeof arg1 === 'string')
4012
- label = arg1;
4013
- else {
4014
- // first params is Vocabulary
4015
- vocabulary = arg1;
4016
- }
4017
- if (!label)
4018
- throw new Error('Getting target was wrong because label was not founded.');
4019
- return [vocabulary, label];
4020
- }
4041
+ t.getScope = function (scopeName) {
4042
+ return t.bind({
4043
+ vocabulary: jenesiusVueForm.utils.getPropFromObject(store, scopeName)
4044
+ });
4045
+ };
4046
+ t.setVocabulary = function (scope) {
4047
+ if (typeof scope === 'string')
4048
+ scope = jenesiusVueForm.utils.getPropFromObject(store, scope);
4049
+ return t.bind({
4050
+ vocabulary: scope
4051
+ });
4052
+ };
4021
4053
 
4022
4054
  function useSocket(namespace = 'default') {
4023
4055
  if (!SocketStore.manager)
@@ -6213,6 +6245,7 @@ exports.documentsService = documentsService;
6213
6245
  exports.equipmentService = equipmentService;
6214
6246
  exports.fileService = fileService;
6215
6247
  exports.historyService = historyService;
6248
+ exports.internationalizationService = internationalizationService;
6216
6249
  exports.invitationService = InvitationService;
6217
6250
  exports.metadataService = metadataService;
6218
6251
  exports.newImport = newImport;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eservices-core",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Core library",
5
5
  "author": "",
6
6
  "scripts": {
@@ -28,7 +28,6 @@
28
28
  "@types/jest": "29.4.0",
29
29
  "@types/object-hash": "^2.2.1",
30
30
  "@vue/cli-plugin-typescript": "^5.0.8",
31
- "@vue/cli-plugin-unit-jest": "^5.0.8",
32
31
  "@vue/cli-service": "^5.0.8",
33
32
  "@vue/compiler-sfc": "^3.0.0",
34
33
  "@vue/test-utils": "^2.0.0-rc.18",
@@ -38,9 +37,8 @@
38
37
  "rollup-plugin-typescript2": "0.34.1",
39
38
  "rollup-plugin-vue": "6.0.0",
40
39
  "tslib": "^2.3.1",
41
- "typescript": "~4.1.5",
40
+ "typescript": "~4.3.2",
42
41
  "vitepress": "^1.0.0-alpha.29",
43
- "vue-jest": "^5.0.0-alpha.10",
44
42
  "ts-jest": "29.0.5",
45
43
  "@vue/vue3-jest": "29.2.2"
46
44
  },