@flashist/flibs 0.0.265 → 0.0.267
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.
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { ILocaleConfig } from "./ILocaleConfig";
|
|
2
2
|
export declare class LocaleManager {
|
|
3
3
|
protected localeToIdMap: any;
|
|
4
|
-
private
|
|
5
|
-
protected
|
|
4
|
+
private _currentLocaleId;
|
|
5
|
+
protected currentLocaleTexts: ILocaleConfig;
|
|
6
|
+
protected defaultLocaleId: string;
|
|
6
7
|
useTextLinks: boolean;
|
|
7
8
|
protected bindMethodReplaceRegExpKeyByStrings: (substring: string, ...params: any[]) => string;
|
|
8
9
|
constructor();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
addLocaleTexts(data: ILocaleConfig, localeId: string): void;
|
|
11
|
+
getCurrentLocaleId(): string;
|
|
12
|
+
setCurrentLocaleId(value: string): void;
|
|
12
13
|
protected commitLocaleData(): void;
|
|
13
14
|
getText(textId: string, params?: any): string;
|
|
14
15
|
protected format(str: string, params?: any): string;
|
package/locale/LocaleManager.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ObjectTools, StringTools } from "@flashist/fcore";
|
|
2
2
|
import { getInstance } from "../servicelocator/ServiceLocatorShortcuts";
|
|
3
|
+
import { LocaleId } from "./LocaleId";
|
|
3
4
|
export class LocaleManager {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.useTextLinks = true;
|
|
6
7
|
this.localeToIdMap = {};
|
|
7
8
|
this.bindMethodReplaceRegExpKeyByStrings = this.replaceRegExpKeyByStrings.bind(this);
|
|
8
|
-
this.
|
|
9
|
+
this.defaultLocaleId = LocaleId.EN;
|
|
10
|
+
this.setCurrentLocaleId("");
|
|
9
11
|
}
|
|
10
|
-
|
|
12
|
+
addLocaleTexts(data, localeId) {
|
|
11
13
|
// Support adding texts to the old localization
|
|
12
14
|
let oldLocale = {
|
|
13
15
|
texts: {}
|
|
@@ -20,25 +22,30 @@ export class LocaleManager {
|
|
|
20
22
|
this.localeToIdMap[localeId] = oldLocale;
|
|
21
23
|
this.commitLocaleData();
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
return this.
|
|
25
|
+
getCurrentLocaleId() {
|
|
26
|
+
return this._currentLocaleId;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
if (value == this.
|
|
28
|
+
setCurrentLocaleId(value) {
|
|
29
|
+
if (value == this._currentLocaleId) {
|
|
28
30
|
return;
|
|
29
31
|
}
|
|
30
|
-
this.
|
|
32
|
+
this._currentLocaleId = value;
|
|
31
33
|
this.commitLocaleData();
|
|
32
34
|
}
|
|
33
35
|
commitLocaleData() {
|
|
34
|
-
this.
|
|
36
|
+
// this.currentLocaleTexts = this.localeToIdMap[this._currentLocaleId];
|
|
37
|
+
let newLocaleTexts = this.localeToIdMap[this._currentLocaleId];
|
|
38
|
+
if (!newLocaleTexts) {
|
|
39
|
+
newLocaleTexts = this.localeToIdMap[this.defaultLocaleId];
|
|
40
|
+
}
|
|
41
|
+
this.currentLocaleTexts = newLocaleTexts;
|
|
35
42
|
}
|
|
36
43
|
getText(textId, params = null) {
|
|
37
44
|
// The text id will be used in the case of no text found
|
|
38
45
|
let result = textId;
|
|
39
|
-
if (this.
|
|
46
|
+
if (this.currentLocaleTexts) {
|
|
40
47
|
const pathsToText = textId.split(".");
|
|
41
|
-
let curPathLevel = this.
|
|
48
|
+
let curPathLevel = this.currentLocaleTexts.texts;
|
|
42
49
|
const pathsCount = pathsToText.length;
|
|
43
50
|
for (let pathIndex = 0; pathIndex < pathsCount; pathIndex++) {
|
|
44
51
|
const tempPathId = pathsToText[pathIndex];
|
|
@@ -80,7 +87,7 @@ export class LocaleManager {
|
|
|
80
87
|
}
|
|
81
88
|
findAllUniqueCharactersForCurrentLocale() {
|
|
82
89
|
const allTexts = [];
|
|
83
|
-
this.getAllTextsOf(this.
|
|
90
|
+
this.getAllTextsOf(this.currentLocaleTexts.texts, allTexts);
|
|
84
91
|
let usedCharactersMap = {};
|
|
85
92
|
let result = [];
|
|
86
93
|
for (let singleText of allTexts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocaleManager.js","sourceRoot":"","sources":["../../src/locale/LocaleManager.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"LocaleManager.js","sourceRoot":"","sources":["../../src/locale/LocaleManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAGxE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,OAAO,aAAa;IAYtB;QAJO,iBAAY,GAAY,IAAI,CAAC;QAKhC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,mCAAmC,GAAG,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErF,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,EAAE,CAAC;QAEnC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC;IAEM,cAAc,CAAC,IAAmB,EAAE,QAAgB;QACvD,+CAA+C;QAC/C,IAAI,SAAS,GAAkB;YAC3B,KAAK,EAAE,EAAE;SACZ,CAAC;QACF,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE;YAC9B,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;SAC5C;QAED,sDAAsD;QACrD,MAAc,CAAC,MAAM,CAClB,SAAS,CAAC,KAAK,EACf,IAAI,CAAC,KAAK,CACb,CAAC;QAEF,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;QAEzC,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC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