@sv-print/plugin-i18n 0.1.3 → 0.1.5
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/README.md +52 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +160 -186
- package/dist/index.umd.js +1 -1
- package/dist/translate-option.d.ts +2 -0
- package/package.json +10 -6
package/dist/index.mjs
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var $e = Object.defineProperty, Re = Object.defineProperties;
|
|
2
|
+
var Pe = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var ne = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var re = (o, e, t) => e in o ?
|
|
4
|
+
var ke = Object.prototype.hasOwnProperty, Ne = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var re = (o, e, t) => e in o ? $e(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, p = (o, e) => {
|
|
6
6
|
for (var t in e || (e = {}))
|
|
7
|
-
|
|
7
|
+
ke.call(e, t) && re(o, t, e[t]);
|
|
8
8
|
if (ne)
|
|
9
9
|
for (var t of ne(e))
|
|
10
|
-
|
|
10
|
+
Ne.call(e, t) && re(o, t, e[t]);
|
|
11
11
|
return o;
|
|
12
|
-
}, O = (o, e) =>
|
|
12
|
+
}, O = (o, e) => Re(o, Pe(e));
|
|
13
13
|
const g = (o) => typeof o == "string", U = () => {
|
|
14
14
|
let o, e;
|
|
15
15
|
const t = new Promise((i, s) => {
|
|
16
16
|
o = i, e = s;
|
|
17
17
|
});
|
|
18
18
|
return t.resolve = o, t.reject = e, t;
|
|
19
|
-
}, ae = (o) => o == null ? "" : "" + o,
|
|
19
|
+
}, ae = (o) => o == null ? "" : "" + o, Fe = (o, e, t) => {
|
|
20
20
|
o.forEach((i) => {
|
|
21
21
|
e[i] && (t[i] = e[i]);
|
|
22
22
|
});
|
|
23
|
-
},
|
|
23
|
+
}, Te = /###/g, oe = (o) => o && o.indexOf("###") > -1 ? o.replace(Te, ".") : o, le = (o) => !o || g(o), M = (o, e, t) => {
|
|
24
24
|
const i = g(e) ? e.split(".") : e;
|
|
25
25
|
let s = 0;
|
|
26
26
|
for (; s < i.length - 1; ) {
|
|
27
|
-
if (le(o))
|
|
28
|
-
return {};
|
|
27
|
+
if (le(o)) return {};
|
|
29
28
|
const n = oe(i[s]);
|
|
30
29
|
!o[n] && t && (o[n] = new t()), Object.prototype.hasOwnProperty.call(o, n) ? o = o[n] : o = {}, ++s;
|
|
31
30
|
}
|
|
@@ -44,9 +43,9 @@ const g = (o) => typeof o == "string", U = () => {
|
|
|
44
43
|
}
|
|
45
44
|
let n = e[e.length - 1], r = e.slice(0, e.length - 1), a = M(o, r, Object);
|
|
46
45
|
for (; a.obj === void 0 && r.length; )
|
|
47
|
-
n = `${r[r.length - 1]}.${n}`, r = r.slice(0, r.length - 1), a = M(o, r, Object),
|
|
46
|
+
n = `${r[r.length - 1]}.${n}`, r = r.slice(0, r.length - 1), a = M(o, r, Object), a != null && a.obj && typeof a.obj[`${a.k}.${n}`] != "undefined" && (a.obj = void 0);
|
|
48
47
|
a.obj[`${a.k}.${n}`] = t;
|
|
49
|
-
},
|
|
48
|
+
}, je = (o, e, t, i) => {
|
|
50
49
|
const {
|
|
51
50
|
obj: s,
|
|
52
51
|
k: n
|
|
@@ -57,17 +56,17 @@ const g = (o) => typeof o == "string", U = () => {
|
|
|
57
56
|
obj: t,
|
|
58
57
|
k: i
|
|
59
58
|
} = M(o, e);
|
|
60
|
-
if (
|
|
59
|
+
if (t && Object.prototype.hasOwnProperty.call(t, i))
|
|
61
60
|
return t[i];
|
|
62
|
-
},
|
|
61
|
+
}, Ee = (o, e, t) => {
|
|
63
62
|
const i = Y(o, t);
|
|
64
63
|
return i !== void 0 ? i : Y(e, t);
|
|
65
|
-
},
|
|
64
|
+
}, Oe = (o, e, t) => {
|
|
66
65
|
for (const i in e)
|
|
67
|
-
i !== "__proto__" && i !== "constructor" && (i in o ? g(o[i]) || o[i] instanceof String || g(e[i]) || e[i] instanceof String ? t && (o[i] = e[i]) :
|
|
66
|
+
i !== "__proto__" && i !== "constructor" && (i in o ? g(o[i]) || o[i] instanceof String || g(e[i]) || e[i] instanceof String ? t && (o[i] = e[i]) : Oe(o[i], e[i], t) : o[i] = e[i]);
|
|
68
67
|
return o;
|
|
69
|
-
},
|
|
70
|
-
var
|
|
68
|
+
}, D = (o) => o.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
69
|
+
var Ie = {
|
|
71
70
|
"&": "&",
|
|
72
71
|
"<": "<",
|
|
73
72
|
">": ">",
|
|
@@ -75,8 +74,8 @@ var Te = {
|
|
|
75
74
|
"'": "'",
|
|
76
75
|
"/": "/"
|
|
77
76
|
};
|
|
78
|
-
const
|
|
79
|
-
class
|
|
77
|
+
const De = (o) => g(o) ? o.replace(/[&<>"'\/]/g, (e) => Ie[e]) : o;
|
|
78
|
+
class Ve {
|
|
80
79
|
constructor(e) {
|
|
81
80
|
this.capacity = e, this.regExpMap = /* @__PURE__ */ new Map(), this.regExpQueue = [];
|
|
82
81
|
}
|
|
@@ -88,12 +87,11 @@ class De {
|
|
|
88
87
|
return this.regExpQueue.length === this.capacity && this.regExpMap.delete(this.regExpQueue.shift()), this.regExpMap.set(e, i), this.regExpQueue.push(e), i;
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
|
-
const
|
|
90
|
+
const Ae = [" ", ",", "?", "!", ";"], Ke = new Ve(20), Ue = (o, e, t) => {
|
|
92
91
|
e = e || "", t = t || "";
|
|
93
|
-
const i =
|
|
94
|
-
if (i.length === 0)
|
|
95
|
-
|
|
96
|
-
const s = Ae.getRegExp(`(${i.map((r) => r === "?" ? "\\?" : r).join("|")})`);
|
|
92
|
+
const i = Ae.filter((r) => e.indexOf(r) < 0 && t.indexOf(r) < 0);
|
|
93
|
+
if (i.length === 0) return !0;
|
|
94
|
+
const s = Ke.getRegExp(`(${i.map((r) => r === "?" ? "\\?" : r).join("|")})`);
|
|
97
95
|
let n = !s.test(o);
|
|
98
96
|
if (!n) {
|
|
99
97
|
const r = o.indexOf(t);
|
|
@@ -101,8 +99,7 @@ const Ie = [" ", ",", "?", "!", ";"], Ae = new De(20), Ve = (o, e, t) => {
|
|
|
101
99
|
}
|
|
102
100
|
return n;
|
|
103
101
|
}, q = (o, e, t = ".") => {
|
|
104
|
-
if (!o)
|
|
105
|
-
return;
|
|
102
|
+
if (!o) return;
|
|
106
103
|
if (o[e])
|
|
107
104
|
return Object.prototype.hasOwnProperty.call(o, e) ? o[e] : void 0;
|
|
108
105
|
const i = e.split(t);
|
|
@@ -121,7 +118,7 @@ const Ie = [" ", ",", "?", "!", ";"], Ae = new De(20), Ve = (o, e, t) => {
|
|
|
121
118
|
s = r;
|
|
122
119
|
}
|
|
123
120
|
return s;
|
|
124
|
-
},
|
|
121
|
+
}, H = (o) => o == null ? void 0 : o.replace("_", "-"), Me = {
|
|
125
122
|
type: "logger",
|
|
126
123
|
log(o) {
|
|
127
124
|
this.output("log", o);
|
|
@@ -142,7 +139,7 @@ class Q {
|
|
|
142
139
|
this.init(e, t);
|
|
143
140
|
}
|
|
144
141
|
init(e, t = {}) {
|
|
145
|
-
this.prefix = t.prefix || "i18next:", this.logger = e ||
|
|
142
|
+
this.prefix = t.prefix || "i18next:", this.logger = e || Me, this.options = t, this.debug = t.debug;
|
|
146
143
|
}
|
|
147
144
|
log(...e) {
|
|
148
145
|
return this.forward(e, "log", "", !0);
|
|
@@ -181,7 +178,7 @@ class Z {
|
|
|
181
178
|
}), this;
|
|
182
179
|
}
|
|
183
180
|
off(e, t) {
|
|
184
|
-
if (
|
|
181
|
+
if (this.observers[e]) {
|
|
185
182
|
if (!t) {
|
|
186
183
|
delete this.observers[e];
|
|
187
184
|
return;
|
|
@@ -244,7 +241,7 @@ class fe extends Z {
|
|
|
244
241
|
let a = [e, t];
|
|
245
242
|
e.indexOf(".") > -1 && (a = e.split("."), s = i, i = t, t = a[1]), this.addNamespaces(t);
|
|
246
243
|
let l = Y(this.data, a) || {};
|
|
247
|
-
r.skipCopy || (i = JSON.parse(JSON.stringify(i))), s ?
|
|
244
|
+
r.skipCopy || (i = JSON.parse(JSON.stringify(i))), s ? Oe(l, i, n) : l = p(p({}, l), i), ue(this.data, a, l), r.silent || this.emit("added", e, t, i);
|
|
248
245
|
}
|
|
249
246
|
removeResourceBundle(e, t) {
|
|
250
247
|
this.hasResourceBundle(e, t) && delete this.data[e][t], this.removeNamespaces(t), this.emit("removed", e, t);
|
|
@@ -266,7 +263,7 @@ class fe extends Z {
|
|
|
266
263
|
return this.data;
|
|
267
264
|
}
|
|
268
265
|
}
|
|
269
|
-
var
|
|
266
|
+
var we = {
|
|
270
267
|
processors: {},
|
|
271
268
|
addPostProcessor(o) {
|
|
272
269
|
this.processors[o.name] = o;
|
|
@@ -281,7 +278,7 @@ var Le = {
|
|
|
281
278
|
const he = {}, ce = (o) => !g(o) && typeof o != "boolean" && typeof o != "number";
|
|
282
279
|
class G extends Z {
|
|
283
280
|
constructor(e, t = {}) {
|
|
284
|
-
super(),
|
|
281
|
+
super(), Fe(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], e, this), this.options = t, this.options.keySeparator === void 0 && (this.options.keySeparator = "."), this.logger = N.create("translator");
|
|
285
282
|
}
|
|
286
283
|
changeLanguage(e) {
|
|
287
284
|
e && (this.language = e);
|
|
@@ -290,8 +287,7 @@ class G extends Z {
|
|
|
290
287
|
interpolation: {}
|
|
291
288
|
}) {
|
|
292
289
|
const i = p({}, t);
|
|
293
|
-
if (e == null)
|
|
294
|
-
return !1;
|
|
290
|
+
if (e == null) return !1;
|
|
295
291
|
const s = this.resolve(e, i);
|
|
296
292
|
return (s == null ? void 0 : s.res) !== void 0;
|
|
297
293
|
}
|
|
@@ -300,7 +296,7 @@ class G extends Z {
|
|
|
300
296
|
i === void 0 && (i = ":");
|
|
301
297
|
const s = t.keySeparator !== void 0 ? t.keySeparator : this.options.keySeparator;
|
|
302
298
|
let n = t.ns || this.options.defaultNS || [];
|
|
303
|
-
const r = i && e.indexOf(i) > -1, a = !this.options.userDefinedKeySeparator && !t.keySeparator && !this.options.userDefinedNsSeparator && !t.nsSeparator && !
|
|
299
|
+
const r = i && e.indexOf(i) > -1, a = !this.options.userDefinedKeySeparator && !t.keySeparator && !this.options.userDefinedNsSeparator && !t.nsSeparator && !Ue(e, i, s);
|
|
304
300
|
if (r && !a) {
|
|
305
301
|
const l = e.match(this.interpolator.nestingRegexp);
|
|
306
302
|
if (l && l.length > 0)
|
|
@@ -318,8 +314,7 @@ class G extends Z {
|
|
|
318
314
|
}
|
|
319
315
|
translate(e, t, i) {
|
|
320
316
|
let s = typeof t == "object" ? p({}, t) : t;
|
|
321
|
-
if (typeof s != "object" && this.options.overloadTranslationOptionHandler && (s = this.options.overloadTranslationOptionHandler(arguments)), typeof options == "object" && (s = p({}, s)), s || (s = {}), e == null)
|
|
322
|
-
return "";
|
|
317
|
+
if (typeof s != "object" && this.options.overloadTranslationOptionHandler && (s = this.options.overloadTranslationOptionHandler(arguments)), typeof options == "object" && (s = p({}, s)), s || (s = {}), e == null) return "";
|
|
323
318
|
Array.isArray(e) || (e = [String(e)]);
|
|
324
319
|
const n = s.returnDetails !== void 0 ? s.returnDetails : this.options.returnDetails, r = s.keySeparator !== void 0 ? s.keySeparator : this.options.keySeparator, {
|
|
325
320
|
key: a,
|
|
@@ -346,13 +341,13 @@ class G extends Z {
|
|
|
346
341
|
} : a;
|
|
347
342
|
const d = this.resolve(e, s);
|
|
348
343
|
let c = d == null ? void 0 : d.res;
|
|
349
|
-
const x = (d == null ? void 0 : d.usedKey) || a, S = (d == null ? void 0 : d.exactUsedKey) || a, $ = ["[object Number]", "[object Function]", "[object RegExp]"],
|
|
344
|
+
const x = (d == null ? void 0 : d.usedKey) || a, S = (d == null ? void 0 : d.exactUsedKey) || a, $ = ["[object Number]", "[object Function]", "[object RegExp]"], C = s.joinArrays !== void 0 ? s.joinArrays : this.options.joinArrays, E = !this.i18nFormat || this.i18nFormat.handleAsObject, L = s.count !== void 0 && !g(s.count), F = G.hasDefaultValue(s), z = L ? this.pluralResolver.getSuffix(f, s.count, s) : "", T = s.ordinal && L ? this.pluralResolver.getSuffix(f, s.count, {
|
|
350
345
|
ordinal: !1
|
|
351
|
-
}) : "",
|
|
346
|
+
}) : "", V = L && !s.ordinal && s.count === 0, w = V && s[`defaultValue${this.options.pluralSeparator}zero`] || s[`defaultValue${z}`] || s[`defaultValue${T}`] || s.defaultValue;
|
|
352
347
|
let b = c;
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
if (
|
|
348
|
+
E && !c && F && (b = w);
|
|
349
|
+
const ve = ce(b), Ce = Object.prototype.toString.apply(b);
|
|
350
|
+
if (E && b && ve && $.indexOf(Ce) < 0 && !(g(C) && Array.isArray(b))) {
|
|
356
351
|
if (!s.returnObjects && !this.options.returnObjects) {
|
|
357
352
|
this.options.returnedObjectHandler || this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
358
353
|
const P = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(x, b, O(p({}, s), {
|
|
@@ -364,49 +359,48 @@ class G extends Z {
|
|
|
364
359
|
const P = Array.isArray(b), R = P ? [] : {}, ee = P ? S : x;
|
|
365
360
|
for (const k in b)
|
|
366
361
|
if (Object.prototype.hasOwnProperty.call(b, k)) {
|
|
367
|
-
const
|
|
368
|
-
|
|
362
|
+
const j = `${ee}${r}${k}`;
|
|
363
|
+
F && !c ? R[k] = this.translate(j, O(p({}, s), {
|
|
369
364
|
defaultValue: ce(w) ? w[k] : void 0,
|
|
370
365
|
joinArrays: !1,
|
|
371
366
|
ns: l
|
|
372
|
-
})) : R[k] = this.translate(
|
|
367
|
+
})) : R[k] = this.translate(j, O(p({}, s), {
|
|
373
368
|
joinArrays: !1,
|
|
374
369
|
ns: l
|
|
375
|
-
})), R[k] ===
|
|
370
|
+
})), R[k] === j && (R[k] = b[k]);
|
|
376
371
|
}
|
|
377
372
|
c = R;
|
|
378
373
|
}
|
|
379
|
-
} else if (
|
|
380
|
-
c = c.join(
|
|
374
|
+
} else if (E && g(C) && Array.isArray(c))
|
|
375
|
+
c = c.join(C), c && (c = this.extendTranslation(c, e, s, i));
|
|
381
376
|
else {
|
|
382
377
|
let P = !1, R = !1;
|
|
383
|
-
!this.isValidLookup(c) &&
|
|
384
|
-
const k = (s.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey) && R ? void 0 : c,
|
|
385
|
-
if (R || P ||
|
|
386
|
-
if (this.logger.log(
|
|
387
|
-
const
|
|
378
|
+
!this.isValidLookup(c) && F && (P = !0, c = w), this.isValidLookup(c) || (R = !0, c = a);
|
|
379
|
+
const k = (s.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey) && R ? void 0 : c, j = F && w !== c && this.options.updateMissing;
|
|
380
|
+
if (R || P || j) {
|
|
381
|
+
if (this.logger.log(j ? "updateKey" : "missingKey", f, u, a, j ? w : c), r) {
|
|
382
|
+
const v = this.resolve(a, O(p({}, s), {
|
|
388
383
|
keySeparator: !1
|
|
389
384
|
}));
|
|
390
|
-
|
|
385
|
+
v && v.res && this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
|
|
391
386
|
}
|
|
392
|
-
let
|
|
387
|
+
let A = [];
|
|
393
388
|
const J = this.languageUtils.getFallbackCodes(this.options.fallbackLng, s.lng || this.language);
|
|
394
389
|
if (this.options.saveMissingTo === "fallback" && J && J[0])
|
|
395
|
-
for (let
|
|
396
|
-
|
|
397
|
-
else
|
|
398
|
-
|
|
399
|
-
const te = (C, D, K) => {
|
|
390
|
+
for (let v = 0; v < J.length; v++)
|
|
391
|
+
A.push(J[v]);
|
|
392
|
+
else this.options.saveMissingTo === "all" ? A = this.languageUtils.toResolveHierarchy(s.lng || this.language) : A.push(s.lng || this.language);
|
|
393
|
+
const te = (v, I, K) => {
|
|
400
394
|
var se;
|
|
401
|
-
const ie =
|
|
402
|
-
this.options.missingKeyHandler ? this.options.missingKeyHandler(
|
|
395
|
+
const ie = F && K !== c ? K : k;
|
|
396
|
+
this.options.missingKeyHandler ? this.options.missingKeyHandler(v, u, I, ie, j, s) : (se = this.backendConnector) != null && se.saveMissing && this.backendConnector.saveMissing(v, u, I, ie, j, s), this.emit("missingKey", v, u, I, c);
|
|
403
397
|
};
|
|
404
|
-
this.options.saveMissing && (this.options.saveMissingPlurals && L ?
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
te([
|
|
398
|
+
this.options.saveMissing && (this.options.saveMissingPlurals && L ? A.forEach((v) => {
|
|
399
|
+
const I = this.pluralResolver.getSuffixes(v, s);
|
|
400
|
+
V && s[`defaultValue${this.options.pluralSeparator}zero`] && I.indexOf(`${this.options.pluralSeparator}zero`) < 0 && I.push(`${this.options.pluralSeparator}zero`), I.forEach((K) => {
|
|
401
|
+
te([v], a + K, s[`defaultValue${K}`] || w);
|
|
408
402
|
});
|
|
409
|
-
}) : te(
|
|
403
|
+
}) : te(A, a, w));
|
|
410
404
|
}
|
|
411
405
|
c = this.extendTranslation(c, e, s, d, i), R && c === a && this.options.appendNamespaceToMissingKey && (c = `${u}${h}${a}`), (R || P) && this.options.parseMissingKeyHandler && (c = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${u}${h}${a}` : a, P ? c : void 0, s));
|
|
412
406
|
}
|
|
@@ -436,7 +430,7 @@ class G extends Z {
|
|
|
436
430
|
!i.lng && s && s.res && (i.lng = this.language || s.usedLng), i.nest !== !1 && (e = this.interpolator.nest(e, (...d) => (n == null ? void 0 : n[0]) === d[0] && !i.context ? (this.logger.warn(`It seems you are nesting recursively key: ${d[0]} in key: ${t[0]}`), null) : this.translate(...d, t), i)), i.interpolation && this.interpolator.reset();
|
|
437
431
|
}
|
|
438
432
|
const r = i.postProcess || this.options.postProcess, a = g(r) ? [r] : r;
|
|
439
|
-
return e != null && (a
|
|
433
|
+
return e != null && (a != null && a.length) && i.applyPostProcessor !== !1 && (e = we.handle(a, e, t, this.options && this.options.postProcessPassResolved ? p({
|
|
440
434
|
i18nResolved: O(p({}, s), {
|
|
441
435
|
usedParams: this.getUsedParamsDetails(i)
|
|
442
436
|
})
|
|
@@ -445,35 +439,33 @@ class G extends Z {
|
|
|
445
439
|
resolve(e, t = {}) {
|
|
446
440
|
let i, s, n, r, a;
|
|
447
441
|
return g(e) && (e = [e]), e.forEach((l) => {
|
|
448
|
-
if (this.isValidLookup(i))
|
|
449
|
-
return;
|
|
442
|
+
if (this.isValidLookup(i)) return;
|
|
450
443
|
const u = this.extractFromKey(l, t), h = u.key;
|
|
451
444
|
s = h;
|
|
452
445
|
let f = u.namespaces;
|
|
453
446
|
this.options.fallbackNS && (f = f.concat(this.options.fallbackNS));
|
|
454
447
|
const m = t.count !== void 0 && !g(t.count), d = m && !t.ordinal && t.count === 0, c = t.context !== void 0 && (g(t.context) || typeof t.context == "number") && t.context !== "", x = t.lngs ? t.lngs : this.languageUtils.toResolveHierarchy(t.lng || this.language, t.fallbackLng);
|
|
455
448
|
f.forEach((S) => {
|
|
456
|
-
var $,
|
|
457
|
-
this.isValidLookup(i) || (a = S, !he[`${x[0]}-${S}`] && (($ = this.utils)
|
|
449
|
+
var $, C;
|
|
450
|
+
this.isValidLookup(i) || (a = S, !he[`${x[0]}-${S}`] && (($ = this.utils) != null && $.hasLoadedNamespace) && !((C = this.utils) != null && C.hasLoadedNamespace(a)) && (he[`${x[0]}-${S}`] = !0, this.logger.warn(`key "${s}" for languages "${x.join(", ")}" won't get resolved as namespace "${a}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")), x.forEach((E) => {
|
|
458
451
|
var z;
|
|
459
|
-
if (this.isValidLookup(i))
|
|
460
|
-
|
|
461
|
-
r = j;
|
|
452
|
+
if (this.isValidLookup(i)) return;
|
|
453
|
+
r = E;
|
|
462
454
|
const L = [h];
|
|
463
455
|
if ((z = this.i18nFormat) != null && z.addLookupKeys)
|
|
464
|
-
this.i18nFormat.addLookupKeys(L, h,
|
|
456
|
+
this.i18nFormat.addLookupKeys(L, h, E, S, t);
|
|
465
457
|
else {
|
|
466
|
-
let
|
|
467
|
-
m && (
|
|
468
|
-
const
|
|
469
|
-
if (m && (L.push(h +
|
|
458
|
+
let T;
|
|
459
|
+
m && (T = this.pluralResolver.getSuffix(E, t.count, t));
|
|
460
|
+
const V = `${this.options.pluralSeparator}zero`, w = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
461
|
+
if (m && (L.push(h + T), t.ordinal && T.indexOf(w) === 0 && L.push(h + T.replace(w, this.options.pluralSeparator)), d && L.push(h + V)), c) {
|
|
470
462
|
const b = `${h}${this.options.contextSeparator}${t.context}`;
|
|
471
|
-
L.push(b), m && (L.push(b +
|
|
463
|
+
L.push(b), m && (L.push(b + T), t.ordinal && T.indexOf(w) === 0 && L.push(b + T.replace(w, this.options.pluralSeparator)), d && L.push(b + V));
|
|
472
464
|
}
|
|
473
465
|
}
|
|
474
|
-
let
|
|
475
|
-
for (;
|
|
476
|
-
this.isValidLookup(i) || (n =
|
|
466
|
+
let F;
|
|
467
|
+
for (; F = L.pop(); )
|
|
468
|
+
this.isValidLookup(i) || (n = F, i = this.getResource(E, S, F, t));
|
|
477
469
|
}));
|
|
478
470
|
});
|
|
479
471
|
}), {
|
|
@@ -514,14 +506,12 @@ class de {
|
|
|
514
506
|
this.options = e, this.supportedLngs = this.options.supportedLngs || !1, this.logger = N.create("languageUtils");
|
|
515
507
|
}
|
|
516
508
|
getScriptPartFromCode(e) {
|
|
517
|
-
if (e =
|
|
518
|
-
return null;
|
|
509
|
+
if (e = H(e), !e || e.indexOf("-") < 0) return null;
|
|
519
510
|
const t = e.split("-");
|
|
520
511
|
return t.length === 2 || (t.pop(), t[t.length - 1].toLowerCase() === "x") ? null : this.formatLanguageCode(t.join("-"));
|
|
521
512
|
}
|
|
522
513
|
getLanguagePartFromCode(e) {
|
|
523
|
-
if (e =
|
|
524
|
-
return e;
|
|
514
|
+
if (e = H(e), !e || e.indexOf("-") < 0) return e;
|
|
525
515
|
const t = e.split("-");
|
|
526
516
|
return this.formatLanguageCode(t[0]);
|
|
527
517
|
}
|
|
@@ -540,44 +530,35 @@ class de {
|
|
|
540
530
|
return (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) && (e = this.getLanguagePartFromCode(e)), !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(e) > -1;
|
|
541
531
|
}
|
|
542
532
|
getBestMatchFromCodes(e) {
|
|
543
|
-
if (!e)
|
|
544
|
-
return null;
|
|
533
|
+
if (!e) return null;
|
|
545
534
|
let t;
|
|
546
535
|
return e.forEach((i) => {
|
|
547
|
-
if (t)
|
|
548
|
-
return;
|
|
536
|
+
if (t) return;
|
|
549
537
|
const s = this.formatLanguageCode(i);
|
|
550
538
|
(!this.options.supportedLngs || this.isSupportedCode(s)) && (t = s);
|
|
551
539
|
}), !t && this.options.supportedLngs && e.forEach((i) => {
|
|
552
|
-
if (t)
|
|
553
|
-
return;
|
|
540
|
+
if (t) return;
|
|
554
541
|
const s = this.getScriptPartFromCode(i);
|
|
555
|
-
if (this.isSupportedCode(s))
|
|
556
|
-
return t = s;
|
|
542
|
+
if (this.isSupportedCode(s)) return t = s;
|
|
557
543
|
const n = this.getLanguagePartFromCode(i);
|
|
558
|
-
if (this.isSupportedCode(n))
|
|
559
|
-
return t = n;
|
|
544
|
+
if (this.isSupportedCode(n)) return t = n;
|
|
560
545
|
t = this.options.supportedLngs.find((r) => {
|
|
561
|
-
if (r === n)
|
|
562
|
-
return r;
|
|
546
|
+
if (r === n) return r;
|
|
563
547
|
if (!(r.indexOf("-") < 0 && n.indexOf("-") < 0) && (r.indexOf("-") > 0 && n.indexOf("-") < 0 && r.substring(0, r.indexOf("-")) === n || r.indexOf(n) === 0 && n.length > 1))
|
|
564
548
|
return r;
|
|
565
549
|
});
|
|
566
550
|
}), t || (t = this.getFallbackCodes(this.options.fallbackLng)[0]), t;
|
|
567
551
|
}
|
|
568
552
|
getFallbackCodes(e, t) {
|
|
569
|
-
if (!e)
|
|
570
|
-
|
|
571
|
-
if (
|
|
572
|
-
return e;
|
|
573
|
-
if (!t)
|
|
574
|
-
return e.default || [];
|
|
553
|
+
if (!e) return [];
|
|
554
|
+
if (typeof e == "function" && (e = e(t)), g(e) && (e = [e]), Array.isArray(e)) return e;
|
|
555
|
+
if (!t) return e.default || [];
|
|
575
556
|
let i = e[t];
|
|
576
557
|
return i || (i = e[this.getScriptPartFromCode(t)]), i || (i = e[this.formatLanguageCode(t)]), i || (i = e[this.getLanguagePartFromCode(t)]), i || (i = e.default), i || [];
|
|
577
558
|
}
|
|
578
559
|
toResolveHierarchy(e, t) {
|
|
579
560
|
const i = this.getFallbackCodes((t === !1 ? [] : t) || this.options.fallbackLng || [], e), s = [], n = (r) => {
|
|
580
|
-
|
|
561
|
+
r && (this.isSupportedCode(r) ? s.push(r) : this.logger.warn(`rejecting language code not found in supportedLngs: ${r}`));
|
|
581
562
|
};
|
|
582
563
|
return g(e) && (e.indexOf("-") > -1 || e.indexOf("_") > -1) ? (this.options.load !== "languageOnly" && n(this.formatLanguageCode(e)), this.options.load !== "languageOnly" && this.options.load !== "currentOnly" && n(this.getScriptPartFromCode(e)), this.options.load !== "currentOnly" && n(this.getLanguagePartFromCode(e))) : g(e) && n(this.formatLanguageCode(e)), i.forEach((r) => {
|
|
583
564
|
s.indexOf(r) < 0 && n(this.formatLanguageCode(r));
|
|
@@ -597,7 +578,7 @@ const pe = {
|
|
|
597
578
|
pluralCategories: ["one", "other"]
|
|
598
579
|
})
|
|
599
580
|
};
|
|
600
|
-
class
|
|
581
|
+
class He {
|
|
601
582
|
constructor(e, t = {}) {
|
|
602
583
|
this.languageUtils = e, this.options = t, this.logger = N.create("pluralResolver"), this.pluralRulesCache = {};
|
|
603
584
|
}
|
|
@@ -608,7 +589,7 @@ class Ue {
|
|
|
608
589
|
this.pluralRulesCache = {};
|
|
609
590
|
}
|
|
610
591
|
getRule(e, t = {}) {
|
|
611
|
-
const i =
|
|
592
|
+
const i = H(e === "dev" ? "en" : e), s = t.ordinal ? "ordinal" : "cardinal", n = JSON.stringify({
|
|
612
593
|
cleanedCode: i,
|
|
613
594
|
type: s
|
|
614
595
|
});
|
|
@@ -622,8 +603,7 @@ class Ue {
|
|
|
622
603
|
} catch (a) {
|
|
623
604
|
if (!Intl)
|
|
624
605
|
return this.logger.error("No Intl support, please use an Intl polyfill!"), ge;
|
|
625
|
-
if (!e.match(/-|_/))
|
|
626
|
-
return ge;
|
|
606
|
+
if (!e.match(/-|_/)) return ge;
|
|
627
607
|
const l = this.languageUtils.getLanguagePartFromCode(e);
|
|
628
608
|
r = this.getRule(l, t);
|
|
629
609
|
}
|
|
@@ -646,10 +626,10 @@ class Ue {
|
|
|
646
626
|
}
|
|
647
627
|
}
|
|
648
628
|
const me = (o, e, t, i = ".", s = !0) => {
|
|
649
|
-
let n =
|
|
629
|
+
let n = Ee(o, e, t);
|
|
650
630
|
return !n && s && g(t) && (n = q(o, t, i), n === void 0 && (n = q(e, t, i))), n;
|
|
651
631
|
}, X = (o) => o.replace(/\$/g, "$$$$");
|
|
652
|
-
class
|
|
632
|
+
class Be {
|
|
653
633
|
constructor(e = {}) {
|
|
654
634
|
var t;
|
|
655
635
|
this.logger = N.create("interpolator"), this.options = e, this.format = ((t = e == null ? void 0 : e.interpolation) == null ? void 0 : t.format) || ((i) => i), this.init(e);
|
|
@@ -675,9 +655,9 @@ class Me {
|
|
|
675
655
|
nestingSuffixEscaped: x,
|
|
676
656
|
nestingOptionsSeparator: S,
|
|
677
657
|
maxReplaces: $,
|
|
678
|
-
alwaysFormat:
|
|
658
|
+
alwaysFormat: C
|
|
679
659
|
} = e.interpolation;
|
|
680
|
-
this.escape = t !== void 0 ? t :
|
|
660
|
+
this.escape = t !== void 0 ? t : De, this.escapeValue = i !== void 0 ? i : !0, this.useRawValueToEscape = s !== void 0 ? s : !1, this.prefix = n ? D(n) : r || "{{", this.suffix = a ? D(a) : l || "}}", this.formatSeparator = u || ",", this.unescapePrefix = h ? "" : f || "-", this.unescapeSuffix = this.unescapePrefix ? "" : h || "", this.nestingPrefix = m ? D(m) : d || D("$t("), this.nestingSuffix = c ? D(c) : x || D(")"), this.nestingOptionsSeparator = S || ",", this.maxReplaces = $ || 1e3, this.alwaysFormat = C !== void 0 ? C : !1, this.resetRegExp();
|
|
681
661
|
}
|
|
682
662
|
reset() {
|
|
683
663
|
this.options && this.init(this.options);
|
|
@@ -691,10 +671,10 @@ class Me {
|
|
|
691
671
|
let n, r, a;
|
|
692
672
|
const l = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {}, u = (c) => {
|
|
693
673
|
if (c.indexOf(this.formatSeparator) < 0) {
|
|
694
|
-
const
|
|
695
|
-
return this.alwaysFormat ? this.format(
|
|
674
|
+
const C = me(t, l, c, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
675
|
+
return this.alwaysFormat ? this.format(C, void 0, i, O(p(p({}, s), t), {
|
|
696
676
|
interpolationkey: c
|
|
697
|
-
})) :
|
|
677
|
+
})) : C;
|
|
698
678
|
}
|
|
699
679
|
const x = c.split(this.formatSeparator), S = x.shift().trim(), $ = x.join(this.formatSeparator).trim();
|
|
700
680
|
return this.format(me(t, l, S, this.options.keySeparator, this.options.ignoreJSONStructure), $, i, O(p(p({}, s), t), {
|
|
@@ -723,8 +703,7 @@ class Me {
|
|
|
723
703
|
continue;
|
|
724
704
|
} else
|
|
725
705
|
this.logger.warn(`missed to pass in variable ${x} for interpolating ${e}`), r = "";
|
|
726
|
-
else
|
|
727
|
-
!g(r) && !this.useRawValueToEscape && (r = ae(r));
|
|
706
|
+
else !g(r) && !this.useRawValueToEscape && (r = ae(r));
|
|
728
707
|
const S = c.safeValue(r);
|
|
729
708
|
if (e = e.replace(n[0], S), f ? (c.regex.lastIndex += r.length, c.regex.lastIndex -= n[0].length) : c.regex.lastIndex = 0, a++, a >= this.maxReplaces)
|
|
730
709
|
break;
|
|
@@ -736,8 +715,7 @@ class Me {
|
|
|
736
715
|
const a = (l, u) => {
|
|
737
716
|
var x;
|
|
738
717
|
const h = this.nestingOptionsSeparator;
|
|
739
|
-
if (l.indexOf(h) < 0)
|
|
740
|
-
return l;
|
|
718
|
+
if (l.indexOf(h) < 0) return l;
|
|
741
719
|
const f = l.split(new RegExp(`${h}[ ]*{`));
|
|
742
720
|
let m = `{${f[1]}`;
|
|
743
721
|
l = f[0], m = this.interpolate(m, r);
|
|
@@ -754,8 +732,7 @@ class Me {
|
|
|
754
732
|
let l = [];
|
|
755
733
|
r = p({}, i), r = r.replace && !g(r.replace) ? r.replace : r, r.applyPostProcessor = !1, delete r.defaultValue;
|
|
756
734
|
const u = /{.*}/.test(s[1]) ? s[1].lastIndexOf("}") + 1 : s[1].indexOf(this.formatSeparator);
|
|
757
|
-
if (u !== -1 && (l = s[1].slice(u).split(this.formatSeparator).map((h) => h.trim()).filter(Boolean), s[1] = s[1].slice(0, u)), n = t(a.call(this, s[1].trim(), r), r), n && s[0] === e && !g(n))
|
|
758
|
-
return n;
|
|
735
|
+
if (u !== -1 && (l = s[1].slice(u).split(this.formatSeparator).map((h) => h.trim()).filter(Boolean), s[1] = s[1].slice(0, u)), n = t(a.call(this, s[1].trim(), r), r), n && s[0] === e && !g(n)) return n;
|
|
759
736
|
g(n) || (n = ae(n)), n || (this.logger.warn(`missed to resolve ${s[1]} for nesting ${e}`), n = ""), l.length && (n = l.reduce((h, f) => this.format(h, f, i.lng, O(p({}, i), {
|
|
760
737
|
interpolationkey: s[1].trim()
|
|
761
738
|
})), n.trim())), e = e.replace(s[0], n), this.regexp.lastIndex = 0;
|
|
@@ -763,7 +740,7 @@ class Me {
|
|
|
763
740
|
return e;
|
|
764
741
|
}
|
|
765
742
|
}
|
|
766
|
-
const
|
|
743
|
+
const ze = (o) => {
|
|
767
744
|
let e = o.toLowerCase().trim();
|
|
768
745
|
const t = {};
|
|
769
746
|
if (o.indexOf("(") > -1) {
|
|
@@ -790,10 +767,10 @@ const Be = (o) => {
|
|
|
790
767
|
}));
|
|
791
768
|
const r = i + JSON.stringify(n);
|
|
792
769
|
let a = e[r];
|
|
793
|
-
return a || (a = o(
|
|
770
|
+
return a || (a = o(H(i), s), e[r] = a), a(t);
|
|
794
771
|
};
|
|
795
|
-
},
|
|
796
|
-
class
|
|
772
|
+
}, Je = (o) => (e, t, i) => o(H(t), i)(e);
|
|
773
|
+
class We {
|
|
797
774
|
constructor(e = {}) {
|
|
798
775
|
this.logger = N.create("formatter"), this.options = e, this.init(e);
|
|
799
776
|
}
|
|
@@ -801,7 +778,7 @@ class ze {
|
|
|
801
778
|
interpolation: {}
|
|
802
779
|
}) {
|
|
803
780
|
this.formatSeparator = t.interpolation.formatSeparator || ",";
|
|
804
|
-
const i = t.cacheInBuiltFormats ? xe :
|
|
781
|
+
const i = t.cacheInBuiltFormats ? xe : Je;
|
|
805
782
|
this.formats = {
|
|
806
783
|
number: i((s, n) => {
|
|
807
784
|
const r = new Intl.NumberFormat(s, p({}, n));
|
|
@@ -844,7 +821,7 @@ class ze {
|
|
|
844
821
|
const {
|
|
845
822
|
formatName: u,
|
|
846
823
|
formatOptions: h
|
|
847
|
-
} =
|
|
824
|
+
} = ze(l);
|
|
848
825
|
if (this.formats[u]) {
|
|
849
826
|
let m = a;
|
|
850
827
|
try {
|
|
@@ -860,10 +837,10 @@ class ze {
|
|
|
860
837
|
}, e);
|
|
861
838
|
}
|
|
862
839
|
}
|
|
863
|
-
const
|
|
840
|
+
const _e = (o, e) => {
|
|
864
841
|
o.pending[e] !== void 0 && (delete o.pending[e], o.pendingCount--);
|
|
865
842
|
};
|
|
866
|
-
class
|
|
843
|
+
class Ye extends Z {
|
|
867
844
|
constructor(e, t, i, s = {}) {
|
|
868
845
|
var n, r;
|
|
869
846
|
super(), this.backend = e, this.store = t, this.services = i, this.languageUtils = i.languageUtils, this.options = s, this.logger = N.create("backendConnector"), this.waitingReads = [], this.maxParallelReads = s.maxParallelReads || 10, this.readingCalls = 0, this.maxRetries = s.maxRetries >= 0 ? s.maxRetries : 5, this.retryTimeout = s.retryTimeout >= 1 ? s.retryTimeout : 350, this.state = {}, this.queue = [], (r = (n = this.backend) == null ? void 0 : n.init) == null || r.call(n, i, s.backend, s);
|
|
@@ -896,7 +873,7 @@ class We extends Z {
|
|
|
896
873
|
}), this.state[e] = t ? -1 : 2, t && i && (this.state[e] = 0);
|
|
897
874
|
const a = {};
|
|
898
875
|
this.queue.forEach((l) => {
|
|
899
|
-
|
|
876
|
+
je(l.loaded, [n], r), _e(l, e), t && l.errors.push(t), l.pendingCount === 0 && !l.done && (Object.keys(l.loaded).forEach((u) => {
|
|
900
877
|
a[u] || (a[u] = {});
|
|
901
878
|
const h = l.loaded[u];
|
|
902
879
|
h.length && h.forEach((f) => {
|
|
@@ -906,8 +883,7 @@ class We extends Z {
|
|
|
906
883
|
}), this.emit("loaded", a), this.queue = this.queue.filter((l) => !l.done);
|
|
907
884
|
}
|
|
908
885
|
read(e, t, i, s = 0, n = this.retryTimeout, r) {
|
|
909
|
-
if (!e.length)
|
|
910
|
-
return r(null, {});
|
|
886
|
+
if (!e.length) return r(null, {});
|
|
911
887
|
if (this.readingCalls >= this.maxParallelReads) {
|
|
912
888
|
this.waitingReads.push({
|
|
913
889
|
lng: e,
|
|
@@ -972,7 +948,7 @@ class We extends Z {
|
|
|
972
948
|
saveMissing(e, t, i, s, n, r = {}, a = () => {
|
|
973
949
|
}) {
|
|
974
950
|
var l, u, h, f, m;
|
|
975
|
-
if ((
|
|
951
|
+
if ((u = (l = this.services) == null ? void 0 : l.utils) != null && u.hasLoadedNamespace && !((f = (h = this.services) == null ? void 0 : h.utils) != null && f.hasLoadedNamespace(t))) {
|
|
976
952
|
this.logger.warn(`did not save key "${i}" as the namespace "${t}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
977
953
|
return;
|
|
978
954
|
}
|
|
@@ -1056,16 +1032,16 @@ const ye = () => ({
|
|
|
1056
1032
|
var e, t;
|
|
1057
1033
|
return g(o.ns) && (o.ns = [o.ns]), g(o.fallbackLng) && (o.fallbackLng = [o.fallbackLng]), g(o.fallbackNS) && (o.fallbackNS = [o.fallbackNS]), ((t = (e = o.supportedLngs) == null ? void 0 : e.indexOf) == null ? void 0 : t.call(e, "cimode")) < 0 && (o.supportedLngs = o.supportedLngs.concat(["cimode"])), typeof o.initImmediate == "boolean" && (o.initAsync = o.initImmediate), o;
|
|
1058
1034
|
}, W = () => {
|
|
1059
|
-
},
|
|
1035
|
+
}, Qe = (o) => {
|
|
1060
1036
|
Object.getOwnPropertyNames(Object.getPrototypeOf(o)).forEach((t) => {
|
|
1061
1037
|
typeof o[t] == "function" && (o[t] = o[t].bind(o));
|
|
1062
1038
|
});
|
|
1063
1039
|
};
|
|
1064
|
-
class
|
|
1040
|
+
class B extends Z {
|
|
1065
1041
|
constructor(e = {}, t) {
|
|
1066
1042
|
if (super(), this.options = Se(e), this.services = {}, this.logger = N, this.modules = {
|
|
1067
1043
|
external: []
|
|
1068
|
-
},
|
|
1044
|
+
}, Qe(this), t && !this.isInitialized && !e.isClone) {
|
|
1069
1045
|
if (!this.options.initAsync)
|
|
1070
1046
|
return this.init(e, t), this;
|
|
1071
1047
|
setTimeout(() => {
|
|
@@ -1081,16 +1057,16 @@ class H extends Z {
|
|
|
1081
1057
|
if (!this.options.isClone) {
|
|
1082
1058
|
this.modules.logger ? N.init(s(this.modules.logger), this.options) : N.init(null, this.options);
|
|
1083
1059
|
let u;
|
|
1084
|
-
this.modules.formatter ? u = this.modules.formatter : u =
|
|
1060
|
+
this.modules.formatter ? u = this.modules.formatter : u = We;
|
|
1085
1061
|
const h = new de(this.options);
|
|
1086
1062
|
this.store = new fe(this.options.resources, this.options);
|
|
1087
1063
|
const f = this.services;
|
|
1088
|
-
f.logger = N, f.resourceStore = this.store, f.languageUtils = h, f.pluralResolver = new
|
|
1064
|
+
f.logger = N, f.resourceStore = this.store, f.languageUtils = h, f.pluralResolver = new He(h, {
|
|
1089
1065
|
prepend: this.options.pluralSeparator,
|
|
1090
1066
|
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1091
|
-
}), this.options.interpolation.format && this.options.interpolation.format !== i.interpolation.format && this.logger.warn("init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting"), u && (!this.options.interpolation.format || this.options.interpolation.format === i.interpolation.format) && (f.formatter = s(u), f.formatter.init && f.formatter.init(f, this.options), this.options.interpolation.format = f.formatter.format.bind(f.formatter)), f.interpolator = new
|
|
1067
|
+
}), this.options.interpolation.format && this.options.interpolation.format !== i.interpolation.format && this.logger.warn("init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting"), u && (!this.options.interpolation.format || this.options.interpolation.format === i.interpolation.format) && (f.formatter = s(u), f.formatter.init && f.formatter.init(f, this.options), this.options.interpolation.format = f.formatter.format.bind(f.formatter)), f.interpolator = new Be(this.options), f.utils = {
|
|
1092
1068
|
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1093
|
-
}, f.backendConnector = new
|
|
1069
|
+
}, f.backendConnector = new Ye(s(this.modules.backend), f.resourceStore, f, this.options), f.backendConnector.on("*", (d, ...c) => {
|
|
1094
1070
|
this.emit(d, ...c);
|
|
1095
1071
|
}), this.modules.languageDetector && (f.languageDetector = s(this.modules.languageDetector), f.languageDetector.init && f.languageDetector.init(f, this.options.detection, this.options)), this.modules.i18nFormat && (f.i18nFormat = s(this.modules.i18nFormat), f.i18nFormat.init && f.i18nFormat.init(this)), this.translator = new G(this.services, this.options), this.translator.on("*", (d, ...c) => {
|
|
1096
1072
|
this.emit(d, ...c);
|
|
@@ -1111,8 +1087,7 @@ class H extends Z {
|
|
|
1111
1087
|
const u = (h, f) => {
|
|
1112
1088
|
this.isInitializing = !1, this.isInitialized && !this.initializedStoreOnce && this.logger.warn("init: i18next is already initialized. You should call init just once!"), this.isInitialized = !0, this.options.isClone || this.logger.log("initialized", this.options), this.emit("initialized", this.options), a.resolve(f), t(h, f);
|
|
1113
1089
|
};
|
|
1114
|
-
if (this.languages && !this.isInitialized)
|
|
1115
|
-
return u(null, this.t.bind(this));
|
|
1090
|
+
if (this.languages && !this.isInitialized) return u(null, this.t.bind(this));
|
|
1116
1091
|
this.changeLanguage(this.options.lng, u);
|
|
1117
1092
|
};
|
|
1118
1093
|
return this.options.resources || !this.options.initAsync ? l() : setTimeout(l, 0), a;
|
|
@@ -1122,11 +1097,9 @@ class H extends Z {
|
|
|
1122
1097
|
let i = t;
|
|
1123
1098
|
const s = g(e) ? e : this.language;
|
|
1124
1099
|
if (typeof e == "function" && (i = e), !this.options.resources || this.options.partialBundledLanguages) {
|
|
1125
|
-
if ((s == null ? void 0 : s.toLowerCase()) === "cimode" && (!this.options.preload || this.options.preload.length === 0))
|
|
1126
|
-
return i();
|
|
1100
|
+
if ((s == null ? void 0 : s.toLowerCase()) === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return i();
|
|
1127
1101
|
const a = [], l = (u) => {
|
|
1128
|
-
if (!u || u === "cimode")
|
|
1129
|
-
return;
|
|
1102
|
+
if (!u || u === "cimode") return;
|
|
1130
1103
|
this.services.languageUtils.toResolveHierarchy(u).forEach((f) => {
|
|
1131
1104
|
f !== "cimode" && a.indexOf(f) < 0 && a.push(f);
|
|
1132
1105
|
});
|
|
@@ -1144,11 +1117,9 @@ class H extends Z {
|
|
|
1144
1117
|
}), s;
|
|
1145
1118
|
}
|
|
1146
1119
|
use(e) {
|
|
1147
|
-
if (!e)
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
1151
|
-
return e.type === "backend" && (this.modules.backend = e), (e.type === "logger" || e.log && e.warn && e.error) && (this.modules.logger = e), e.type === "languageDetector" && (this.modules.languageDetector = e), e.type === "i18nFormat" && (this.modules.i18nFormat = e), e.type === "postProcessor" && Le.addPostProcessor(e), e.type === "formatter" && (this.modules.formatter = e), e.type === "3rdParty" && this.modules.external.push(e), this;
|
|
1120
|
+
if (!e) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
1121
|
+
if (!e.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
1122
|
+
return e.type === "backend" && (this.modules.backend = e), (e.type === "logger" || e.log && e.warn && e.error) && (this.modules.logger = e), e.type === "languageDetector" && (this.modules.languageDetector = e), e.type === "i18nFormat" && (this.modules.i18nFormat = e), e.type === "postProcessor" && we.addPostProcessor(e), e.type === "formatter" && (this.modules.formatter = e), e.type === "3rdParty" && this.modules.external.push(e), this;
|
|
1152
1123
|
}
|
|
1153
1124
|
setResolvedLanguage(e) {
|
|
1154
1125
|
if (!(!e || !this.languages) && !(["cimode", "dev"].indexOf(e) > -1)) {
|
|
@@ -1207,16 +1178,14 @@ class H extends Z {
|
|
|
1207
1178
|
if (!this.languages || !this.languages.length)
|
|
1208
1179
|
return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages), !1;
|
|
1209
1180
|
const i = t.lng || this.resolvedLanguage || this.languages[0], s = this.options ? this.options.fallbackLng : !1, n = this.languages[this.languages.length - 1];
|
|
1210
|
-
if (i.toLowerCase() === "cimode")
|
|
1211
|
-
return !0;
|
|
1181
|
+
if (i.toLowerCase() === "cimode") return !0;
|
|
1212
1182
|
const r = (a, l) => {
|
|
1213
1183
|
const u = this.services.backendConnector.state[`${a}|${l}`];
|
|
1214
1184
|
return u === -1 || u === 0 || u === 2;
|
|
1215
1185
|
};
|
|
1216
1186
|
if (t.precheck) {
|
|
1217
1187
|
const a = t.precheck(this, r);
|
|
1218
|
-
if (a !== void 0)
|
|
1219
|
-
return a;
|
|
1188
|
+
if (a !== void 0) return a;
|
|
1220
1189
|
}
|
|
1221
1190
|
return !!(this.hasResourceBundle(i, e) || !this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages || r(i, e) && (!s || r(n, e)));
|
|
1222
1191
|
}
|
|
@@ -1238,14 +1207,12 @@ class H extends Z {
|
|
|
1238
1207
|
}
|
|
1239
1208
|
dir(e) {
|
|
1240
1209
|
var s, n;
|
|
1241
|
-
if (e || (e = this.resolvedLanguage || (((s = this.languages) == null ? void 0 : s.length) > 0 ? this.languages[0] : this.language)), !e)
|
|
1242
|
-
return "rtl";
|
|
1210
|
+
if (e || (e = this.resolvedLanguage || (((s = this.languages) == null ? void 0 : s.length) > 0 ? this.languages[0] : this.language)), !e) return "rtl";
|
|
1243
1211
|
try {
|
|
1244
1212
|
const r = new Intl.Locale(e);
|
|
1245
1213
|
if (r && r.getTextInfo) {
|
|
1246
1214
|
const a = r.getTextInfo();
|
|
1247
|
-
if (a && a.direction)
|
|
1248
|
-
return a.direction;
|
|
1215
|
+
if (a && a.direction) return a.direction;
|
|
1249
1216
|
}
|
|
1250
1217
|
} catch (r) {
|
|
1251
1218
|
}
|
|
@@ -1253,14 +1220,14 @@ class H extends Z {
|
|
|
1253
1220
|
return e.toLowerCase().indexOf("-latn") > 1 ? "ltr" : t.indexOf(i.getLanguagePartFromCode(e)) > -1 || e.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
1254
1221
|
}
|
|
1255
1222
|
static createInstance(e = {}, t) {
|
|
1256
|
-
return new
|
|
1223
|
+
return new B(e, t);
|
|
1257
1224
|
}
|
|
1258
1225
|
cloneInstance(e = {}, t = W) {
|
|
1259
1226
|
const i = e.forkResourceStore;
|
|
1260
1227
|
i && delete e.forkResourceStore;
|
|
1261
1228
|
const s = O(p(p({}, this.options), e), {
|
|
1262
1229
|
isClone: !0
|
|
1263
|
-
}), n = new
|
|
1230
|
+
}), n = new B(s);
|
|
1264
1231
|
if ((e.debug !== void 0 || e.prefix !== void 0) && (n.logger = n.logger.clone(e)), ["store", "services", "language"].forEach((a) => {
|
|
1265
1232
|
n[a] = this[a];
|
|
1266
1233
|
}), n.services = p({}, this.services), n.services.utils = {
|
|
@@ -1285,8 +1252,8 @@ class H extends Z {
|
|
|
1285
1252
|
};
|
|
1286
1253
|
}
|
|
1287
1254
|
}
|
|
1288
|
-
const y =
|
|
1289
|
-
y.createInstance =
|
|
1255
|
+
const y = B.createInstance();
|
|
1256
|
+
y.createInstance = B.createInstance;
|
|
1290
1257
|
y.createInstance;
|
|
1291
1258
|
y.dir;
|
|
1292
1259
|
y.init;
|
|
@@ -1301,7 +1268,7 @@ y.setDefaultNamespace;
|
|
|
1301
1268
|
y.hasLoadedNamespace;
|
|
1302
1269
|
y.loadNamespaces;
|
|
1303
1270
|
y.loadLanguages;
|
|
1304
|
-
const
|
|
1271
|
+
const Ge = (o, e) => {
|
|
1305
1272
|
for (const t of e) {
|
|
1306
1273
|
const i = o.find(t);
|
|
1307
1274
|
i && i.each((s, n) => {
|
|
@@ -1339,8 +1306,8 @@ const Ye = (o, e) => {
|
|
|
1339
1306
|
}));
|
|
1340
1307
|
});
|
|
1341
1308
|
}
|
|
1342
|
-
},
|
|
1343
|
-
|
|
1309
|
+
}, Ze = (o, e) => {
|
|
1310
|
+
Ge(e, [
|
|
1344
1311
|
".hiprint-option-item-label",
|
|
1345
1312
|
"textarea",
|
|
1346
1313
|
"input",
|
|
@@ -1351,7 +1318,7 @@ const Ye = (o, e) => {
|
|
|
1351
1318
|
".hiprint-option-title",
|
|
1352
1319
|
".hiprint-option-item-desc"
|
|
1353
1320
|
]);
|
|
1354
|
-
},
|
|
1321
|
+
}, Xe = () => {
|
|
1355
1322
|
document.querySelectorAll("[data-i18n]").forEach((o) => {
|
|
1356
1323
|
const e = o.getAttribute("data-i18n");
|
|
1357
1324
|
if (!e.includes("[")) {
|
|
@@ -1365,7 +1332,19 @@ const Ye = (o, e) => {
|
|
|
1365
1332
|
}
|
|
1366
1333
|
});
|
|
1367
1334
|
};
|
|
1368
|
-
|
|
1335
|
+
let be = !1;
|
|
1336
|
+
const Le = (o) => {
|
|
1337
|
+
if (be)
|
|
1338
|
+
return;
|
|
1339
|
+
be = !0, globalThis.hiprint.i18next = y, globalThis.hiprint.t = y.t;
|
|
1340
|
+
const e = Object.keys(o.resources || {});
|
|
1341
|
+
globalThis.hiprint.languages = ["简体中文", ...e], globalThis.hiprint.changeLanguage = (t, i) => {
|
|
1342
|
+
y.changeLanguage(t, (s, n) => {
|
|
1343
|
+
i && i(s, n), Xe();
|
|
1344
|
+
});
|
|
1345
|
+
};
|
|
1346
|
+
};
|
|
1347
|
+
function et(o, e) {
|
|
1369
1348
|
y.init(p({}, o), (i, s) => {
|
|
1370
1349
|
e && e(y, s, i);
|
|
1371
1350
|
});
|
|
@@ -1377,22 +1356,16 @@ function Xe(o, e) {
|
|
|
1377
1356
|
{
|
|
1378
1357
|
hook: "ready",
|
|
1379
1358
|
name: "i18n set",
|
|
1380
|
-
description: "
|
|
1359
|
+
description: "添加 i18n 方法",
|
|
1381
1360
|
priority: 1,
|
|
1382
1361
|
run: () => {
|
|
1383
|
-
|
|
1384
|
-
const i = Object.keys(o.resources || {});
|
|
1385
|
-
globalThis.hiprint.languages = ["\u7B80\u4F53\u4E2D\u6587", ...i], globalThis.hiprint.changeLanguage = (s, n) => {
|
|
1386
|
-
y.changeLanguage(s, (r, a) => {
|
|
1387
|
-
n && n(r, a), Ge();
|
|
1388
|
-
});
|
|
1389
|
-
};
|
|
1362
|
+
Le(o);
|
|
1390
1363
|
}
|
|
1391
1364
|
},
|
|
1392
1365
|
{
|
|
1393
1366
|
hook: "getOptionItem",
|
|
1394
1367
|
name: "i18n options",
|
|
1395
|
-
description: "
|
|
1368
|
+
description: "渲染元素属性时做多语言处理",
|
|
1396
1369
|
priority: 1,
|
|
1397
1370
|
run: (i) => {
|
|
1398
1371
|
if (i) {
|
|
@@ -1402,7 +1375,7 @@ function Xe(o, e) {
|
|
|
1402
1375
|
const r = s.call(i, ...n);
|
|
1403
1376
|
return t.some((a) => a == i.name) && r.attr("data-name") || (r.attr({
|
|
1404
1377
|
"data-name": i.name
|
|
1405
|
-
}),
|
|
1378
|
+
}), Ze(i, r)), r;
|
|
1406
1379
|
}, i;
|
|
1407
1380
|
}
|
|
1408
1381
|
}
|
|
@@ -1410,10 +1383,11 @@ function Xe(o, e) {
|
|
|
1410
1383
|
{
|
|
1411
1384
|
hook: "onDesigned",
|
|
1412
1385
|
name: "i18n other selector",
|
|
1413
|
-
description: "
|
|
1386
|
+
description: "其他UI选择器多语言处理",
|
|
1414
1387
|
priority: 1,
|
|
1415
1388
|
run: ({ hiprint: i, designerUtils: s }) => {
|
|
1416
1389
|
var a;
|
|
1390
|
+
Le(o);
|
|
1417
1391
|
const n = (a = s.printTemplate) == null ? void 0 : a.id;
|
|
1418
1392
|
n && (globalThis.hinnn.event.on("PrintElementSelectEventKey_" + n, (l) => {
|
|
1419
1393
|
setTimeout(() => {
|
|
@@ -1436,7 +1410,7 @@ function Xe(o, e) {
|
|
|
1436
1410
|
{
|
|
1437
1411
|
hook: "onPreview",
|
|
1438
1412
|
name: "i18n preview selector",
|
|
1439
|
-
description: "
|
|
1413
|
+
description: "组件内预览选择器多语言处理",
|
|
1440
1414
|
priority: 1,
|
|
1441
1415
|
run: (i) => {
|
|
1442
1416
|
setTimeout(() => {
|
|
@@ -1449,6 +1423,6 @@ function Xe(o, e) {
|
|
|
1449
1423
|
};
|
|
1450
1424
|
}
|
|
1451
1425
|
export {
|
|
1452
|
-
|
|
1426
|
+
et as default,
|
|
1453
1427
|
_ as translateBySelector
|
|
1454
1428
|
};
|