@urso/core 0.4.3 → 0.4.4
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/package.json
CHANGED
|
@@ -5,9 +5,14 @@ class ModulesI18nController {
|
|
|
5
5
|
/**
|
|
6
6
|
* get text by localeId
|
|
7
7
|
* @param {String} localeId
|
|
8
|
+
* @param {Object} [localeVariables] - variables for locale string
|
|
8
9
|
*/
|
|
9
|
-
get(localeId) {
|
|
10
|
-
|
|
10
|
+
get(localeId, localeVariables = {}) {
|
|
11
|
+
if (this.#vocabulary && this.#vocabulary[localeId]) {
|
|
12
|
+
return this._interpolate(this.#vocabulary[localeId], localeVariables);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return localeId;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
/**
|
|
@@ -59,6 +64,12 @@ class ModulesI18nController {
|
|
|
59
64
|
const localeAsset = { type: Urso.types.assets.JSON, key: localeKey, path: pathToLocaleJson };
|
|
60
65
|
Urso.assets.preload(localeAsset, () => this.setLocale(localeKey));
|
|
61
66
|
}
|
|
67
|
+
|
|
68
|
+
_interpolate(string, params) {
|
|
69
|
+
const names = Object.keys(params);
|
|
70
|
+
const vals = Object.values(params);
|
|
71
|
+
return new Function(...names, `return \`${string}\`;`)(...vals);
|
|
72
|
+
}
|
|
62
73
|
}
|
|
63
74
|
|
|
64
75
|
module.exports = ModulesI18nController;
|
|
@@ -12,6 +12,8 @@ class ModulesObjectsModelsBitmapText extends Urso.Core.Modules.Objects.BaseModel
|
|
|
12
12
|
this.text = Urso.helper.recursiveGet('text', params, false);
|
|
13
13
|
this.localeId = Urso.helper.recursiveGet('localeId', params, false); //you can use this instead text for localization
|
|
14
14
|
|
|
15
|
+
this.localeVariables = Urso.helper.recursiveGet('localeVariables', params, {}); //optional variables for localization by localeId
|
|
16
|
+
|
|
15
17
|
this.fontName = Urso.helper.recursiveGet('fontName', params, false);
|
|
16
18
|
this.fontSize = Urso.helper.recursiveGet('fontSize', params, false);
|
|
17
19
|
|
|
@@ -20,13 +22,13 @@ class ModulesObjectsModelsBitmapText extends Urso.Core.Modules.Objects.BaseModel
|
|
|
20
22
|
|
|
21
23
|
_addBaseObject() {
|
|
22
24
|
if (this.localeId)
|
|
23
|
-
this._originalModel.text = this.text = Urso.i18n.get(this.localeId);
|
|
25
|
+
this._originalModel.text = this.text = Urso.i18n.get(this.localeId, this.localeVariables);
|
|
24
26
|
|
|
25
27
|
this._baseObject = new PIXI.BitmapText(this.text, { fontName: this.fontName, fontSize: this.fontSize });
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
_newLocaleHandler() {
|
|
29
|
-
this.text = this._baseObject.text = Urso.i18n.get(this.localeId);
|
|
31
|
+
this.text = this._baseObject.text = Urso.i18n.get(this.localeId, this.localeVariables);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
_subscribeOnce() {
|
|
@@ -12,6 +12,8 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
12
12
|
this.text = Urso.helper.recursiveGet('text', params, false);
|
|
13
13
|
this.localeId = Urso.helper.recursiveGet('localeId', params, false); //you can use this instead text for localization
|
|
14
14
|
|
|
15
|
+
this.localeVariables = Urso.helper.recursiveGet('localeVariables', params, {}); //optional variables for localization by localeId
|
|
16
|
+
|
|
15
17
|
this.lineHeight = Urso.helper.recursiveGet('lineHeight', params, 0);
|
|
16
18
|
this.fontFamily = Urso.helper.recursiveGet('fontFamily', params, 'Arial');
|
|
17
19
|
this.fontSize = Urso.helper.recursiveGet('fontSize', params, false);
|
|
@@ -33,13 +35,13 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
33
35
|
|
|
34
36
|
_addBaseObject() {
|
|
35
37
|
if (this.localeId)
|
|
36
|
-
this._originalModel.text = this.text = Urso.i18n.get(this.localeId);
|
|
38
|
+
this._originalModel.text = this.text = Urso.i18n.get(this.localeId, this.localeVariables);
|
|
37
39
|
|
|
38
40
|
this._baseObject = new PIXI.Text(this.text);
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
_newLocaleHandler() {
|
|
42
|
-
this.text = this._baseObject.text = Urso.i18n.get(this.localeId);
|
|
44
|
+
this.text = this._baseObject.text = Urso.i18n.get(this.localeId, this.localeVariables);
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
_subscribeOnce() {
|