@pisell/core 1.0.4 → 1.0.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/es/locales/index.d.ts +13 -13
- package/es/locales/index.js +50 -68
- package/es/routes/index.js +4 -1
- package/es/storage/index.d.ts +5 -5
- package/es/storage/index.js +35 -48
- package/lib/locales/index.d.ts +13 -13
- package/lib/locales/index.js +57 -57
- package/lib/routes/index.js +1 -0
- package/lib/storage/index.d.ts +5 -5
- package/lib/storage/index.js +22 -22
- package/package.json +1 -1
package/es/locales/index.d.ts
CHANGED
|
@@ -13,27 +13,27 @@ export declare class Locales {
|
|
|
13
13
|
[key in Locale]: LibraryItem;
|
|
14
14
|
};
|
|
15
15
|
constructor(app: App, options?: LocalesOptions);
|
|
16
|
-
getLocale()
|
|
17
|
-
getCurrentTexts(locale?: Locale)
|
|
16
|
+
getLocale: () => string;
|
|
17
|
+
getCurrentTexts: (locale?: Locale) => {
|
|
18
18
|
[key: string]: string;
|
|
19
19
|
};
|
|
20
|
-
setLocale(locale: Locale, reload?: boolean)
|
|
21
|
-
getText(id: string, locale?: Locale)
|
|
22
|
-
isCN()
|
|
20
|
+
setLocale: (locale: Locale, reload?: boolean) => void;
|
|
21
|
+
getText: (id: string, locale?: Locale) => string;
|
|
22
|
+
isCN: () => boolean;
|
|
23
23
|
loadLibraryByUrl: (urls: LoadLibraryByUrlParams) => Promise<{
|
|
24
24
|
[x: string]: LibraryItem;
|
|
25
25
|
}>;
|
|
26
26
|
loadLibraryByItems(libraryList: LibraryItem[]): void;
|
|
27
|
-
loadLibrary(urls: LoadLibraryByUrlParams)
|
|
27
|
+
loadLibrary: (urls: LoadLibraryByUrlParams) => Promise<{
|
|
28
28
|
[x: string]: LibraryItem;
|
|
29
29
|
}>;
|
|
30
|
-
translation(text: string | {
|
|
31
|
-
[key:
|
|
32
|
-
}, locale?: Locale)
|
|
33
|
-
getLibraryByData(data: LibraryItem[])
|
|
34
|
-
createTextsByLibrary(id: string, library?: {
|
|
35
|
-
[
|
|
36
|
-
})
|
|
30
|
+
translation: (text: string | {
|
|
31
|
+
[key: string]: string;
|
|
32
|
+
}, locale?: Locale) => string | number;
|
|
33
|
+
getLibraryByData: (data: LibraryItem[]) => LibraryItem;
|
|
34
|
+
createTextsByLibrary: (id: string, library?: {
|
|
35
|
+
[x: string]: LibraryItem;
|
|
36
|
+
} | undefined) => {
|
|
37
37
|
[x: string]: string;
|
|
38
38
|
};
|
|
39
39
|
}
|
package/es/locales/index.js
CHANGED
|
@@ -32,6 +32,28 @@ export var Locales = /*#__PURE__*/function () {
|
|
|
32
32
|
pre[cur.locale] = cur;
|
|
33
33
|
return pre;
|
|
34
34
|
}, {}));
|
|
35
|
+
_defineProperty(this, "getLocale", function () {
|
|
36
|
+
return _this.locale;
|
|
37
|
+
});
|
|
38
|
+
_defineProperty(this, "getCurrentTexts", function (locale) {
|
|
39
|
+
return _this.library[locale || _this.locale].translations;
|
|
40
|
+
});
|
|
41
|
+
_defineProperty(this, "setLocale", function (locale) {
|
|
42
|
+
var reload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
43
|
+
_this.locale = locale;
|
|
44
|
+
if (reload) {
|
|
45
|
+
window.location.reload();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
_defineProperty(this, "getText", function (id, locale) {
|
|
50
|
+
var _this$getCurrentTexts;
|
|
51
|
+
return ((_this$getCurrentTexts = _this.getCurrentTexts(locale)) === null || _this$getCurrentTexts === void 0 ? void 0 : _this$getCurrentTexts[id]) || id;
|
|
52
|
+
});
|
|
53
|
+
_defineProperty(this, "isCN", function () {
|
|
54
|
+
var locale = _this.getLocale();
|
|
55
|
+
return locale === "zh-CN" || locale === "zh-HK";
|
|
56
|
+
});
|
|
35
57
|
_defineProperty(this, "loadLibraryByUrl", /*#__PURE__*/function () {
|
|
36
58
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(urls) {
|
|
37
59
|
var fetchList, res, library, _iterator, _step, item, _item;
|
|
@@ -121,87 +143,29 @@ export var Locales = /*#__PURE__*/function () {
|
|
|
121
143
|
return _ref.apply(this, arguments);
|
|
122
144
|
};
|
|
123
145
|
}());
|
|
124
|
-
this
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return pre;
|
|
129
|
-
}, {});
|
|
130
|
-
}
|
|
131
|
-
_createClass(Locales, [{
|
|
132
|
-
key: "getLocale",
|
|
133
|
-
value: function getLocale() {
|
|
134
|
-
return this.locale;
|
|
135
|
-
}
|
|
136
|
-
}, {
|
|
137
|
-
key: "getCurrentTexts",
|
|
138
|
-
value: function getCurrentTexts(locale) {
|
|
139
|
-
return this.library[locale || this.locale].translations;
|
|
140
|
-
}
|
|
141
|
-
}, {
|
|
142
|
-
key: "setLocale",
|
|
143
|
-
value: function setLocale(locale) {
|
|
144
|
-
var reload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
145
|
-
this.locale = locale;
|
|
146
|
-
if (reload) {
|
|
147
|
-
window.location.reload();
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}, {
|
|
152
|
-
key: "getText",
|
|
153
|
-
value: function getText(id, locale) {
|
|
154
|
-
var _this$getCurrentTexts;
|
|
155
|
-
return ((_this$getCurrentTexts = this.getCurrentTexts(locale)) === null || _this$getCurrentTexts === void 0 ? void 0 : _this$getCurrentTexts[id]) || id;
|
|
156
|
-
}
|
|
157
|
-
}, {
|
|
158
|
-
key: "isCN",
|
|
159
|
-
value: function isCN() {
|
|
160
|
-
var locale = this.getLocale();
|
|
161
|
-
return locale === "zh-CN" || locale === "zh-HK";
|
|
162
|
-
}
|
|
163
|
-
}, {
|
|
164
|
-
key: "loadLibraryByItems",
|
|
165
|
-
value: function loadLibraryByItems(libraryList) {
|
|
166
|
-
var library = _objectSpread({}, this.library);
|
|
167
|
-
libraryList.forEach(function (item) {
|
|
168
|
-
library = _objectSpread(_objectSpread({}, library), {}, _defineProperty({}, item.locale, _.mergeWith(library[item.locale] || {}, item)));
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// 设置
|
|
172
|
-
this.library = library;
|
|
173
|
-
}
|
|
174
|
-
}, {
|
|
175
|
-
key: "loadLibrary",
|
|
176
|
-
value: function loadLibrary(urls) {
|
|
177
|
-
return this.loadLibraryByUrl(urls);
|
|
178
|
-
}
|
|
179
|
-
}, {
|
|
180
|
-
key: "translation",
|
|
181
|
-
value: function translation(text, locale) {
|
|
146
|
+
_defineProperty(this, "loadLibrary", function (urls) {
|
|
147
|
+
return _this.loadLibraryByUrl(urls);
|
|
148
|
+
});
|
|
149
|
+
_defineProperty(this, "translation", function (text, locale) {
|
|
182
150
|
if (!text) {
|
|
183
151
|
return "";
|
|
184
152
|
}
|
|
185
153
|
if (isString(text) || isNumber(text)) {
|
|
186
154
|
return text;
|
|
187
155
|
}
|
|
188
|
-
var primary = locale ||
|
|
156
|
+
var primary = locale || _this.getLocale();
|
|
189
157
|
if (typeof text === 'string') {
|
|
190
158
|
return text;
|
|
191
159
|
}
|
|
192
160
|
return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
key: "getLibraryByData",
|
|
196
|
-
value: function getLibraryByData(data) {
|
|
161
|
+
});
|
|
162
|
+
_defineProperty(this, "getLibraryByData", function (data) {
|
|
197
163
|
return data.reduce(function (pre, next) {
|
|
198
164
|
return _objectSpread(_objectSpread({}, pre), {}, _defineProperty({}, next.locale, next));
|
|
199
165
|
}, {});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
value: function createTextsByLibrary(id, library) {
|
|
204
|
-
var _library = library || this.library;
|
|
166
|
+
});
|
|
167
|
+
_defineProperty(this, "createTextsByLibrary", function (id, library) {
|
|
168
|
+
var _library = library || _this.library;
|
|
205
169
|
return Object.keys(_library).reduce(function (pre, next) {
|
|
206
170
|
var _library$next$transla;
|
|
207
171
|
var _pre = _objectSpread({}, pre);
|
|
@@ -211,6 +175,24 @@ export var Locales = /*#__PURE__*/function () {
|
|
|
211
175
|
}
|
|
212
176
|
return _pre;
|
|
213
177
|
}, {});
|
|
178
|
+
});
|
|
179
|
+
this.app = app;
|
|
180
|
+
this.locale = (options === null || options === void 0 ? void 0 : options.locale) || this.app.storage.getStorage('locale') || en.locale;
|
|
181
|
+
this.library = (options === null || options === void 0 ? void 0 : options.library) || [original, en, zhCN, zhHK].reduce(function (pre, cur) {
|
|
182
|
+
pre[cur.locale] = cur;
|
|
183
|
+
return pre;
|
|
184
|
+
}, {});
|
|
185
|
+
}
|
|
186
|
+
_createClass(Locales, [{
|
|
187
|
+
key: "loadLibraryByItems",
|
|
188
|
+
value: function loadLibraryByItems(libraryList) {
|
|
189
|
+
var library = _objectSpread({}, this.library);
|
|
190
|
+
libraryList.forEach(function (item) {
|
|
191
|
+
library = _objectSpread(_objectSpread({}, library), {}, _defineProperty({}, item.locale, _.mergeWith(library[item.locale] || {}, item)));
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// 设置
|
|
195
|
+
this.library = library;
|
|
214
196
|
}
|
|
215
197
|
}]);
|
|
216
198
|
return Locales;
|
package/es/routes/index.js
CHANGED
|
@@ -121,7 +121,10 @@ export var RouterManager = /*#__PURE__*/function () {
|
|
|
121
121
|
firstRoute = path;
|
|
122
122
|
}
|
|
123
123
|
var component = this.renderComponent(item);
|
|
124
|
-
routes.push(
|
|
124
|
+
routes.push(
|
|
125
|
+
/*#__PURE__*/
|
|
126
|
+
//@ts-ignore
|
|
127
|
+
React.createElement(Route, {
|
|
125
128
|
path: path,
|
|
126
129
|
key: path,
|
|
127
130
|
exact: true
|
package/es/storage/index.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ export declare class Storage {
|
|
|
9
9
|
private app?;
|
|
10
10
|
private options;
|
|
11
11
|
constructor(app?: App, options?: StorageOptions);
|
|
12
|
-
createKey(key: string)
|
|
13
|
-
setStorage(key: string, value: string)
|
|
14
|
-
getStorage(key: string)
|
|
15
|
-
removeStorage(key: string)
|
|
16
|
-
clear()
|
|
12
|
+
createKey: (key: string) => string;
|
|
13
|
+
setStorage: (key: string, value: string) => void;
|
|
14
|
+
getStorage: (key: string) => string | null;
|
|
15
|
+
removeStorage: (key: string) => void;
|
|
16
|
+
clear: () => void;
|
|
17
17
|
}
|
package/es/storage/index.js
CHANGED
|
@@ -1,56 +1,43 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
2
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
3
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
export var Storage = /*#__PURE__*/function () {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
if (options !== null && options !== void 0 && options.storageKey) {
|
|
19
|
-
this.storageKey = options.storageKey;
|
|
8
|
+
export var Storage = /*#__PURE__*/_createClass(function Storage(app, options) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
_classCallCheck(this, Storage);
|
|
11
|
+
_defineProperty(this, "storageKey", 'CapacitorStorage.native_');
|
|
12
|
+
_defineProperty(this, "app", void 0);
|
|
13
|
+
_defineProperty(this, "options", {});
|
|
14
|
+
_defineProperty(this, "createKey", function (key) {
|
|
15
|
+
if (key.indexOf(_this.storageKey) !== -1) {
|
|
16
|
+
return key;
|
|
20
17
|
}
|
|
18
|
+
return _this.storageKey + key;
|
|
19
|
+
});
|
|
20
|
+
_defineProperty(this, "setStorage", function (key, value) {
|
|
21
|
+
var _this$options, _this$options$setStor;
|
|
22
|
+
localStorage.setItem(_this.createKey(key), value);
|
|
23
|
+
(_this$options = _this.options) === null || _this$options === void 0 || (_this$options$setStor = _this$options.setStorageAfter) === null || _this$options$setStor === void 0 || _this$options$setStor.call(_this$options, key, value);
|
|
24
|
+
});
|
|
25
|
+
_defineProperty(this, "getStorage", function (key) {
|
|
26
|
+
return localStorage.getItem(_this.createKey(key));
|
|
27
|
+
});
|
|
28
|
+
_defineProperty(this, "removeStorage", function (key) {
|
|
29
|
+
var _this$options2, _this$options2$remove;
|
|
30
|
+
localStorage.removeItem(_this.createKey(key));
|
|
31
|
+
(_this$options2 = _this.options) === null || _this$options2 === void 0 || (_this$options2$remove = _this$options2.removeStorageAfter) === null || _this$options2$remove === void 0 || _this$options2$remove.call(_this$options2, key);
|
|
32
|
+
});
|
|
33
|
+
_defineProperty(this, "clear", function () {
|
|
34
|
+
localStorage.clear();
|
|
35
|
+
});
|
|
36
|
+
this.app = app;
|
|
37
|
+
if (options) {
|
|
38
|
+
this.options = options;
|
|
21
39
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return key;
|
|
27
|
-
}
|
|
28
|
-
return this.storageKey + key;
|
|
29
|
-
}
|
|
30
|
-
}, {
|
|
31
|
-
key: "setStorage",
|
|
32
|
-
value: function setStorage(key, value) {
|
|
33
|
-
var _this$options, _this$options$setStor;
|
|
34
|
-
localStorage.setItem(this.createKey(key), value);
|
|
35
|
-
(_this$options = this.options) === null || _this$options === void 0 || (_this$options$setStor = _this$options.setStorageAfter) === null || _this$options$setStor === void 0 || _this$options$setStor.call(_this$options, key, value);
|
|
36
|
-
}
|
|
37
|
-
}, {
|
|
38
|
-
key: "getStorage",
|
|
39
|
-
value: function getStorage(key) {
|
|
40
|
-
return localStorage.getItem(this.createKey(key));
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
key: "removeStorage",
|
|
44
|
-
value: function removeStorage(key) {
|
|
45
|
-
var _this$options2, _this$options2$remove;
|
|
46
|
-
localStorage.removeItem(this.createKey(key));
|
|
47
|
-
(_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2$remove = _this$options2.removeStorageAfter) === null || _this$options2$remove === void 0 || _this$options2$remove.call(_this$options2, key);
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
50
|
-
key: "clear",
|
|
51
|
-
value: function clear() {
|
|
52
|
-
localStorage.clear();
|
|
53
|
-
}
|
|
54
|
-
}]);
|
|
55
|
-
return Storage;
|
|
56
|
-
}();
|
|
40
|
+
if (options !== null && options !== void 0 && options.storageKey) {
|
|
41
|
+
this.storageKey = options.storageKey;
|
|
42
|
+
}
|
|
43
|
+
});
|
package/lib/locales/index.d.ts
CHANGED
|
@@ -13,27 +13,27 @@ export declare class Locales {
|
|
|
13
13
|
[key in Locale]: LibraryItem;
|
|
14
14
|
};
|
|
15
15
|
constructor(app: App, options?: LocalesOptions);
|
|
16
|
-
getLocale()
|
|
17
|
-
getCurrentTexts(locale?: Locale)
|
|
16
|
+
getLocale: () => string;
|
|
17
|
+
getCurrentTexts: (locale?: Locale) => {
|
|
18
18
|
[key: string]: string;
|
|
19
19
|
};
|
|
20
|
-
setLocale(locale: Locale, reload?: boolean)
|
|
21
|
-
getText(id: string, locale?: Locale)
|
|
22
|
-
isCN()
|
|
20
|
+
setLocale: (locale: Locale, reload?: boolean) => void;
|
|
21
|
+
getText: (id: string, locale?: Locale) => string;
|
|
22
|
+
isCN: () => boolean;
|
|
23
23
|
loadLibraryByUrl: (urls: LoadLibraryByUrlParams) => Promise<{
|
|
24
24
|
[x: string]: LibraryItem;
|
|
25
25
|
}>;
|
|
26
26
|
loadLibraryByItems(libraryList: LibraryItem[]): void;
|
|
27
|
-
loadLibrary(urls: LoadLibraryByUrlParams)
|
|
27
|
+
loadLibrary: (urls: LoadLibraryByUrlParams) => Promise<{
|
|
28
28
|
[x: string]: LibraryItem;
|
|
29
29
|
}>;
|
|
30
|
-
translation(text: string | {
|
|
31
|
-
[key:
|
|
32
|
-
}, locale?: Locale)
|
|
33
|
-
getLibraryByData(data: LibraryItem[])
|
|
34
|
-
createTextsByLibrary(id: string, library?: {
|
|
35
|
-
[
|
|
36
|
-
})
|
|
30
|
+
translation: (text: string | {
|
|
31
|
+
[key: string]: string;
|
|
32
|
+
}, locale?: Locale) => string | number;
|
|
33
|
+
getLibraryByData: (data: LibraryItem[]) => LibraryItem;
|
|
34
|
+
createTextsByLibrary: (id: string, library?: {
|
|
35
|
+
[x: string]: LibraryItem;
|
|
36
|
+
} | undefined) => {
|
|
37
37
|
[x: string]: string;
|
|
38
38
|
};
|
|
39
39
|
}
|
package/lib/locales/index.js
CHANGED
|
@@ -47,6 +47,27 @@ var Locales = class {
|
|
|
47
47
|
pre[cur.locale] = cur;
|
|
48
48
|
return pre;
|
|
49
49
|
}, {});
|
|
50
|
+
this.getLocale = () => {
|
|
51
|
+
return this.locale;
|
|
52
|
+
};
|
|
53
|
+
this.getCurrentTexts = (locale) => {
|
|
54
|
+
return this.library[locale || this.locale].translations;
|
|
55
|
+
};
|
|
56
|
+
this.setLocale = (locale, reload = false) => {
|
|
57
|
+
this.locale = locale;
|
|
58
|
+
if (reload) {
|
|
59
|
+
window.location.reload();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
this.getText = (id, locale) => {
|
|
64
|
+
var _a;
|
|
65
|
+
return ((_a = this.getCurrentTexts(locale)) == null ? void 0 : _a[id]) || id;
|
|
66
|
+
};
|
|
67
|
+
this.isCN = () => {
|
|
68
|
+
let locale = this.getLocale();
|
|
69
|
+
return locale === "zh-CN" || locale === "zh-HK";
|
|
70
|
+
};
|
|
50
71
|
this.loadLibraryByUrl = async (urls) => {
|
|
51
72
|
try {
|
|
52
73
|
let fetchList = urls.map((item) => {
|
|
@@ -77,6 +98,42 @@ var Locales = class {
|
|
|
77
98
|
throw err;
|
|
78
99
|
}
|
|
79
100
|
};
|
|
101
|
+
this.loadLibrary = (urls) => {
|
|
102
|
+
return this.loadLibraryByUrl(urls);
|
|
103
|
+
};
|
|
104
|
+
this.translation = (text, locale) => {
|
|
105
|
+
if (!text) {
|
|
106
|
+
return "";
|
|
107
|
+
}
|
|
108
|
+
if ((0, import_utils.isString)(text) || (0, import_utils.isNumber)(text)) {
|
|
109
|
+
return text;
|
|
110
|
+
}
|
|
111
|
+
let primary = locale || this.getLocale();
|
|
112
|
+
if (typeof text === "string") {
|
|
113
|
+
return text;
|
|
114
|
+
}
|
|
115
|
+
return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
|
|
116
|
+
};
|
|
117
|
+
this.getLibraryByData = (data) => {
|
|
118
|
+
return data.reduce((pre, next) => {
|
|
119
|
+
return {
|
|
120
|
+
...pre,
|
|
121
|
+
[next.locale]: next
|
|
122
|
+
};
|
|
123
|
+
}, {});
|
|
124
|
+
};
|
|
125
|
+
this.createTextsByLibrary = (id, library) => {
|
|
126
|
+
const _library = library || this.library;
|
|
127
|
+
return Object.keys(_library).reduce((pre, next) => {
|
|
128
|
+
var _a;
|
|
129
|
+
let _pre = { ...pre };
|
|
130
|
+
let cur = (_a = _library[next].translations) == null ? void 0 : _a[id];
|
|
131
|
+
if (cur) {
|
|
132
|
+
_pre[_library[next].locale] = cur;
|
|
133
|
+
}
|
|
134
|
+
return _pre;
|
|
135
|
+
}, {});
|
|
136
|
+
};
|
|
80
137
|
this.app = app;
|
|
81
138
|
this.locale = (options == null ? void 0 : options.locale) || this.app.storage.getStorage("locale") || import_en.default.locale;
|
|
82
139
|
this.library = (options == null ? void 0 : options.library) || [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
|
|
@@ -84,27 +141,6 @@ var Locales = class {
|
|
|
84
141
|
return pre;
|
|
85
142
|
}, {});
|
|
86
143
|
}
|
|
87
|
-
getLocale() {
|
|
88
|
-
return this.locale;
|
|
89
|
-
}
|
|
90
|
-
getCurrentTexts(locale) {
|
|
91
|
-
return this.library[locale || this.locale].translations;
|
|
92
|
-
}
|
|
93
|
-
setLocale(locale, reload = false) {
|
|
94
|
-
this.locale = locale;
|
|
95
|
-
if (reload) {
|
|
96
|
-
window.location.reload();
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
getText(id, locale) {
|
|
101
|
-
var _a;
|
|
102
|
-
return ((_a = this.getCurrentTexts(locale)) == null ? void 0 : _a[id]) || id;
|
|
103
|
-
}
|
|
104
|
-
isCN() {
|
|
105
|
-
let locale = this.getLocale();
|
|
106
|
-
return locale === "zh-CN" || locale === "zh-HK";
|
|
107
|
-
}
|
|
108
144
|
loadLibraryByItems(libraryList) {
|
|
109
145
|
let library = { ...this.library };
|
|
110
146
|
libraryList.forEach((item) => {
|
|
@@ -115,42 +151,6 @@ var Locales = class {
|
|
|
115
151
|
});
|
|
116
152
|
this.library = library;
|
|
117
153
|
}
|
|
118
|
-
loadLibrary(urls) {
|
|
119
|
-
return this.loadLibraryByUrl(urls);
|
|
120
|
-
}
|
|
121
|
-
translation(text, locale) {
|
|
122
|
-
if (!text) {
|
|
123
|
-
return "";
|
|
124
|
-
}
|
|
125
|
-
if ((0, import_utils.isString)(text) || (0, import_utils.isNumber)(text)) {
|
|
126
|
-
return text;
|
|
127
|
-
}
|
|
128
|
-
let primary = locale || this.getLocale();
|
|
129
|
-
if (typeof text === "string") {
|
|
130
|
-
return text;
|
|
131
|
-
}
|
|
132
|
-
return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
|
|
133
|
-
}
|
|
134
|
-
getLibraryByData(data) {
|
|
135
|
-
return data.reduce((pre, next) => {
|
|
136
|
-
return {
|
|
137
|
-
...pre,
|
|
138
|
-
[next.locale]: next
|
|
139
|
-
};
|
|
140
|
-
}, {});
|
|
141
|
-
}
|
|
142
|
-
createTextsByLibrary(id, library) {
|
|
143
|
-
const _library = library || this.library;
|
|
144
|
-
return Object.keys(_library).reduce((pre, next) => {
|
|
145
|
-
var _a;
|
|
146
|
-
let _pre = { ...pre };
|
|
147
|
-
let cur = (_a = _library[next].translations) == null ? void 0 : _a[id];
|
|
148
|
-
if (cur) {
|
|
149
|
-
_pre[_library[next].locale] = cur;
|
|
150
|
-
}
|
|
151
|
-
return _pre;
|
|
152
|
-
}, {});
|
|
153
|
-
}
|
|
154
154
|
};
|
|
155
155
|
// Annotate the CommonJS export names for ESM import in node:
|
|
156
156
|
0 && (module.exports = {
|
package/lib/routes/index.js
CHANGED
|
@@ -106,6 +106,7 @@ var RouterManager = class {
|
|
|
106
106
|
}
|
|
107
107
|
const component = this.renderComponent(item);
|
|
108
108
|
routes.push(
|
|
109
|
+
//@ts-ignore
|
|
109
110
|
/* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Route, { path, key: path, exact: true }, /* @__PURE__ */ import_react.default.createElement(import_react.Suspense, { fallback: fallback || /* @__PURE__ */ import_react.default.createElement("div", null) }, component))
|
|
110
111
|
);
|
|
111
112
|
}
|
package/lib/storage/index.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ export declare class Storage {
|
|
|
9
9
|
private app?;
|
|
10
10
|
private options;
|
|
11
11
|
constructor(app?: App, options?: StorageOptions);
|
|
12
|
-
createKey(key: string)
|
|
13
|
-
setStorage(key: string, value: string)
|
|
14
|
-
getStorage(key: string)
|
|
15
|
-
removeStorage(key: string)
|
|
16
|
-
clear()
|
|
12
|
+
createKey: (key: string) => string;
|
|
13
|
+
setStorage: (key: string, value: string) => void;
|
|
14
|
+
getStorage: (key: string) => string | null;
|
|
15
|
+
removeStorage: (key: string) => void;
|
|
16
|
+
clear: () => void;
|
|
17
17
|
}
|
package/lib/storage/index.js
CHANGED
|
@@ -26,6 +26,28 @@ var Storage = class {
|
|
|
26
26
|
constructor(app, options) {
|
|
27
27
|
this.storageKey = "CapacitorStorage.native_";
|
|
28
28
|
this.options = {};
|
|
29
|
+
this.createKey = (key) => {
|
|
30
|
+
if (key.indexOf(this.storageKey) !== -1) {
|
|
31
|
+
return key;
|
|
32
|
+
}
|
|
33
|
+
return this.storageKey + key;
|
|
34
|
+
};
|
|
35
|
+
this.setStorage = (key, value) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
localStorage.setItem(this.createKey(key), value);
|
|
38
|
+
(_b = (_a = this.options) == null ? void 0 : _a.setStorageAfter) == null ? void 0 : _b.call(_a, key, value);
|
|
39
|
+
};
|
|
40
|
+
this.getStorage = (key) => {
|
|
41
|
+
return localStorage.getItem(this.createKey(key));
|
|
42
|
+
};
|
|
43
|
+
this.removeStorage = (key) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
localStorage.removeItem(this.createKey(key));
|
|
46
|
+
(_b = (_a = this.options) == null ? void 0 : _a.removeStorageAfter) == null ? void 0 : _b.call(_a, key);
|
|
47
|
+
};
|
|
48
|
+
this.clear = () => {
|
|
49
|
+
localStorage.clear();
|
|
50
|
+
};
|
|
29
51
|
this.app = app;
|
|
30
52
|
if (options) {
|
|
31
53
|
this.options = options;
|
|
@@ -34,28 +56,6 @@ var Storage = class {
|
|
|
34
56
|
this.storageKey = options.storageKey;
|
|
35
57
|
}
|
|
36
58
|
}
|
|
37
|
-
createKey(key) {
|
|
38
|
-
if (key.indexOf(this.storageKey) !== -1) {
|
|
39
|
-
return key;
|
|
40
|
-
}
|
|
41
|
-
return this.storageKey + key;
|
|
42
|
-
}
|
|
43
|
-
setStorage(key, value) {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
localStorage.setItem(this.createKey(key), value);
|
|
46
|
-
(_b = (_a = this.options) == null ? void 0 : _a.setStorageAfter) == null ? void 0 : _b.call(_a, key, value);
|
|
47
|
-
}
|
|
48
|
-
getStorage(key) {
|
|
49
|
-
return localStorage.getItem(this.createKey(key));
|
|
50
|
-
}
|
|
51
|
-
removeStorage(key) {
|
|
52
|
-
var _a, _b;
|
|
53
|
-
localStorage.removeItem(this.createKey(key));
|
|
54
|
-
(_b = (_a = this.options) == null ? void 0 : _a.removeStorageAfter) == null ? void 0 : _b.call(_a, key);
|
|
55
|
-
}
|
|
56
|
-
clear() {
|
|
57
|
-
localStorage.clear();
|
|
58
|
-
}
|
|
59
59
|
};
|
|
60
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
61
|
0 && (module.exports = {
|