@etsoo/appscript 1.3.5 → 1.3.6
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.
- package/__tests__/app/CoreApp.ts +1 -1
- package/lib/cjs/address/AddressUtils.d.ts +20 -0
- package/lib/cjs/address/AddressUtils.js +60 -0
- package/lib/cjs/app/CoreApp.js +2 -0
- package/lib/cjs/erp/AddressApi.d.ts +0 -8
- package/lib/cjs/erp/AddressApi.js +4 -45
- package/lib/mjs/address/AddressUtils.d.ts +20 -0
- package/lib/mjs/address/AddressUtils.js +37 -0
- package/lib/mjs/app/CoreApp.js +2 -0
- package/lib/mjs/erp/AddressApi.d.ts +0 -8
- package/lib/mjs/erp/AddressApi.js +4 -22
- package/package.json +1 -1
- package/src/address/AddressUtils.ts +45 -0
- package/src/app/CoreApp.ts +2 -0
- package/src/erp/AddressApi.ts +6 -23
package/__tests__/app/CoreApp.ts
CHANGED
|
@@ -201,7 +201,7 @@ test('Tests for addressApi', async () => {
|
|
|
201
201
|
const continents = await app.addressApi.continents();
|
|
202
202
|
expect(continents.length).toBe(7);
|
|
203
203
|
|
|
204
|
-
const labels = await
|
|
204
|
+
const labels = await AddressUtils.getLabels('en-US');
|
|
205
205
|
expect(labels['regionHK']).toBe('Hong Kong, China');
|
|
206
206
|
|
|
207
207
|
const regions = await app.addressApi.regions('zh-CN');
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
1
2
|
import { AddressRegion } from './AddressRegion';
|
|
2
3
|
/**
|
|
3
4
|
* Address utils
|
|
4
5
|
*/
|
|
5
6
|
export declare namespace AddressUtils {
|
|
7
|
+
/**
|
|
8
|
+
* Get address labels
|
|
9
|
+
* @param language Language
|
|
10
|
+
* @returns Result
|
|
11
|
+
*/
|
|
12
|
+
function getLabels(language: string): Promise<DataTypes.StringRecord>;
|
|
6
13
|
/**
|
|
7
14
|
* Get region from regions and detected region and language
|
|
8
15
|
* @param regions Supported regions
|
|
@@ -10,4 +17,17 @@ export declare namespace AddressUtils {
|
|
|
10
17
|
* @param detectedLanguage Detected language
|
|
11
18
|
*/
|
|
12
19
|
function getRegion(regions: string[], detectedRegion?: string | null, detectedLanguage?: string | null): AddressRegion;
|
|
20
|
+
/**
|
|
21
|
+
* Get region label
|
|
22
|
+
* @param id Region id
|
|
23
|
+
* @param labels Labels
|
|
24
|
+
* @returns Label
|
|
25
|
+
*/
|
|
26
|
+
function getRegionLabel(id: string, labels: DataTypes.StringRecord): string;
|
|
27
|
+
/**
|
|
28
|
+
* Update region label
|
|
29
|
+
* @param region Region
|
|
30
|
+
* @param culture Culture
|
|
31
|
+
*/
|
|
32
|
+
function updateRegionLabel(region: AddressRegion, culture: string): Promise<void>;
|
|
13
33
|
}
|
|
@@ -1,12 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.AddressUtils = void 0;
|
|
4
27
|
const AddressRegion_1 = require("./AddressRegion");
|
|
28
|
+
const languageLabels = {};
|
|
5
29
|
/**
|
|
6
30
|
* Address utils
|
|
7
31
|
*/
|
|
8
32
|
var AddressUtils;
|
|
9
33
|
(function (AddressUtils) {
|
|
34
|
+
/**
|
|
35
|
+
* Get address labels
|
|
36
|
+
* @param language Language
|
|
37
|
+
* @returns Result
|
|
38
|
+
*/
|
|
39
|
+
async function getLabels(language) {
|
|
40
|
+
let labels = languageLabels[language];
|
|
41
|
+
if (labels == null) {
|
|
42
|
+
labels = await Promise.resolve().then(() => __importStar(require(`./../i18n/address.${language}.json`)));
|
|
43
|
+
// Cache
|
|
44
|
+
languageLabels[language] = labels;
|
|
45
|
+
}
|
|
46
|
+
return labels;
|
|
47
|
+
}
|
|
48
|
+
AddressUtils.getLabels = getLabels;
|
|
10
49
|
/**
|
|
11
50
|
* Get region from regions and detected region and language
|
|
12
51
|
* @param regions Supported regions
|
|
@@ -32,4 +71,25 @@ var AddressUtils;
|
|
|
32
71
|
return AddressRegion_1.AddressRegion.getById(regions[0]);
|
|
33
72
|
}
|
|
34
73
|
AddressUtils.getRegion = getRegion;
|
|
74
|
+
/**
|
|
75
|
+
* Get region label
|
|
76
|
+
* @param id Region id
|
|
77
|
+
* @param labels Labels
|
|
78
|
+
* @returns Label
|
|
79
|
+
*/
|
|
80
|
+
function getRegionLabel(id, labels) {
|
|
81
|
+
var _a;
|
|
82
|
+
return (_a = labels['region' + id]) !== null && _a !== void 0 ? _a : id;
|
|
83
|
+
}
|
|
84
|
+
AddressUtils.getRegionLabel = getRegionLabel;
|
|
85
|
+
/**
|
|
86
|
+
* Update region label
|
|
87
|
+
* @param region Region
|
|
88
|
+
* @param culture Culture
|
|
89
|
+
*/
|
|
90
|
+
async function updateRegionLabel(region, culture) {
|
|
91
|
+
const labels = await AddressUtils.getLabels(culture);
|
|
92
|
+
region.label = getRegionLabel(region.id, labels);
|
|
93
|
+
}
|
|
94
|
+
AddressUtils.updateRegionLabel = updateRegionLabel;
|
|
35
95
|
})(AddressUtils = exports.AddressUtils || (exports.AddressUtils = {}));
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -6,6 +6,7 @@ const restclient_1 = require("@etsoo/restclient");
|
|
|
6
6
|
const shared_1 = require("@etsoo/shared");
|
|
7
7
|
const crypto_js_1 = require("crypto-js");
|
|
8
8
|
const AddressRegion_1 = require("../address/AddressRegion");
|
|
9
|
+
const AddressUtils_1 = require("../address/AddressUtils");
|
|
9
10
|
const BridgeUtils_1 = require("../bridges/BridgeUtils");
|
|
10
11
|
const EntityStatus_1 = require("../business/EntityStatus");
|
|
11
12
|
const ActionResultError_1 = require("../result/ActionResultError");
|
|
@@ -486,6 +487,7 @@ class CoreApp {
|
|
|
486
487
|
this._currency = regionItem.currency;
|
|
487
488
|
this._region = regionId;
|
|
488
489
|
// Hold the current country or region
|
|
490
|
+
AddressUtils_1.AddressUtils.updateRegionLabel(regionItem, this._culture);
|
|
489
491
|
this.settings.currentRegion = regionItem;
|
|
490
492
|
}
|
|
491
493
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
2
1
|
import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
|
|
3
2
|
import { AddressState } from '../address/AddressState';
|
|
4
3
|
import { IdLabelConditional } from '../dto/IdLabelDto';
|
|
@@ -7,13 +6,6 @@ import { BaseApi } from './BaseApi';
|
|
|
7
6
|
* Address Api
|
|
8
7
|
*/
|
|
9
8
|
export declare class AddressApi extends BaseApi {
|
|
10
|
-
private languageLabels;
|
|
11
|
-
/**
|
|
12
|
-
* Get address labels
|
|
13
|
-
* @param language Language
|
|
14
|
-
* @returns Result
|
|
15
|
-
*/
|
|
16
|
-
getLabels(language?: string): Promise<DataTypes.StringRecord>;
|
|
17
9
|
/**
|
|
18
10
|
* Get all continents
|
|
19
11
|
* @param language Language
|
|
@@ -1,56 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.AddressApi = void 0;
|
|
27
4
|
const shared_1 = require("@etsoo/shared");
|
|
28
5
|
const AddressContinent_1 = require("../address/AddressContinent");
|
|
29
6
|
const AddressRegion_1 = require("../address/AddressRegion");
|
|
7
|
+
const AddressUtils_1 = require("../address/AddressUtils");
|
|
30
8
|
const BaseApi_1 = require("./BaseApi");
|
|
31
9
|
/**
|
|
32
10
|
* Address Api
|
|
33
11
|
*/
|
|
34
12
|
class AddressApi extends BaseApi_1.BaseApi {
|
|
35
|
-
constructor() {
|
|
36
|
-
super(...arguments);
|
|
37
|
-
this.languageLabels = {};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Get address labels
|
|
41
|
-
* @param language Language
|
|
42
|
-
* @returns Result
|
|
43
|
-
*/
|
|
44
|
-
async getLabels(language) {
|
|
45
|
-
const l = this.app.checkLanguage(language);
|
|
46
|
-
let labels = this.languageLabels[l];
|
|
47
|
-
if (labels == null) {
|
|
48
|
-
labels = await Promise.resolve().then(() => __importStar(require(`./../i18n/address.${l}.json`)));
|
|
49
|
-
// Cache
|
|
50
|
-
this.languageLabels[l] = labels;
|
|
51
|
-
}
|
|
52
|
-
return labels;
|
|
53
|
-
}
|
|
54
13
|
/**
|
|
55
14
|
* Get all continents
|
|
56
15
|
* @param language Language
|
|
@@ -58,7 +17,7 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
58
17
|
* @returns Continents
|
|
59
18
|
*/
|
|
60
19
|
async continents(language, isNumberKey = false) {
|
|
61
|
-
const labels = await
|
|
20
|
+
const labels = await AddressUtils_1.AddressUtils.getLabels(this.app.checkLanguage(language));
|
|
62
21
|
return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => {
|
|
63
22
|
var _a;
|
|
64
23
|
return ({
|
|
@@ -78,9 +37,9 @@ class AddressApi extends BaseApi_1.BaseApi {
|
|
|
78
37
|
async regions(language, isLocal) {
|
|
79
38
|
language = this.app.checkLanguage(language);
|
|
80
39
|
if (isLocal == null || isLocal) {
|
|
81
|
-
const labels = await
|
|
40
|
+
const labels = await AddressUtils_1.AddressUtils.getLabels(language);
|
|
82
41
|
return AddressRegion_1.AddressRegion.all.map((region) => {
|
|
83
|
-
region.label =
|
|
42
|
+
region.label = AddressUtils_1.AddressUtils.getRegionLabel(region.id, labels);
|
|
84
43
|
return { ...region };
|
|
85
44
|
});
|
|
86
45
|
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
1
2
|
import { AddressRegion } from './AddressRegion';
|
|
2
3
|
/**
|
|
3
4
|
* Address utils
|
|
4
5
|
*/
|
|
5
6
|
export declare namespace AddressUtils {
|
|
7
|
+
/**
|
|
8
|
+
* Get address labels
|
|
9
|
+
* @param language Language
|
|
10
|
+
* @returns Result
|
|
11
|
+
*/
|
|
12
|
+
function getLabels(language: string): Promise<DataTypes.StringRecord>;
|
|
6
13
|
/**
|
|
7
14
|
* Get region from regions and detected region and language
|
|
8
15
|
* @param regions Supported regions
|
|
@@ -10,4 +17,17 @@ export declare namespace AddressUtils {
|
|
|
10
17
|
* @param detectedLanguage Detected language
|
|
11
18
|
*/
|
|
12
19
|
function getRegion(regions: string[], detectedRegion?: string | null, detectedLanguage?: string | null): AddressRegion;
|
|
20
|
+
/**
|
|
21
|
+
* Get region label
|
|
22
|
+
* @param id Region id
|
|
23
|
+
* @param labels Labels
|
|
24
|
+
* @returns Label
|
|
25
|
+
*/
|
|
26
|
+
function getRegionLabel(id: string, labels: DataTypes.StringRecord): string;
|
|
27
|
+
/**
|
|
28
|
+
* Update region label
|
|
29
|
+
* @param region Region
|
|
30
|
+
* @param culture Culture
|
|
31
|
+
*/
|
|
32
|
+
function updateRegionLabel(region: AddressRegion, culture: string): Promise<void>;
|
|
13
33
|
}
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import { AddressRegion } from './AddressRegion';
|
|
2
|
+
const languageLabels = {};
|
|
2
3
|
/**
|
|
3
4
|
* Address utils
|
|
4
5
|
*/
|
|
5
6
|
export var AddressUtils;
|
|
6
7
|
(function (AddressUtils) {
|
|
8
|
+
/**
|
|
9
|
+
* Get address labels
|
|
10
|
+
* @param language Language
|
|
11
|
+
* @returns Result
|
|
12
|
+
*/
|
|
13
|
+
async function getLabels(language) {
|
|
14
|
+
let labels = languageLabels[language];
|
|
15
|
+
if (labels == null) {
|
|
16
|
+
labels = await import(`./../i18n/address.${language}.json`);
|
|
17
|
+
// Cache
|
|
18
|
+
languageLabels[language] = labels;
|
|
19
|
+
}
|
|
20
|
+
return labels;
|
|
21
|
+
}
|
|
22
|
+
AddressUtils.getLabels = getLabels;
|
|
7
23
|
/**
|
|
8
24
|
* Get region from regions and detected region and language
|
|
9
25
|
* @param regions Supported regions
|
|
@@ -29,4 +45,25 @@ export var AddressUtils;
|
|
|
29
45
|
return AddressRegion.getById(regions[0]);
|
|
30
46
|
}
|
|
31
47
|
AddressUtils.getRegion = getRegion;
|
|
48
|
+
/**
|
|
49
|
+
* Get region label
|
|
50
|
+
* @param id Region id
|
|
51
|
+
* @param labels Labels
|
|
52
|
+
* @returns Label
|
|
53
|
+
*/
|
|
54
|
+
function getRegionLabel(id, labels) {
|
|
55
|
+
var _a;
|
|
56
|
+
return (_a = labels['region' + id]) !== null && _a !== void 0 ? _a : id;
|
|
57
|
+
}
|
|
58
|
+
AddressUtils.getRegionLabel = getRegionLabel;
|
|
59
|
+
/**
|
|
60
|
+
* Update region label
|
|
61
|
+
* @param region Region
|
|
62
|
+
* @param culture Culture
|
|
63
|
+
*/
|
|
64
|
+
async function updateRegionLabel(region, culture) {
|
|
65
|
+
const labels = await AddressUtils.getLabels(culture);
|
|
66
|
+
region.label = getRegionLabel(region.id, labels);
|
|
67
|
+
}
|
|
68
|
+
AddressUtils.updateRegionLabel = updateRegionLabel;
|
|
32
69
|
})(AddressUtils || (AddressUtils = {}));
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -3,6 +3,7 @@ import { ApiDataError } from '@etsoo/restclient';
|
|
|
3
3
|
import { DataTypes, DateUtils, DomUtils, NumberUtils, Utils } from '@etsoo/shared';
|
|
4
4
|
import { AES, algo, enc, HmacSHA512, lib, mode, pad, PBKDF2, SHA3 } from 'crypto-js';
|
|
5
5
|
import { AddressRegion } from '../address/AddressRegion';
|
|
6
|
+
import { AddressUtils } from '../address/AddressUtils';
|
|
6
7
|
import { BridgeUtils } from '../bridges/BridgeUtils';
|
|
7
8
|
import { EntityStatus } from '../business/EntityStatus';
|
|
8
9
|
import { ActionResultError } from '../result/ActionResultError';
|
|
@@ -483,6 +484,7 @@ export class CoreApp {
|
|
|
483
484
|
this._currency = regionItem.currency;
|
|
484
485
|
this._region = regionId;
|
|
485
486
|
// Hold the current country or region
|
|
487
|
+
AddressUtils.updateRegionLabel(regionItem, this._culture);
|
|
486
488
|
this.settings.currentRegion = regionItem;
|
|
487
489
|
}
|
|
488
490
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
2
1
|
import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
|
|
3
2
|
import { AddressState } from '../address/AddressState';
|
|
4
3
|
import { IdLabelConditional } from '../dto/IdLabelDto';
|
|
@@ -7,13 +6,6 @@ import { BaseApi } from './BaseApi';
|
|
|
7
6
|
* Address Api
|
|
8
7
|
*/
|
|
9
8
|
export declare class AddressApi extends BaseApi {
|
|
10
|
-
private languageLabels;
|
|
11
|
-
/**
|
|
12
|
-
* Get address labels
|
|
13
|
-
* @param language Language
|
|
14
|
-
* @returns Result
|
|
15
|
-
*/
|
|
16
|
-
getLabels(language?: string): Promise<DataTypes.StringRecord>;
|
|
17
9
|
/**
|
|
18
10
|
* Get all continents
|
|
19
11
|
* @param language Language
|
|
@@ -1,30 +1,12 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { AddressContinent } from '../address/AddressContinent';
|
|
3
3
|
import { AddressRegion } from '../address/AddressRegion';
|
|
4
|
+
import { AddressUtils } from '../address/AddressUtils';
|
|
4
5
|
import { BaseApi } from './BaseApi';
|
|
5
6
|
/**
|
|
6
7
|
* Address Api
|
|
7
8
|
*/
|
|
8
9
|
export class AddressApi extends BaseApi {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
this.languageLabels = {};
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Get address labels
|
|
15
|
-
* @param language Language
|
|
16
|
-
* @returns Result
|
|
17
|
-
*/
|
|
18
|
-
async getLabels(language) {
|
|
19
|
-
const l = this.app.checkLanguage(language);
|
|
20
|
-
let labels = this.languageLabels[l];
|
|
21
|
-
if (labels == null) {
|
|
22
|
-
labels = await import(`./../i18n/address.${l}.json`);
|
|
23
|
-
// Cache
|
|
24
|
-
this.languageLabels[l] = labels;
|
|
25
|
-
}
|
|
26
|
-
return labels;
|
|
27
|
-
}
|
|
28
10
|
/**
|
|
29
11
|
* Get all continents
|
|
30
12
|
* @param language Language
|
|
@@ -32,7 +14,7 @@ export class AddressApi extends BaseApi {
|
|
|
32
14
|
* @returns Continents
|
|
33
15
|
*/
|
|
34
16
|
async continents(language, isNumberKey = false) {
|
|
35
|
-
const labels = await
|
|
17
|
+
const labels = await AddressUtils.getLabels(this.app.checkLanguage(language));
|
|
36
18
|
return DataTypes.getEnumKeys(AddressContinent).map((key) => {
|
|
37
19
|
var _a;
|
|
38
20
|
return ({
|
|
@@ -52,9 +34,9 @@ export class AddressApi extends BaseApi {
|
|
|
52
34
|
async regions(language, isLocal) {
|
|
53
35
|
language = this.app.checkLanguage(language);
|
|
54
36
|
if (isLocal == null || isLocal) {
|
|
55
|
-
const labels = await
|
|
37
|
+
const labels = await AddressUtils.getLabels(language);
|
|
56
38
|
return AddressRegion.all.map((region) => {
|
|
57
|
-
region.label =
|
|
39
|
+
region.label = AddressUtils.getRegionLabel(region.id, labels);
|
|
58
40
|
return { ...region };
|
|
59
41
|
});
|
|
60
42
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
1
2
|
import { AddressRegion } from './AddressRegion';
|
|
2
3
|
|
|
4
|
+
const languageLabels: Record<string, DataTypes.StringRecord | undefined> = {};
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Address utils
|
|
5
8
|
*/
|
|
6
9
|
export namespace AddressUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Get address labels
|
|
12
|
+
* @param language Language
|
|
13
|
+
* @returns Result
|
|
14
|
+
*/
|
|
15
|
+
export async function getLabels(language: string) {
|
|
16
|
+
let labels = languageLabels[language];
|
|
17
|
+
if (labels == null) {
|
|
18
|
+
labels = await import(`./../i18n/address.${language}.json`);
|
|
19
|
+
|
|
20
|
+
// Cache
|
|
21
|
+
languageLabels[language] = labels;
|
|
22
|
+
}
|
|
23
|
+
return labels!;
|
|
24
|
+
}
|
|
25
|
+
|
|
7
26
|
/**
|
|
8
27
|
* Get region from regions and detected region and language
|
|
9
28
|
* @param regions Supported regions
|
|
@@ -32,4 +51,30 @@ export namespace AddressUtils {
|
|
|
32
51
|
// Default
|
|
33
52
|
return AddressRegion.getById(regions[0])!;
|
|
34
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get region label
|
|
57
|
+
* @param id Region id
|
|
58
|
+
* @param labels Labels
|
|
59
|
+
* @returns Label
|
|
60
|
+
*/
|
|
61
|
+
export function getRegionLabel(
|
|
62
|
+
id: string,
|
|
63
|
+
labels: DataTypes.StringRecord
|
|
64
|
+
): string {
|
|
65
|
+
return (labels['region' + id] as string) ?? id;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Update region label
|
|
70
|
+
* @param region Region
|
|
71
|
+
* @param culture Culture
|
|
72
|
+
*/
|
|
73
|
+
export async function updateRegionLabel(
|
|
74
|
+
region: AddressRegion,
|
|
75
|
+
culture: string
|
|
76
|
+
) {
|
|
77
|
+
const labels = await AddressUtils.getLabels(culture);
|
|
78
|
+
region.label = getRegionLabel(region.id, labels);
|
|
79
|
+
}
|
|
35
80
|
}
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
SHA3
|
|
31
31
|
} from 'crypto-js';
|
|
32
32
|
import { AddressRegion } from '../address/AddressRegion';
|
|
33
|
+
import { AddressUtils } from '../address/AddressUtils';
|
|
33
34
|
import { BridgeUtils } from '../bridges/BridgeUtils';
|
|
34
35
|
import { EntityStatus } from '../business/EntityStatus';
|
|
35
36
|
import { InitCallDto } from '../dto/InitCallDto';
|
|
@@ -717,6 +718,7 @@ export abstract class CoreApp<
|
|
|
717
718
|
this._region = regionId;
|
|
718
719
|
|
|
719
720
|
// Hold the current country or region
|
|
721
|
+
AddressUtils.updateRegionLabel(regionItem, this._culture);
|
|
720
722
|
this.settings.currentRegion = regionItem;
|
|
721
723
|
}
|
|
722
724
|
|
package/src/erp/AddressApi.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { DataTypes } from '@etsoo/shared';
|
|
|
2
2
|
import { AddressContinent } from '../address/AddressContinent';
|
|
3
3
|
import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
|
|
4
4
|
import { AddressState } from '../address/AddressState';
|
|
5
|
+
import { AddressUtils } from '../address/AddressUtils';
|
|
5
6
|
import { IdLabelConditional } from '../dto/IdLabelDto';
|
|
6
7
|
import { BaseApi } from './BaseApi';
|
|
7
8
|
|
|
@@ -9,26 +10,6 @@ import { BaseApi } from './BaseApi';
|
|
|
9
10
|
* Address Api
|
|
10
11
|
*/
|
|
11
12
|
export class AddressApi extends BaseApi {
|
|
12
|
-
private languageLabels: Record<string, DataTypes.StringRecord | undefined> =
|
|
13
|
-
{};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get address labels
|
|
17
|
-
* @param language Language
|
|
18
|
-
* @returns Result
|
|
19
|
-
*/
|
|
20
|
-
async getLabels(language?: string) {
|
|
21
|
-
const l = this.app.checkLanguage(language);
|
|
22
|
-
let labels = this.languageLabels[l];
|
|
23
|
-
if (labels == null) {
|
|
24
|
-
labels = await import(`./../i18n/address.${l}.json`);
|
|
25
|
-
|
|
26
|
-
// Cache
|
|
27
|
-
this.languageLabels[l] = labels;
|
|
28
|
-
}
|
|
29
|
-
return labels!;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
13
|
/**
|
|
33
14
|
* Get all continents
|
|
34
15
|
* @param language Language
|
|
@@ -39,7 +20,9 @@ export class AddressApi extends BaseApi {
|
|
|
39
20
|
language?: string,
|
|
40
21
|
isNumberKey = <T>false
|
|
41
22
|
): Promise<IdLabelConditional<T>> {
|
|
42
|
-
const labels = await
|
|
23
|
+
const labels = await AddressUtils.getLabels(
|
|
24
|
+
this.app.checkLanguage(language)
|
|
25
|
+
);
|
|
43
26
|
return <IdLabelConditional<T>>DataTypes.getEnumKeys(
|
|
44
27
|
AddressContinent
|
|
45
28
|
).map((key) => ({
|
|
@@ -66,9 +49,9 @@ export class AddressApi extends BaseApi {
|
|
|
66
49
|
> {
|
|
67
50
|
language = this.app.checkLanguage(language);
|
|
68
51
|
if (isLocal == null || isLocal) {
|
|
69
|
-
const labels = await
|
|
52
|
+
const labels = await AddressUtils.getLabels(language);
|
|
70
53
|
return AddressRegion.all.map((region) => {
|
|
71
|
-
region.label =
|
|
54
|
+
region.label = AddressUtils.getRegionLabel(region.id, labels);
|
|
72
55
|
return { ...region };
|
|
73
56
|
});
|
|
74
57
|
} else {
|