@opra/common 0.27.2 → 0.28.0
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/browser.js +32 -74
- package/cjs/i18n/i18n.js +1 -48
- package/esm/i18n/i18n.js +1 -48
- package/package.json +1 -1
- package/types/i18n/i18n.d.ts +0 -3
package/browser.js
CHANGED
|
@@ -367,8 +367,6 @@ var ResponsiveMap = class extends Map {
|
|
|
367
367
|
|
|
368
368
|
// ../../build/common/esm/i18n/i18n.js
|
|
369
369
|
import { splitString, tokenize } from "fast-tokenizer";
|
|
370
|
-
import fs from "@browsery/fs";
|
|
371
|
-
import path from "path-browserify";
|
|
372
370
|
import i18next from "@browsery/i18next";
|
|
373
371
|
|
|
374
372
|
// ../../build/common/esm/i18n/string-utils.js
|
|
@@ -384,8 +382,7 @@ function unescapeString(s) {
|
|
|
384
382
|
__name(unescapeString, "unescapeString");
|
|
385
383
|
|
|
386
384
|
// ../../build/common/esm/i18n/i18n.js
|
|
387
|
-
var BaseI18n = Object.getPrototypeOf(i18next).constructor;
|
|
388
|
-
var globalLocaleDirs = [];
|
|
385
|
+
var BaseI18n = Object.getPrototypeOf(i18next.createInstance()).constructor;
|
|
389
386
|
var I18n = class _I18n extends BaseI18n {
|
|
390
387
|
static {
|
|
391
388
|
__name(this, "I18n");
|
|
@@ -399,11 +396,6 @@ var I18n = class _I18n extends BaseI18n {
|
|
|
399
396
|
formatter.add("lowercase", (value, lng) => value.toLocaleLowerCase(lng));
|
|
400
397
|
formatter.add("uppercase", (value, lng) => value.toLocaleUpperCase(lng));
|
|
401
398
|
formatter.add("upperFirst", (value, lng) => value.charAt(0).toLocaleUpperCase(lng) + value.substring(1));
|
|
402
|
-
if (globalLocaleDirs.length)
|
|
403
|
-
await this.loadResourceDir(globalLocaleDirs, false, true);
|
|
404
|
-
if (options?.resourceDirs?.length) {
|
|
405
|
-
await this.loadResourceDir(options.resourceDirs, false, true);
|
|
406
|
-
}
|
|
407
399
|
if (options?.resources) {
|
|
408
400
|
for (const lang of Object.keys(options.resources)) {
|
|
409
401
|
const langObj = options.resources[lang];
|
|
@@ -427,40 +419,6 @@ var I18n = class _I18n extends BaseI18n {
|
|
|
427
419
|
const objectStack = /* @__PURE__ */ new WeakMap();
|
|
428
420
|
return this._deepTranslate(input, objectStack, options);
|
|
429
421
|
}
|
|
430
|
-
registerLocaleDir(...dirname) {
|
|
431
|
-
globalLocaleDirs.push(...dirname);
|
|
432
|
-
}
|
|
433
|
-
async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
|
|
434
|
-
let obj;
|
|
435
|
-
if (isUrlString(filePath)) {
|
|
436
|
-
obj = (await fetch(filePath, { headers: { accept: "application/json" } })).json();
|
|
437
|
-
} else {
|
|
438
|
-
const content = fs.readFileSync(filePath, "utf8");
|
|
439
|
-
obj = JSON.parse(content);
|
|
440
|
-
}
|
|
441
|
-
this.addResourceBundle(lang, ns, obj, deep, overwrite);
|
|
442
|
-
}
|
|
443
|
-
async loadResourceDir(dirnames, deep, overwrite) {
|
|
444
|
-
for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
|
|
445
|
-
if (!fs.existsSync(dirname))
|
|
446
|
-
continue;
|
|
447
|
-
const languageDirs = fs.readdirSync(dirname);
|
|
448
|
-
for (const lang of languageDirs) {
|
|
449
|
-
const langDir = path.join(dirname, lang);
|
|
450
|
-
if (fs.statSync(langDir).isDirectory()) {
|
|
451
|
-
const nsDirs = fs.readdirSync(langDir);
|
|
452
|
-
for (const nsfile of nsDirs) {
|
|
453
|
-
const nsFilePath = path.join(langDir, nsfile);
|
|
454
|
-
const ext = path.extname(nsfile);
|
|
455
|
-
if (ext === ".json" && fs.statSync(nsFilePath).isFile()) {
|
|
456
|
-
const ns = path.basename(nsfile, ext);
|
|
457
|
-
await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
422
|
createInstance(options = {}, callback) {
|
|
465
423
|
return new _I18n(options, callback);
|
|
466
424
|
}
|
|
@@ -1251,10 +1209,10 @@ var ContainerClass = class _ContainerClass extends Resource {
|
|
|
1251
1209
|
}
|
|
1252
1210
|
return schema;
|
|
1253
1211
|
}
|
|
1254
|
-
getResource(
|
|
1212
|
+
getResource(path, silent) {
|
|
1255
1213
|
let resource;
|
|
1256
|
-
if (
|
|
1257
|
-
const arr =
|
|
1214
|
+
if (path.includes("/")) {
|
|
1215
|
+
const arr = path.split("/");
|
|
1258
1216
|
let i;
|
|
1259
1217
|
const l = arr.length;
|
|
1260
1218
|
let container = this;
|
|
@@ -1268,37 +1226,37 @@ var ContainerClass = class _ContainerClass extends Resource {
|
|
|
1268
1226
|
if (!resource || i < l - 1)
|
|
1269
1227
|
resource = void 0;
|
|
1270
1228
|
} else
|
|
1271
|
-
resource = this.resources.get(
|
|
1229
|
+
resource = this.resources.get(path);
|
|
1272
1230
|
if (resource || silent)
|
|
1273
1231
|
return resource;
|
|
1274
|
-
throw new ResourceNotFoundError(
|
|
1232
|
+
throw new ResourceNotFoundError(path);
|
|
1275
1233
|
}
|
|
1276
|
-
getContainer(
|
|
1277
|
-
const t = this.getResource(
|
|
1234
|
+
getContainer(path, silent) {
|
|
1235
|
+
const t = this.getResource(path);
|
|
1278
1236
|
if (!t && silent)
|
|
1279
1237
|
return;
|
|
1280
1238
|
if (t && t.kind === opra_schema_ns_exports.Container.Kind)
|
|
1281
1239
|
return t;
|
|
1282
1240
|
throw new NotAcceptableError(`Resource type "${t.name}" is not a Container`);
|
|
1283
1241
|
}
|
|
1284
|
-
getCollection(
|
|
1285
|
-
const t = this.getResource(
|
|
1242
|
+
getCollection(path, silent) {
|
|
1243
|
+
const t = this.getResource(path);
|
|
1286
1244
|
if (!t && silent)
|
|
1287
1245
|
return;
|
|
1288
1246
|
if (t && t.kind === opra_schema_ns_exports.Collection.Kind)
|
|
1289
1247
|
return t;
|
|
1290
1248
|
throw new NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
|
|
1291
1249
|
}
|
|
1292
|
-
getSingleton(
|
|
1293
|
-
const t = this.getResource(
|
|
1250
|
+
getSingleton(path, silent) {
|
|
1251
|
+
const t = this.getResource(path);
|
|
1294
1252
|
if (!t && silent)
|
|
1295
1253
|
return;
|
|
1296
1254
|
if (t && t.kind === opra_schema_ns_exports.Singleton.Kind)
|
|
1297
1255
|
return t;
|
|
1298
1256
|
throw new NotAcceptableError(`Resource type "${t.name}" is not a Singleton`);
|
|
1299
1257
|
}
|
|
1300
|
-
getStorage(
|
|
1301
|
-
const t = this.getResource(
|
|
1258
|
+
getStorage(path, silent) {
|
|
1259
|
+
const t = this.getResource(path);
|
|
1302
1260
|
if (!t && silent)
|
|
1303
1261
|
return;
|
|
1304
1262
|
if (t && t.kind === opra_schema_ns_exports.Storage.Kind)
|
|
@@ -1579,8 +1537,8 @@ var ComplexTypeClass = class extends DataType {
|
|
|
1579
1537
|
throw new Error(translate("error:UNKNOWN_FIELD", { field: nameOrPath }));
|
|
1580
1538
|
return field;
|
|
1581
1539
|
}
|
|
1582
|
-
iteratePath(
|
|
1583
|
-
const arr =
|
|
1540
|
+
iteratePath(path, silent) {
|
|
1541
|
+
const arr = path.split(".");
|
|
1584
1542
|
const len = arr.length;
|
|
1585
1543
|
let dataType = this;
|
|
1586
1544
|
let field;
|
|
@@ -1990,20 +1948,20 @@ var ApiDocument = class extends TypeDocument {
|
|
|
1990
1948
|
super(...arguments);
|
|
1991
1949
|
this.root = new Container2(this, { name: "" });
|
|
1992
1950
|
}
|
|
1993
|
-
getResource(
|
|
1994
|
-
return this.root.getResource(
|
|
1951
|
+
getResource(path, silent) {
|
|
1952
|
+
return this.root.getResource(path, silent);
|
|
1995
1953
|
}
|
|
1996
|
-
getContainer(
|
|
1997
|
-
return this.root.getContainer(
|
|
1954
|
+
getContainer(path, silent) {
|
|
1955
|
+
return this.root.getContainer(path, silent);
|
|
1998
1956
|
}
|
|
1999
|
-
getCollection(
|
|
2000
|
-
return this.root.getCollection(
|
|
1957
|
+
getCollection(path, silent) {
|
|
1958
|
+
return this.root.getCollection(path, silent);
|
|
2001
1959
|
}
|
|
2002
|
-
getSingleton(
|
|
2003
|
-
return this.root.getSingleton(
|
|
1960
|
+
getSingleton(path, silent) {
|
|
1961
|
+
return this.root.getSingleton(path, silent);
|
|
2004
1962
|
}
|
|
2005
|
-
getStorage(
|
|
2006
|
-
return this.root.getStorage(
|
|
1963
|
+
getStorage(path, silent) {
|
|
1964
|
+
return this.root.getStorage(path, silent);
|
|
2007
1965
|
}
|
|
2008
1966
|
/**
|
|
2009
1967
|
* Export as Opra schema definition object
|
|
@@ -10545,8 +10503,8 @@ var CollectionClass = class extends CrudResource {
|
|
|
10545
10503
|
return result;
|
|
10546
10504
|
}
|
|
10547
10505
|
}
|
|
10548
|
-
normalizeFieldPath(
|
|
10549
|
-
return this.type.normalizeFieldPath(
|
|
10506
|
+
normalizeFieldPath(path) {
|
|
10507
|
+
return this.type.normalizeFieldPath(path);
|
|
10550
10508
|
}
|
|
10551
10509
|
normalizeSortFields(fields) {
|
|
10552
10510
|
const normalized = this.type.normalizeFieldPath(fields);
|
|
@@ -10889,8 +10847,8 @@ var SingletonClass = class extends CrudResource {
|
|
|
10889
10847
|
type: this.type.name || "any"
|
|
10890
10848
|
};
|
|
10891
10849
|
}
|
|
10892
|
-
normalizeFieldPath(
|
|
10893
|
-
return this.type.normalizeFieldPath(
|
|
10850
|
+
normalizeFieldPath(path) {
|
|
10851
|
+
return this.type.normalizeFieldPath(path);
|
|
10894
10852
|
}
|
|
10895
10853
|
};
|
|
10896
10854
|
|
|
@@ -11631,8 +11589,8 @@ var OpraURL = class _OpraURL {
|
|
|
11631
11589
|
get path() {
|
|
11632
11590
|
return this[kPath];
|
|
11633
11591
|
}
|
|
11634
|
-
set path(
|
|
11635
|
-
this[kPath] =
|
|
11592
|
+
set path(path) {
|
|
11593
|
+
this[kPath] = path instanceof OpraURLPath ? path : new OpraURLPath(path);
|
|
11636
11594
|
this[kContext].pathname = String(this[kPath]);
|
|
11637
11595
|
this.invalidate();
|
|
11638
11596
|
}
|
package/cjs/i18n/i18n.js
CHANGED
|
@@ -3,13 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.I18n = exports.BaseI18n = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
6
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
6
|
const i18next_1 = tslib_1.__importDefault(require("@browsery/i18next"));
|
|
9
|
-
const index_js_1 = require("../helpers/index.js");
|
|
10
7
|
const string_utils_js_1 = require("./string-utils.js");
|
|
11
|
-
exports.BaseI18n = Object.getPrototypeOf(i18next_1.default).constructor;
|
|
12
|
-
const globalLocaleDirs = [];
|
|
8
|
+
exports.BaseI18n = Object.getPrototypeOf(i18next_1.default.createInstance()).constructor;
|
|
13
9
|
class I18n extends exports.BaseI18n {
|
|
14
10
|
async init(arg0, arg1) {
|
|
15
11
|
const options = typeof arg0 === 'object' ? arg0 : {};
|
|
@@ -21,13 +17,6 @@ class I18n extends exports.BaseI18n {
|
|
|
21
17
|
formatter.add('lowercase', (value, lng) => value.toLocaleLowerCase(lng));
|
|
22
18
|
formatter.add('uppercase', (value, lng) => value.toLocaleUpperCase(lng));
|
|
23
19
|
formatter.add('upperFirst', (value, lng) => value.charAt(0).toLocaleUpperCase(lng) + value.substring(1));
|
|
24
|
-
// Load globally registered resources
|
|
25
|
-
if (globalLocaleDirs.length)
|
|
26
|
-
await this.loadResourceDir(globalLocaleDirs, false, true);
|
|
27
|
-
// Load resource dirs and overwrite existing
|
|
28
|
-
if (options?.resourceDirs?.length) {
|
|
29
|
-
await this.loadResourceDir(options.resourceDirs, false, true);
|
|
30
|
-
}
|
|
31
20
|
// overwrite existing resources with options.resources
|
|
32
21
|
if (options?.resources) {
|
|
33
22
|
for (const lang of Object.keys(options.resources)) {
|
|
@@ -53,42 +42,6 @@ class I18n extends exports.BaseI18n {
|
|
|
53
42
|
const objectStack = new WeakMap();
|
|
54
43
|
return this._deepTranslate(input, objectStack, options);
|
|
55
44
|
}
|
|
56
|
-
registerLocaleDir(...dirname) {
|
|
57
|
-
globalLocaleDirs.push(...dirname);
|
|
58
|
-
}
|
|
59
|
-
async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
|
|
60
|
-
let obj;
|
|
61
|
-
if ((0, index_js_1.isUrlString)(filePath)) {
|
|
62
|
-
obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
const content = fs_1.default.readFileSync(filePath, 'utf8');
|
|
66
|
-
obj = JSON.parse(content);
|
|
67
|
-
}
|
|
68
|
-
this.addResourceBundle(lang, ns, obj, deep, overwrite);
|
|
69
|
-
}
|
|
70
|
-
async loadResourceDir(dirnames, deep, overwrite) {
|
|
71
|
-
for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
|
|
72
|
-
/* istanbul ignore next */
|
|
73
|
-
if (!(fs_1.default.existsSync(dirname)))
|
|
74
|
-
continue;
|
|
75
|
-
const languageDirs = fs_1.default.readdirSync(dirname);
|
|
76
|
-
for (const lang of languageDirs) {
|
|
77
|
-
const langDir = path_1.default.join(dirname, lang);
|
|
78
|
-
if ((fs_1.default.statSync(langDir)).isDirectory()) {
|
|
79
|
-
const nsDirs = fs_1.default.readdirSync(langDir);
|
|
80
|
-
for (const nsfile of nsDirs) {
|
|
81
|
-
const nsFilePath = path_1.default.join(langDir, nsfile);
|
|
82
|
-
const ext = path_1.default.extname(nsfile);
|
|
83
|
-
if (ext === '.json' && (fs_1.default.statSync(nsFilePath)).isFile()) {
|
|
84
|
-
const ns = path_1.default.basename(nsfile, ext);
|
|
85
|
-
await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
45
|
createInstance(options = {}, callback) {
|
|
93
46
|
return new I18n(options, callback);
|
|
94
47
|
}
|
package/esm/i18n/i18n.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { splitString, tokenize } from 'fast-tokenizer';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
2
|
import i18next from '@browsery/i18next';
|
|
5
|
-
import { isUrlString } from '../helpers/index.js';
|
|
6
3
|
import { unescapeString } from './string-utils.js';
|
|
7
|
-
export const BaseI18n = Object.getPrototypeOf(i18next).constructor;
|
|
8
|
-
const globalLocaleDirs = [];
|
|
4
|
+
export const BaseI18n = Object.getPrototypeOf(i18next.createInstance()).constructor;
|
|
9
5
|
export class I18n extends BaseI18n {
|
|
10
6
|
async init(arg0, arg1) {
|
|
11
7
|
const options = typeof arg0 === 'object' ? arg0 : {};
|
|
@@ -17,13 +13,6 @@ export class I18n extends BaseI18n {
|
|
|
17
13
|
formatter.add('lowercase', (value, lng) => value.toLocaleLowerCase(lng));
|
|
18
14
|
formatter.add('uppercase', (value, lng) => value.toLocaleUpperCase(lng));
|
|
19
15
|
formatter.add('upperFirst', (value, lng) => value.charAt(0).toLocaleUpperCase(lng) + value.substring(1));
|
|
20
|
-
// Load globally registered resources
|
|
21
|
-
if (globalLocaleDirs.length)
|
|
22
|
-
await this.loadResourceDir(globalLocaleDirs, false, true);
|
|
23
|
-
// Load resource dirs and overwrite existing
|
|
24
|
-
if (options?.resourceDirs?.length) {
|
|
25
|
-
await this.loadResourceDir(options.resourceDirs, false, true);
|
|
26
|
-
}
|
|
27
16
|
// overwrite existing resources with options.resources
|
|
28
17
|
if (options?.resources) {
|
|
29
18
|
for (const lang of Object.keys(options.resources)) {
|
|
@@ -49,42 +38,6 @@ export class I18n extends BaseI18n {
|
|
|
49
38
|
const objectStack = new WeakMap();
|
|
50
39
|
return this._deepTranslate(input, objectStack, options);
|
|
51
40
|
}
|
|
52
|
-
registerLocaleDir(...dirname) {
|
|
53
|
-
globalLocaleDirs.push(...dirname);
|
|
54
|
-
}
|
|
55
|
-
async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
|
|
56
|
-
let obj;
|
|
57
|
-
if (isUrlString(filePath)) {
|
|
58
|
-
obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
62
|
-
obj = JSON.parse(content);
|
|
63
|
-
}
|
|
64
|
-
this.addResourceBundle(lang, ns, obj, deep, overwrite);
|
|
65
|
-
}
|
|
66
|
-
async loadResourceDir(dirnames, deep, overwrite) {
|
|
67
|
-
for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
|
|
68
|
-
/* istanbul ignore next */
|
|
69
|
-
if (!(fs.existsSync(dirname)))
|
|
70
|
-
continue;
|
|
71
|
-
const languageDirs = fs.readdirSync(dirname);
|
|
72
|
-
for (const lang of languageDirs) {
|
|
73
|
-
const langDir = path.join(dirname, lang);
|
|
74
|
-
if ((fs.statSync(langDir)).isDirectory()) {
|
|
75
|
-
const nsDirs = fs.readdirSync(langDir);
|
|
76
|
-
for (const nsfile of nsDirs) {
|
|
77
|
-
const nsFilePath = path.join(langDir, nsfile);
|
|
78
|
-
const ext = path.extname(nsfile);
|
|
79
|
-
if (ext === '.json' && (fs.statSync(nsFilePath)).isFile()) {
|
|
80
|
-
const ns = path.basename(nsfile, ext);
|
|
81
|
-
await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
41
|
createInstance(options = {}, callback) {
|
|
89
42
|
return new I18n(options, callback);
|
|
90
43
|
}
|
package/package.json
CHANGED
package/types/i18n/i18n.d.ts
CHANGED
|
@@ -18,9 +18,6 @@ export declare class I18n extends BaseI18n {
|
|
|
18
18
|
init(callback?: InitCallback): Promise<TranslateFunction>;
|
|
19
19
|
init(options: InitOptions, callback?: InitCallback): Promise<TranslateFunction>;
|
|
20
20
|
deep(input: any, options?: DeepTranslateOptions): any;
|
|
21
|
-
registerLocaleDir(...dirname: string[]): void;
|
|
22
|
-
loadResourceBundle(lang: string, ns: string, filePath: string, deep?: boolean, overwrite?: boolean): Promise<void>;
|
|
23
|
-
loadResourceDir(dirnames: string | string[], deep?: boolean, overwrite?: boolean): Promise<void>;
|
|
24
21
|
createInstance(options: {} | undefined, callback: any): I18n;
|
|
25
22
|
static createInstance(options?: InitOptions, callback?: InitCallback): I18n;
|
|
26
23
|
protected _deepTranslate(input: any, objectStack: WeakMap<object, any>, options?: DeepTranslateOptions): any;
|