pome-ui 2.0.0-preview18 → 2.0.0-preview19
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 +1 -1
- package/pome-localization.js +6 -0
- package/pome-localization.min.js +1 -1
package/package.json
CHANGED
package/pome-localization.js
CHANGED
|
@@ -4,12 +4,16 @@
|
|
|
4
4
|
function create() {
|
|
5
5
|
var currentLocale = null;
|
|
6
6
|
return {
|
|
7
|
+
localesGroups: [],
|
|
7
8
|
locales: {},
|
|
8
9
|
texts: {},
|
|
9
10
|
overrides: {},
|
|
10
11
|
getCurrentLocale() {
|
|
11
12
|
return currentLocale;
|
|
12
13
|
},
|
|
14
|
+
getLocalesGroups() {
|
|
15
|
+
return this.localesGroups;
|
|
16
|
+
},
|
|
13
17
|
addLocale(path, locales, isFallback) {
|
|
14
18
|
if (!locales) {
|
|
15
19
|
var index = path.lastIndexOf('/');
|
|
@@ -21,6 +25,8 @@ function create() {
|
|
|
21
25
|
locales = locales.split('.')[0];
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
this.localesGroups.push(locales);
|
|
29
|
+
|
|
24
30
|
if (typeof locales == 'string') {
|
|
25
31
|
this.locales[locales] = path;
|
|
26
32
|
} else if (locales instanceof Array) {
|
package/pome-localization.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function create(){var
|
|
1
|
+
function create(){var s=null;return{localesGroups:[],locales:{},texts:{},overrides:{},getCurrentLocale(){return s},getLocalesGroups(){return this.localesGroups},addLocale(e,t,l){if(!t){var r=e.lastIndexOf("/");if(r<0){t=e}else{t=e.substr(e,r+1)}t=t.split(".")[0]}this.localesGroups.push(t);if(typeof t=="string"){this.locales[t]=e}else if(t instanceof Array){for(var s=0;s<t.length;++s){this.locales[t[s]]=e}}if(l){this.locales["fallback"]=e}},setLocale(e){if(!e){e=!window.localStorage.locale?window.navigator.language:window.localStorage.locale}if(!this.locales[e]){e="fallback"}if(!this.locales[e]){throw"No available translations for the locale"}s=e;this.texts=require(this.locales[e]).texts;if(this.locales["fallback"]){if(this.locales[e]!=this.locales["fallback"]){var t=require(this.locales["fallback"]).texts;var l=Object.getOwnPropertyNames(t);var r=this;l.forEach(function(e){if(!r.texts[e]){r.texts[e]=t[e]}})}}},sr(){if(arguments.length==0){return null}var e=arguments[0];var t=e;var l=false;if(this.overrides[this.getCurrentLocale()]&&this.overrides[this.getCurrentLocale()][e]){t=this.overrides[this.getCurrentLocale()][e];l=true}if(!l&&this.texts[e]){t=this.texts[e]}for(var r=1;r<arguments.length;++r){t=t.replaceAll(`{${r-1}}`,arguments[r])}return t},setLocalizedString(e,t,l){var r=this;e.forEach(function(e){if(!r.overrides[e]){r.overrides[e]={}}r.overrides[e][t]=l})}}}exports.create=create;
|