eservices-core 1.1.0 → 1.1.2

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,7 +15,9 @@ 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
- export { newImport, testTypes, MetadataStore, ComputedMetadata, prettifyValueByMetadata, NotificationType, clientService };
18
+ import internationalizationService from "./services/internationalization-service";
19
+ import t from "./internationalization/translate";
20
+ export { t, newImport, testTypes, MetadataStore, ComputedMetadata, prettifyValueByMetadata, NotificationType, clientService };
19
21
  import { ICustomerContext, ApplicationType } from "./classes/ApplicationManager";
20
22
  import { IActionExecuteResult, IValidationEffect, IActionResponse } from "./services/action-service";
21
23
  import { IAffectedEntity } from "./hooks/use-form-action";
@@ -78,7 +80,7 @@ import { List, useListRead, useListState, useListOrder, useListFilter, useListCo
78
80
  import { useWizard } from "./hooks/use-wizard";
79
81
  import equipmentService from "./services/equipment-service";
80
82
  import { SYMBOL_ROW } from "./classes/table/Table";
81
- export { IListSettings, debounce, billingService, documentsService, configurationService, INotificationConfig,
83
+ export { IListSettings, debounce, billingService, documentsService, configurationService, INotificationConfig, internationalizationService,
82
84
  /**
83
85
  * @deprecated
84
86
  * */
@@ -1,16 +1,13 @@
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 setVocabulary: (scope: any) => any;
15
12
  }
16
13
  export default t;
@@ -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.0
2
+ * eservices-core v1.1.2
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,6 +4003,42 @@ function prettifyValueByMetadata(value, metadataField) {
3989
4003
  return value;
3990
4004
  }
3991
4005
 
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}`);
4014
+ }
4015
+ }
4016
+
4017
+ let store = {};
4018
+ /**
4019
+ * @description Функция принимает метку и возвращает либо нужно значение их хранилища,
4020
+ * либо новую функцию от этой метки.
4021
+ * */
4022
+ function t(label) {
4023
+ const value = jenesiusVueForm.utils.getPropFromObject(this ? this === null || this === void 0 ? void 0 : this.vocabulary : store, label);
4024
+ if (typeof value === undefined)
4025
+ console.warn(`Translation for label "${label}" is not founded.`);
4026
+ if (typeof value === 'string')
4027
+ return value;
4028
+ return label;
4029
+ }
4030
+ // Устанавливает новый глобальный словарь
4031
+ t.setGlobalVocabulary = function (newStore) {
4032
+ store = newStore;
4033
+ };
4034
+ t.setVocabulary = function (scope) {
4035
+ if (typeof scope === 'string')
4036
+ scope = jenesiusVueForm.utils.getPropFromObject(store, scope);
4037
+ return t.bind({
4038
+ vocabulary: scope
4039
+ });
4040
+ };
4041
+
3992
4042
  function useSocket(namespace = 'default') {
3993
4043
  if (!SocketStore.manager)
3994
4044
  return;
@@ -6183,6 +6233,7 @@ exports.documentsService = documentsService;
6183
6233
  exports.equipmentService = equipmentService;
6184
6234
  exports.fileService = fileService;
6185
6235
  exports.historyService = historyService;
6236
+ exports.internationalizationService = internationalizationService;
6186
6237
  exports.invitationService = InvitationService;
6187
6238
  exports.metadataService = metadataService;
6188
6239
  exports.newImport = newImport;
@@ -6193,6 +6244,7 @@ exports.processWizardService = processWizardService;
6193
6244
  exports.requestHandler = requestHandler;
6194
6245
  exports.ruleValidationService = ruleValidationService;
6195
6246
  exports.setupSocket = setupSocket;
6247
+ exports.t = t;
6196
6248
  exports.testTypes = main;
6197
6249
  exports.useCommunication = useCommunication;
6198
6250
  exports.useCustomerState = useCustomerState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eservices-core",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
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
  },