alif-ui 2.0.0-alpha.8 → 2.0.0-alpha.9
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,33 +1,40 @@
|
|
|
1
1
|
import { getDefaultLocale as e } from "../AlifProvider/AlifProvider.utils.js";
|
|
2
2
|
//#region src/lib/providers/Localization/localization.ts
|
|
3
|
-
var t = e(), n =
|
|
3
|
+
var t = e(), n = [
|
|
4
|
+
"ru",
|
|
5
|
+
"en",
|
|
6
|
+
"tj"
|
|
7
|
+
], r = new class {
|
|
4
8
|
translations = {};
|
|
5
9
|
locale = t;
|
|
6
10
|
cache = {};
|
|
7
|
-
|
|
11
|
+
loader = null;
|
|
8
12
|
constructor() {
|
|
9
13
|
if (typeof window < "u") {
|
|
10
14
|
let e = localStorage.getItem("locale");
|
|
11
15
|
e && (this.locale = e);
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
|
-
async init() {
|
|
15
|
-
this.
|
|
18
|
+
async init(e) {
|
|
19
|
+
this.loader = e, await this.load(this.locale);
|
|
16
20
|
}
|
|
17
21
|
async load(e) {
|
|
22
|
+
if (!n.includes(e)) {
|
|
23
|
+
console.error(`Invalid locale: ${e}`), this.translations = {};
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
18
26
|
if (!(e === this.locale && Object.keys(this.translations).length > 0)) {
|
|
19
27
|
if (this.cache[e]) {
|
|
20
28
|
this.translations = this.cache[e], this.locale = e;
|
|
21
29
|
return;
|
|
22
30
|
}
|
|
31
|
+
if (!this.loader) {
|
|
32
|
+
console.error("No translationsLoader provided to AlifProvider"), this.translations = {};
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
23
35
|
try {
|
|
24
|
-
let t = await
|
|
25
|
-
|
|
26
|
-
console.error(`Failed to fetch locale ${e}: ${t.status}`), this.translations = {};
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
let n = await t.json();
|
|
30
|
-
this.cache[e] = n, this.translations = n, this.locale = e;
|
|
36
|
+
let t = await this.loader(e);
|
|
37
|
+
this.cache[e] = t, this.translations = t, this.locale = e;
|
|
31
38
|
} catch (t) {
|
|
32
39
|
console.error(`Failed to load ${e} translations`, t), this.translations = {};
|
|
33
40
|
}
|
|
@@ -41,4 +48,4 @@ var t = e(), n = new class {
|
|
|
41
48
|
}
|
|
42
49
|
}();
|
|
43
50
|
//#endregion
|
|
44
|
-
export {
|
|
51
|
+
export { r as localization };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
type TranslationsLoader = (locale: string) => Promise<Record<string, any>>;
|
|
1
2
|
declare class Localization {
|
|
2
3
|
private translations;
|
|
3
4
|
private locale;
|
|
4
5
|
private cache;
|
|
5
|
-
private
|
|
6
|
+
private loader;
|
|
6
7
|
constructor();
|
|
7
|
-
init(): Promise<void>;
|
|
8
|
+
init(loader: TranslationsLoader): Promise<void>;
|
|
8
9
|
load(locale: string): Promise<void>;
|
|
9
10
|
t(key: string): string;
|
|
10
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../../../../src/lib/providers/Localization/localization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../../../../src/lib/providers/Localization/localization.ts"],"names":[],"mappings":"AAMA,KAAK,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;AAE3E,cAAM,YAAY;IAEjB,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,MAAM,CAA0B;IAExC,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,MAAM,CAAmC;;IAS3C,IAAI,CAAC,MAAM,EAAE,kBAAkB;IAK/B,IAAI,CAAC,MAAM,EAAE,MAAM;IAkCzB,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAetB;AAED,eAAO,MAAM,YAAY,cAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -21,11 +21,10 @@
|
|
|
21
21
|
},
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"private": false,
|
|
24
|
-
"version": "2.0.0-alpha.
|
|
24
|
+
"version": "2.0.0-alpha.9",
|
|
25
25
|
"type": "module",
|
|
26
26
|
"files": [
|
|
27
|
-
"dist"
|
|
28
|
-
"socket.json"
|
|
27
|
+
"dist"
|
|
29
28
|
],
|
|
30
29
|
"main": "./dist/main.js",
|
|
31
30
|
"module": "./dist/main.js",
|