@prosopo/cli 3.8.17 → 3.8.19

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.
@@ -1,1231 +0,0 @@
1
- import { n as e, t } from "./provider.cli.bundle.js";
2
- //#endregion
3
- //#region ../locale/dist/i18SharedOptions.js
4
- var n = {
5
- debug: (typeof process < "u" ? process : void 0)?.env?.PROSOPO_LOG_LEVEL === "debug",
6
- fallbackLng: t.enum.en,
7
- namespace: "translation",
8
- supportedLngs: Object.values(e),
9
- nonExplicitSupportedLngs: !1
10
- }, r = (e) => typeof e == "string", i = () => {
11
- let e, t, n = new Promise((n, r) => {
12
- e = n, t = r;
13
- });
14
- return n.resolve = e, n.reject = t, n;
15
- }, a = (e) => e == null ? "" : String(e), o = (e, t, n) => {
16
- e.forEach((e) => {
17
- t[e] && (n[e] = t[e]);
18
- });
19
- }, s = /###/g, c = (e) => e && e.includes("###") ? e.replace(s, ".") : e, l = (e) => !e || r(e), u = (e, t, n) => {
20
- let i = r(t) ? t.split(".") : t, a = 0;
21
- for (; a < i.length - 1;) {
22
- if (l(e)) return {};
23
- let t = c(i[a]);
24
- !e[t] && n && (e[t] = new n()), e = Object.prototype.hasOwnProperty.call(e, t) ? e[t] : {}, ++a;
25
- }
26
- return l(e) ? {} : {
27
- obj: e,
28
- k: c(i[a])
29
- };
30
- }, d = (e, t, n) => {
31
- let { obj: r, k: i } = u(e, t, Object);
32
- if (r !== void 0 || t.length === 1) {
33
- r[i] = n;
34
- return;
35
- }
36
- let a = t[t.length - 1], o = t.slice(0, t.length - 1), s = u(e, o, Object);
37
- for (; s.obj === void 0 && o.length;) a = `${o[o.length - 1]}.${a}`, o = o.slice(0, o.length - 1), s = u(e, o, Object), s?.obj && s.obj[`${s.k}.${a}`] !== void 0 && (s.obj = void 0);
38
- s.obj[`${s.k}.${a}`] = n;
39
- }, f = (e, t, n, r) => {
40
- let { obj: i, k: a } = u(e, t, Object);
41
- i[a] = i[a] || [], i[a].push(n);
42
- }, p = (e, t) => {
43
- let { obj: n, k: r } = u(e, t);
44
- if (n && Object.prototype.hasOwnProperty.call(n, r)) return n[r];
45
- }, m = (e, t, n) => {
46
- let r = p(e, n);
47
- return r === void 0 ? p(t, n) : r;
48
- }, h = (e, t, n) => {
49
- for (let i in t) i !== "__proto__" && i !== "constructor" && (Object.prototype.hasOwnProperty.call(e, i) ? r(e[i]) || e[i] instanceof String || r(t[i]) || t[i] instanceof String ? n && (e[i] = t[i]) : h(e[i], t[i], n) : e[i] = t[i]);
50
- return e;
51
- }, g = (e) => e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), _ = {
52
- "&": "&amp;",
53
- "<": "&lt;",
54
- ">": "&gt;",
55
- "\"": "&quot;",
56
- "'": "&#39;",
57
- "/": "&#x2F;"
58
- }, v = (e) => r(e) ? e.replace(/[&<>"'\/]/g, (e) => _[e]) : e, y = class {
59
- constructor(e) {
60
- this.capacity = e, this.regExpMap = /* @__PURE__ */ new Map(), this.regExpQueue = [];
61
- }
62
- getRegExp(e) {
63
- let t = this.regExpMap.get(e);
64
- if (t !== void 0) return t;
65
- let n = new RegExp(e);
66
- return this.regExpQueue.length === this.capacity && this.regExpMap.delete(this.regExpQueue.shift()), this.regExpMap.set(e, n), this.regExpQueue.push(e), n;
67
- }
68
- }, b = [
69
- " ",
70
- ",",
71
- "?",
72
- "!",
73
- ";"
74
- ], x = new y(20), S = (e, t, n) => {
75
- t ||= "", n ||= "";
76
- let r = b.filter((e) => !t.includes(e) && !n.includes(e));
77
- if (r.length === 0) return !0;
78
- let i = x.getRegExp(`(${r.map((e) => e === "?" ? "\\?" : e).join("|")})`), a = !i.test(e);
79
- if (!a) {
80
- let t = e.indexOf(n);
81
- t > 0 && !i.test(e.substring(0, t)) && (a = !0);
82
- }
83
- return a;
84
- }, C = (e, t, n = ".") => {
85
- if (!e) return;
86
- if (e[t]) return Object.prototype.hasOwnProperty.call(e, t) ? e[t] : void 0;
87
- let r = t.split(n), i = e;
88
- for (let e = 0; e < r.length;) {
89
- if (!i || typeof i != "object") return;
90
- let t, a = "";
91
- for (let o = e; o < r.length; ++o) if (o !== e && (a += n), a += r[o], t = i[a], t !== void 0) {
92
- if ([
93
- "string",
94
- "number",
95
- "boolean"
96
- ].includes(typeof t) && o < r.length - 1) continue;
97
- e += o - e + 1;
98
- break;
99
- }
100
- i = t;
101
- }
102
- return i;
103
- }, w = (e) => e?.replace(/_/g, "-"), T = {
104
- type: "logger",
105
- log(e) {
106
- this.output("log", e);
107
- },
108
- warn(e) {
109
- this.output("warn", e);
110
- },
111
- error(e) {
112
- this.output("error", e);
113
- },
114
- output(e, t) {
115
- console?.[e]?.apply?.(console, t);
116
- }
117
- }, E = new class e {
118
- constructor(e, t = {}) {
119
- this.init(e, t);
120
- }
121
- init(e, t = {}) {
122
- this.prefix = t.prefix || "i18next:", this.logger = e || T, this.options = t, this.debug = t.debug;
123
- }
124
- log(...e) {
125
- return this.forward(e, "log", "", !0);
126
- }
127
- warn(...e) {
128
- return this.forward(e, "warn", "", !0);
129
- }
130
- error(...e) {
131
- return this.forward(e, "error", "");
132
- }
133
- deprecate(...e) {
134
- return this.forward(e, "warn", "WARNING DEPRECATED: ", !0);
135
- }
136
- forward(e, t, n, i) {
137
- return i && !this.debug ? null : (e = e.map((e) => r(e) ? e.replace(/[\r\n\x00-\x1F\x7F]/g, " ") : e), r(e[0]) && (e[0] = `${n}${this.prefix} ${e[0]}`), this.logger[t](e));
138
- }
139
- create(t) {
140
- return new e(this.logger, {
141
- prefix: `${this.prefix}:${t}:`,
142
- ...this.options
143
- });
144
- }
145
- clone(t) {
146
- return t ||= this.options, t.prefix = t.prefix || this.prefix, new e(this.logger, t);
147
- }
148
- }(), D = class {
149
- constructor() {
150
- this.observers = {};
151
- }
152
- on(e, t) {
153
- return e.split(" ").forEach((e) => {
154
- this.observers[e] || (this.observers[e] = /* @__PURE__ */ new Map());
155
- let n = this.observers[e].get(t) || 0;
156
- this.observers[e].set(t, n + 1);
157
- }), this;
158
- }
159
- off(e, t) {
160
- if (this.observers[e]) {
161
- if (!t) {
162
- delete this.observers[e];
163
- return;
164
- }
165
- this.observers[e].delete(t);
166
- }
167
- }
168
- once(e, t) {
169
- let n = (...r) => {
170
- t(...r), this.off(e, n);
171
- };
172
- return this.on(e, n), this;
173
- }
174
- emit(e, ...t) {
175
- this.observers[e] && Array.from(this.observers[e].entries()).forEach(([e, n]) => {
176
- for (let r = 0; r < n; r++) e(...t);
177
- }), this.observers["*"] && Array.from(this.observers["*"].entries()).forEach(([n, r]) => {
178
- for (let i = 0; i < r; i++) n(e, ...t);
179
- });
180
- }
181
- }, O = class extends D {
182
- constructor(e, t = {
183
- ns: ["translation"],
184
- defaultNS: "translation"
185
- }) {
186
- super(), this.data = e || {}, this.options = t, this.options.keySeparator === void 0 && (this.options.keySeparator = "."), this.options.ignoreJSONStructure === void 0 && (this.options.ignoreJSONStructure = !0);
187
- }
188
- addNamespaces(e) {
189
- this.options.ns.includes(e) || this.options.ns.push(e);
190
- }
191
- removeNamespaces(e) {
192
- let t = this.options.ns.indexOf(e);
193
- t > -1 && this.options.ns.splice(t, 1);
194
- }
195
- getResource(e, t, n, i = {}) {
196
- let a = i.keySeparator === void 0 ? this.options.keySeparator : i.keySeparator, o = i.ignoreJSONStructure === void 0 ? this.options.ignoreJSONStructure : i.ignoreJSONStructure, s;
197
- e.includes(".") ? s = e.split(".") : (s = [e, t], n && (Array.isArray(n) ? s.push(...n) : r(n) && a ? s.push(...n.split(a)) : s.push(n)));
198
- let c = p(this.data, s);
199
- return !c && !t && !n && e.includes(".") && (e = s[0], t = s[1], n = s.slice(2).join(".")), c || !o || !r(n) ? c : C(this.data?.[e]?.[t], n, a);
200
- }
201
- addResource(e, t, n, r, i = { silent: !1 }) {
202
- let a = i.keySeparator === void 0 ? this.options.keySeparator : i.keySeparator, o = [e, t];
203
- n && (o = o.concat(a ? n.split(a) : n)), e.includes(".") && (o = e.split("."), r = t, t = o[1]), this.addNamespaces(t), d(this.data, o, r), i.silent || this.emit("added", e, t, n, r);
204
- }
205
- addResources(e, t, n, i = { silent: !1 }) {
206
- for (let i in n) (r(n[i]) || Array.isArray(n[i])) && this.addResource(e, t, i, n[i], { silent: !0 });
207
- i.silent || this.emit("added", e, t, n);
208
- }
209
- addResourceBundle(e, t, n, r, i, a = {
210
- silent: !1,
211
- skipCopy: !1
212
- }) {
213
- let o = [e, t];
214
- e.includes(".") && (o = e.split("."), r = n, n = t, t = o[1]), this.addNamespaces(t);
215
- let s = p(this.data, o) || {};
216
- a.skipCopy || (n = JSON.parse(JSON.stringify(n))), r ? h(s, n, i) : s = {
217
- ...s,
218
- ...n
219
- }, d(this.data, o, s), a.silent || this.emit("added", e, t, n);
220
- }
221
- removeResourceBundle(e, t) {
222
- this.hasResourceBundle(e, t) && delete this.data[e][t], this.removeNamespaces(t), this.emit("removed", e, t);
223
- }
224
- hasResourceBundle(e, t) {
225
- return this.getResource(e, t) !== void 0;
226
- }
227
- getResourceBundle(e, t) {
228
- return t ||= this.options.defaultNS, this.getResource(e, t);
229
- }
230
- getDataByLanguage(e) {
231
- return this.data[e];
232
- }
233
- hasLanguageSomeTranslations(e) {
234
- let t = this.getDataByLanguage(e);
235
- return !!(t && Object.keys(t) || []).find((e) => t[e] && Object.keys(t[e]).length > 0);
236
- }
237
- toJSON() {
238
- return this.data;
239
- }
240
- }, k = {
241
- processors: {},
242
- addPostProcessor(e) {
243
- this.processors[e.name] = e;
244
- },
245
- handle(e, t, n, r, i) {
246
- return e.forEach((e) => {
247
- t = this.processors[e]?.process(t, n, r, i) ?? t;
248
- }), t;
249
- }
250
- }, A = Symbol("i18next/PATH_KEY");
251
- function j() {
252
- let e = [], t = Object.create(null), n;
253
- return t.get = (r, i) => (n?.revoke?.(), i === A ? e : (e.push(i), n = Proxy.revocable(r, t), n.proxy)), Proxy.revocable(Object.create(null), t).proxy;
254
- }
255
- function M(e, t) {
256
- let { [A]: n } = e(j()), r = t?.keySeparator ?? ".", i = t?.nsSeparator ?? ":", a = t?.enableSelector === "strict";
257
- if (n.length > 1 && i) {
258
- let e = t?.ns, o = a ? Array.isArray(e) ? e : e ? [e] : null : Array.isArray(e) ? e : null;
259
- if (o && (a ? o : o.length > 1 ? o.slice(1) : []).includes(n[0])) return `${n[0]}${i}${n.slice(1).join(r)}`;
260
- }
261
- return n.join(r);
262
- }
263
- var N = (e) => !r(e) && typeof e != "boolean" && typeof e != "number", P = class e extends D {
264
- constructor(e, t = {}) {
265
- super(), o([
266
- "resourceStore",
267
- "languageUtils",
268
- "pluralResolver",
269
- "interpolator",
270
- "backendConnector",
271
- "i18nFormat",
272
- "utils"
273
- ], e, this), this.options = t, this.options.keySeparator === void 0 && (this.options.keySeparator = "."), this.logger = E.create("translator"), this.checkedLoadedFor = {};
274
- }
275
- changeLanguage(e) {
276
- e && (this.language = e);
277
- }
278
- exists(e, t = { interpolation: {} }) {
279
- let n = { ...t };
280
- if (e == null) return !1;
281
- let r = this.resolve(e, n);
282
- if (r?.res === void 0) return !1;
283
- let i = N(r.res);
284
- return !(n.returnObjects === !1 && i);
285
- }
286
- extractFromKey(e, t) {
287
- let n = t.nsSeparator === void 0 ? this.options.nsSeparator : t.nsSeparator;
288
- n === void 0 && (n = ":");
289
- let i = t.keySeparator === void 0 ? this.options.keySeparator : t.keySeparator, a = t.ns || this.options.defaultNS || [], o = n && e.includes(n), s = !this.options.userDefinedKeySeparator && !t.keySeparator && !this.options.userDefinedNsSeparator && !t.nsSeparator && !S(e, n, i);
290
- if (o && !s) {
291
- let t = e.match(this.interpolator.nestingRegexp);
292
- if (t && t.length > 0) return {
293
- key: e,
294
- namespaces: r(a) ? [a] : a
295
- };
296
- let o = e.split(n);
297
- (n !== i || n === i && this.options.ns.includes(o[0])) && (a = o.shift()), e = o.join(i);
298
- }
299
- return {
300
- key: e,
301
- namespaces: r(a) ? [a] : a
302
- };
303
- }
304
- translate(t, n, i) {
305
- let a = typeof n == "object" ? { ...n } : n;
306
- if (typeof a != "object" && this.options.overloadTranslationOptionHandler && (a = this.options.overloadTranslationOptionHandler(arguments)), typeof a == "object" && (a = { ...a }), a ||= {}, t == null) return "";
307
- typeof t == "function" && (t = M(t, {
308
- ...this.options,
309
- ...a
310
- })), Array.isArray(t) || (t = [String(t)]), t = t.map((e) => typeof e == "function" ? M(e, {
311
- ...this.options,
312
- ...a
313
- }) : String(e));
314
- let o = a.returnDetails === void 0 ? this.options.returnDetails : a.returnDetails, s = a.keySeparator === void 0 ? this.options.keySeparator : a.keySeparator, { key: c, namespaces: l } = this.extractFromKey(t[t.length - 1], a), u = l[l.length - 1], d = a.nsSeparator === void 0 ? this.options.nsSeparator : a.nsSeparator;
315
- d === void 0 && (d = ":");
316
- let f = a.lng || this.language, p = a.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
317
- if (f?.toLowerCase() === "cimode") return p ? o ? {
318
- res: `${u}${d}${c}`,
319
- usedKey: c,
320
- exactUsedKey: c,
321
- usedLng: f,
322
- usedNS: u,
323
- usedParams: this.getUsedParamsDetails(a)
324
- } : `${u}${d}${c}` : o ? {
325
- res: c,
326
- usedKey: c,
327
- exactUsedKey: c,
328
- usedLng: f,
329
- usedNS: u,
330
- usedParams: this.getUsedParamsDetails(a)
331
- } : c;
332
- let m = this.resolve(t, a), h = m?.res, g = m?.usedKey || c, _ = m?.exactUsedKey || c, v = [
333
- "[object Number]",
334
- "[object Function]",
335
- "[object RegExp]"
336
- ], y = a.joinArrays === void 0 ? this.options.joinArrays : a.joinArrays, b = !this.i18nFormat || this.i18nFormat.handleAsObject, x = a.count !== void 0 && !r(a.count), S = e.hasDefaultValue(a), C = x ? this.pluralResolver.getSuffix(f, a.count, a) : "", w = a.ordinal && x ? this.pluralResolver.getSuffix(f, a.count, { ordinal: !1 }) : "", T = x && !a.ordinal && a.count === 0, E = T && a[`defaultValue${this.options.pluralSeparator}zero`] || a[`defaultValue${C}`] || a[`defaultValue${w}`] || a.defaultValue, D = h;
337
- b && !h && S && (D = E);
338
- let O = N(D), k = Object.prototype.toString.apply(D);
339
- if (b && D && O && !v.includes(k) && !(r(y) && Array.isArray(D))) {
340
- if (!a.returnObjects && !this.options.returnObjects) {
341
- this.options.returnedObjectHandler || this.logger.warn("accessing an object - but returnObjects options is not enabled!");
342
- let e = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(g, D, {
343
- ...a,
344
- ns: l
345
- }) : `key '${c} (${this.language})' returned an object instead of string.`;
346
- return o ? (m.res = e, m.usedParams = this.getUsedParamsDetails(a), m) : e;
347
- }
348
- if (s) {
349
- let e = Array.isArray(D), t = e ? [] : {}, n = e ? _ : g;
350
- for (let e in D) if (Object.prototype.hasOwnProperty.call(D, e)) {
351
- let r = `${n}${s}${e}`;
352
- S && !h ? t[e] = this.translate(r, {
353
- ...a,
354
- defaultValue: N(E) ? E[e] : void 0,
355
- joinArrays: !1,
356
- ns: l
357
- }) : t[e] = this.translate(r, {
358
- ...a,
359
- joinArrays: !1,
360
- ns: l
361
- }), t[e] === r && (t[e] = D[e]);
362
- }
363
- h = t;
364
- }
365
- } else if (b && r(y) && Array.isArray(h)) h = h.join(y), h &&= this.extendTranslation(h, t, a, i);
366
- else {
367
- let e = !1, n = !1;
368
- !this.isValidLookup(h) && S && (e = !0, h = E), this.isValidLookup(h) || (n = !0, h = c);
369
- let r = (a.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey) && n ? void 0 : h, o = S && E !== h && this.options.updateMissing;
370
- if (n || e || o) {
371
- if (this.logger.log(o ? "updateKey" : "missingKey", f, u, x && !o ? `${c}${this.pluralResolver.getSuffix(f, a.count, a)}` : c, o ? E : h), s) {
372
- let e = this.resolve(c, {
373
- ...a,
374
- keySeparator: !1
375
- });
376
- e && e.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.");
377
- }
378
- let e = [], t = this.languageUtils.getFallbackCodes(this.options.fallbackLng, a.lng || this.language);
379
- if (this.options.saveMissingTo === "fallback" && t && t[0]) for (let n = 0; n < t.length; n++) e.push(t[n]);
380
- else this.options.saveMissingTo === "all" ? e = this.languageUtils.toResolveHierarchy(a.lng || this.language) : e.push(a.lng || this.language);
381
- let n = (e, t, n) => {
382
- let i = S && n !== h ? n : r;
383
- this.options.missingKeyHandler ? this.options.missingKeyHandler(e, u, t, i, o, a) : this.backendConnector?.saveMissing && this.backendConnector.saveMissing(e, u, t, i, o, a), this.emit("missingKey", e, u, t, h);
384
- };
385
- this.options.saveMissing && (this.options.saveMissingPlurals && x ? e.forEach((e) => {
386
- let t = this.pluralResolver.getSuffixes(e, a);
387
- T && a[`defaultValue${this.options.pluralSeparator}zero`] && !t.includes(`${this.options.pluralSeparator}zero`) && t.push(`${this.options.pluralSeparator}zero`), t.forEach((t) => {
388
- n([e], c + t, a[`defaultValue${t}`] || E);
389
- });
390
- }) : n(e, c, E));
391
- }
392
- h = this.extendTranslation(h, t, a, m, i), n && h === c && this.options.appendNamespaceToMissingKey && (h = `${u}${d}${c}`), (n || e) && this.options.parseMissingKeyHandler && (h = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${u}${d}${c}` : c, e ? h : void 0, a));
393
- }
394
- return o ? (m.res = h, m.usedParams = this.getUsedParamsDetails(a), m) : h;
395
- }
396
- extendTranslation(e, t, n, i, a) {
397
- if (this.i18nFormat?.parse) e = this.i18nFormat.parse(e, {
398
- ...this.options.interpolation.defaultVariables,
399
- ...n
400
- }, n.lng || this.language || i.usedLng, i.usedNS, i.usedKey, { resolved: i });
401
- else if (!n.skipInterpolation) {
402
- n.interpolation && this.interpolator.init({
403
- ...n,
404
- interpolation: {
405
- ...this.options.interpolation,
406
- ...n.interpolation
407
- }
408
- });
409
- let o = r(e) && (n?.interpolation?.skipOnVariables === void 0 ? this.options.interpolation.skipOnVariables : n.interpolation.skipOnVariables), s;
410
- if (o) {
411
- let t = e.match(this.interpolator.nestingRegexp);
412
- s = t && t.length;
413
- }
414
- let c = n.replace && !r(n.replace) ? n.replace : n;
415
- if (this.options.interpolation.defaultVariables && (c = {
416
- ...this.options.interpolation.defaultVariables,
417
- ...c
418
- }), e = this.interpolator.interpolate(e, c, n.lng || this.language || i.usedLng, n), o) {
419
- let t = e.match(this.interpolator.nestingRegexp), r = t && t.length;
420
- s < r && (n.nest = !1);
421
- }
422
- !n.lng && i && i.res && (n.lng = this.language || i.usedLng), n.nest !== !1 && (e = this.interpolator.nest(e, (...e) => a?.[0] === e[0] && !n.context ? (this.logger.warn(`It seems you are nesting recursively key: ${e[0]} in key: ${t[0]}`), null) : this.translate(...e, t), n)), n.interpolation && this.interpolator.reset();
423
- }
424
- let o = n.postProcess || this.options.postProcess, s = r(o) ? [o] : o;
425
- return e != null && s?.length && n.applyPostProcessor !== !1 && (e = k.handle(s, e, t, this.options && this.options.postProcessPassResolved ? {
426
- i18nResolved: {
427
- ...i,
428
- usedParams: this.getUsedParamsDetails(n)
429
- },
430
- ...n
431
- } : n, this)), e;
432
- }
433
- resolve(e, t = {}) {
434
- let n, i, a, o, s;
435
- return r(e) && (e = [e]), Array.isArray(e) && (e = e.map((e) => typeof e == "function" ? M(e, {
436
- ...this.options,
437
- ...t
438
- }) : e)), e.forEach((e) => {
439
- if (this.isValidLookup(n)) return;
440
- let c = this.extractFromKey(e, t), l = c.key;
441
- i = l;
442
- let u = c.namespaces;
443
- this.options.fallbackNS && (u = u.concat(this.options.fallbackNS));
444
- let d = t.count !== void 0 && !r(t.count), f = d && !t.ordinal && t.count === 0, p = t.context !== void 0 && (r(t.context) || typeof t.context == "number") && t.context !== "", m = t.lngs ? t.lngs : this.languageUtils.toResolveHierarchy(t.lng || this.language, t.fallbackLng);
445
- u.forEach((e) => {
446
- this.isValidLookup(n) || (s = e, !this.checkedLoadedFor[`${m[0]}-${e}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(s) && (this.checkedLoadedFor[`${m[0]}-${e}`] = !0, this.logger.warn(`key "${i}" for languages "${m.join(", ")}" won't get resolved as namespace "${s}" 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!!!")), m.forEach((r) => {
447
- if (this.isValidLookup(n)) return;
448
- o = r;
449
- let i = [l];
450
- if (this.i18nFormat?.addLookupKeys) this.i18nFormat.addLookupKeys(i, l, r, e, t);
451
- else {
452
- let e;
453
- d && (e = this.pluralResolver.getSuffix(r, t.count, t));
454
- let n = `${this.options.pluralSeparator}zero`, a = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
455
- if (d && (t.ordinal && e.startsWith(a) && i.push(l + e.replace(a, this.options.pluralSeparator)), i.push(l + e), f && i.push(l + n)), p) {
456
- let r = `${l}${this.options.contextSeparator || "_"}${t.context}`;
457
- i.push(r), d && (t.ordinal && e.startsWith(a) && i.push(r + e.replace(a, this.options.pluralSeparator)), i.push(r + e), f && i.push(r + n));
458
- }
459
- }
460
- let s;
461
- for (; s = i.pop();) this.isValidLookup(n) || (a = s, n = this.getResource(r, e, s, t));
462
- }));
463
- });
464
- }), {
465
- res: n,
466
- usedKey: i,
467
- exactUsedKey: a,
468
- usedLng: o,
469
- usedNS: s
470
- };
471
- }
472
- isValidLookup(e) {
473
- return e !== void 0 && !(!this.options.returnNull && e === null) && !(!this.options.returnEmptyString && e === "");
474
- }
475
- getResource(e, t, n, r = {}) {
476
- return this.i18nFormat?.getResource ? this.i18nFormat.getResource(e, t, n, r) : this.resourceStore.getResource(e, t, n, r);
477
- }
478
- getUsedParamsDetails(e = {}) {
479
- let t = [
480
- "defaultValue",
481
- "ordinal",
482
- "context",
483
- "replace",
484
- "lng",
485
- "lngs",
486
- "fallbackLng",
487
- "ns",
488
- "keySeparator",
489
- "nsSeparator",
490
- "returnObjects",
491
- "returnDetails",
492
- "joinArrays",
493
- "postProcess",
494
- "interpolation"
495
- ], n = e.replace && !r(e.replace), i = n ? e.replace : e;
496
- if (n && e.count !== void 0 && (i = {
497
- ...i,
498
- count: e.count
499
- }), this.options.interpolation.defaultVariables && (i = {
500
- ...this.options.interpolation.defaultVariables,
501
- ...i
502
- }), !n) {
503
- i = { ...i };
504
- for (let e of t) delete i[e];
505
- }
506
- return i;
507
- }
508
- static hasDefaultValue(e) {
509
- for (let t in e) if (Object.prototype.hasOwnProperty.call(e, t) && t.startsWith("defaultValue") && e[t] !== void 0) return !0;
510
- return !1;
511
- }
512
- }, F = class {
513
- constructor(e) {
514
- this.options = e, this.supportedLngs = this.options.supportedLngs || !1, this.logger = E.create("languageUtils"), this.resolveHierarchyCache = {};
515
- }
516
- clearCache() {
517
- this.resolveHierarchyCache = {};
518
- }
519
- getScriptPartFromCode(e) {
520
- if (e = w(e), !e || !e.includes("-")) return null;
521
- let t = e.split("-");
522
- return t.length === 2 || (t.pop(), t[t.length - 1].toLowerCase() === "x") ? null : this.formatLanguageCode(t.join("-"));
523
- }
524
- getLanguagePartFromCode(e) {
525
- if (e = w(e), !e || !e.includes("-")) return e;
526
- let t = e.split("-");
527
- return this.formatLanguageCode(t[0]);
528
- }
529
- formatLanguageCode(e) {
530
- if (r(e) && e.includes("-")) {
531
- let t;
532
- try {
533
- t = Intl.getCanonicalLocales(e)[0];
534
- } catch {}
535
- return t && this.options.lowerCaseLng && (t = t.toLowerCase()), t || (this.options.lowerCaseLng ? e.toLowerCase() : e);
536
- }
537
- return this.options.cleanCode || this.options.lowerCaseLng ? e.toLowerCase() : e;
538
- }
539
- isSupportedCode(e) {
540
- return (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) && (e = this.getLanguagePartFromCode(e)), !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.includes(e);
541
- }
542
- getBestMatchFromCodes(e) {
543
- if (!e) return null;
544
- let t;
545
- return e.forEach((e) => {
546
- if (t) return;
547
- let n = this.formatLanguageCode(e);
548
- (!this.options.supportedLngs || this.isSupportedCode(n)) && (t = n);
549
- }), !t && this.options.supportedLngs && e.forEach((e) => {
550
- if (t) return;
551
- let n = this.getScriptPartFromCode(e);
552
- if (this.isSupportedCode(n)) return t = n;
553
- let r = this.getLanguagePartFromCode(e);
554
- if (this.isSupportedCode(r)) return t = r;
555
- t = this.options.supportedLngs.find((e) => e === r ? !0 : !e.includes("-") && !r.includes("-") ? !1 : !!(e.includes("-") && !r.includes("-") && e.slice(0, e.indexOf("-")) === r || e.startsWith(r) && r.length > 1));
556
- }), t ||= this.getFallbackCodes(this.options.fallbackLng)[0], t;
557
- }
558
- getFallbackCodes(e, t) {
559
- if (!e) return [];
560
- if (typeof e == "function" && (e = e(t)), r(e) && (e = [e]), Array.isArray(e)) return e;
561
- if (!t) return e.default || [];
562
- let n = e[t];
563
- return n ||= e[this.getScriptPartFromCode(t)], n ||= e[this.formatLanguageCode(t)], n ||= e[this.getLanguagePartFromCode(t)], n ||= e.default, n || [];
564
- }
565
- toResolveHierarchy(e, t) {
566
- let n = this.options.fallbackLng, i = Array.isArray(n) ? n.join("|") : n;
567
- i !== this._cachedFallbackLng && (this.resolveHierarchyCache = {}, this._cachedFallbackLng = i);
568
- let a = t === void 0 || t === !1 || r(t), o = t === void 0 && typeof this.options.fallbackLng == "function", s = r(e) && a && !o, c = null;
569
- if (s) {
570
- let n;
571
- n = t === void 0 ? "undefined" : t === !1 ? "boolean:false" : `string:${t}`, c = `${e.length}:${e}|${n}`;
572
- }
573
- if (c !== null) {
574
- let e = this.resolveHierarchyCache[c];
575
- if (e !== void 0) return e.slice();
576
- }
577
- let l = this.getFallbackCodes((t === !1 ? [] : t) || this.options.fallbackLng || [], e), u = [], d = (e) => {
578
- e && (this.isSupportedCode(e) ? u.push(e) : this.logger.warn(`rejecting language code not found in supportedLngs: ${e}`));
579
- };
580
- return r(e) && (e.includes("-") || e.includes("_")) ? (this.options.load !== "languageOnly" && d(this.formatLanguageCode(e)), this.options.load !== "languageOnly" && this.options.load !== "currentOnly" && d(this.getScriptPartFromCode(e)), this.options.load !== "currentOnly" && d(this.getLanguagePartFromCode(e))) : r(e) && d(this.formatLanguageCode(e)), l.forEach((e) => {
581
- u.includes(e) || d(this.formatLanguageCode(e));
582
- }), c === null ? u : (this.resolveHierarchyCache[c] = u, u.slice());
583
- }
584
- }, I = {
585
- zero: 0,
586
- one: 1,
587
- two: 2,
588
- few: 3,
589
- many: 4,
590
- other: 5
591
- }, L = {
592
- select: (e) => e === 1 ? "one" : "other",
593
- resolvedOptions: () => ({ pluralCategories: ["one", "other"] })
594
- }, R = class {
595
- constructor(e, t = {}) {
596
- this.languageUtils = e, this.options = t, this.logger = E.create("pluralResolver"), this.pluralRulesCache = {};
597
- }
598
- clearCache() {
599
- this.pluralRulesCache = {};
600
- }
601
- getRule(e, t = {}) {
602
- let n = w(e === "dev" ? "en" : e), r = t.ordinal ? "ordinal" : "cardinal", i = JSON.stringify({
603
- cleanedCode: n,
604
- type: r
605
- });
606
- if (i in this.pluralRulesCache) return this.pluralRulesCache[i];
607
- let a;
608
- try {
609
- a = new Intl.PluralRules(n, { type: r });
610
- } catch {
611
- if (typeof Intl > "u") return this.logger.error("No Intl support, please use an Intl polyfill!"), L;
612
- if (!e.match(/-|_/)) return L;
613
- let n = this.languageUtils.getLanguagePartFromCode(e);
614
- a = this.getRule(n, t);
615
- }
616
- return this.pluralRulesCache[i] = a, a;
617
- }
618
- needsPlural(e, t = {}) {
619
- let n = this.getRule(e, t);
620
- return n ||= this.getRule("dev", t), n?.resolvedOptions().pluralCategories.length > 1;
621
- }
622
- getPluralFormsOfKey(e, t, n = {}) {
623
- return this.getSuffixes(e, n).map((e) => `${t}${e}`);
624
- }
625
- getSuffixes(e, t = {}) {
626
- let n = this.getRule(e, t);
627
- return n ||= this.getRule("dev", t), n ? n.resolvedOptions().pluralCategories.sort((e, t) => I[e] - I[t]).map((e) => `${this.options.prepend}${t.ordinal ? `ordinal${this.options.prepend}` : ""}${e}`) : [];
628
- }
629
- getSuffix(e, t, n = {}) {
630
- let r = this.getRule(e, n);
631
- return r ? `${this.options.prepend}${n.ordinal ? `ordinal${this.options.prepend}` : ""}${r.select(t)}` : (this.logger.warn(`no plural rule found for: ${e}`), this.getSuffix("dev", t, n));
632
- }
633
- }, z = (e, t, n, i = ".", a = !0) => {
634
- let o = m(e, t, n);
635
- return !o && a && r(n) && (o = C(e, n, i), o === void 0 && (o = C(t, n, i))), o;
636
- }, B = (e) => e.replace(/\$/g, "$$$$"), V = class {
637
- constructor(e = {}) {
638
- this.logger = E.create("interpolator"), this.options = e, this.format = e?.interpolation?.format || ((e) => e), this.init(e);
639
- }
640
- init(e = {}) {
641
- e.interpolation ||= { escapeValue: !0 };
642
- let { escape: t, escapeValue: n, useRawValueToEscape: r, prefix: i, prefixEscaped: a, suffix: o, suffixEscaped: s, formatSeparator: c, unescapeSuffix: l, unescapePrefix: u, nestingPrefix: d, nestingPrefixEscaped: f, nestingSuffix: p, nestingSuffixEscaped: m, nestingOptionsSeparator: h, maxReplaces: _, alwaysFormat: y } = e.interpolation;
643
- this.escape = t === void 0 ? v : t, this.escapeValue = n === void 0 || n, this.useRawValueToEscape = r !== void 0 && r, this.prefix = i ? g(i) : a || "{{", this.suffix = o ? g(o) : s || "}}", this.formatSeparator = c || ",", this.unescapePrefix = l ? "" : u ? g(u) : "-", this.unescapeSuffix = this.unescapePrefix ? "" : l ? g(l) : "", this.nestingPrefix = d ? g(d) : f || g("$t("), this.nestingSuffix = p ? g(p) : m || g(")"), this.nestingOptionsSeparator = h || ",", this.maxReplaces = _ || 1e3, this.alwaysFormat = y !== void 0 && y, this.resetRegExp();
644
- }
645
- reset() {
646
- this.options && this.init(this.options);
647
- }
648
- resetRegExp() {
649
- let e = (e, t) => e?.source === t ? (e.lastIndex = 0, e) : new RegExp(t, "g");
650
- this.regexp = e(this.regexp, `${this.prefix}(.+?)${this.suffix}`), this.regexpUnescape = e(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`), this.nestingRegexp = e(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
651
- }
652
- interpolate(e, t, n, i) {
653
- let o, s, c, l = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {}, u = (e) => {
654
- if (!e.includes(this.formatSeparator)) {
655
- let r = z(t, l, e, this.options.keySeparator, this.options.ignoreJSONStructure);
656
- return this.alwaysFormat ? this.format(r, void 0, n, {
657
- ...i,
658
- ...t,
659
- interpolationkey: e
660
- }) : r;
661
- }
662
- let r = e.split(this.formatSeparator), a = r.shift().trim(), o = r.join(this.formatSeparator).trim();
663
- return this.format(z(t, l, a, this.options.keySeparator, this.options.ignoreJSONStructure), o, n, {
664
- ...i,
665
- ...t,
666
- interpolationkey: a
667
- });
668
- };
669
- this.resetRegExp(), !this.escapeValue && typeof e == "string" && /\$t\([^)]*\{[^}]*\{\{/.test(e) && this.logger.warn("nesting options string contains interpolated variables with escapeValue: false — if any of those values are attacker-controlled they can inject additional nesting options (e.g. redirect lng/ns). Sanitise untrusted input before passing it to t(), or keep escapeValue: true.");
670
- let d = i?.missingInterpolationHandler || this.options.missingInterpolationHandler, f = i?.interpolation?.skipOnVariables === void 0 ? this.options.interpolation.skipOnVariables : i.interpolation.skipOnVariables;
671
- return [{
672
- regex: this.regexpUnescape,
673
- safeValue: (e) => e
674
- }, {
675
- regex: this.regexp,
676
- safeValue: (e) => this.escapeValue ? this.escape(e) : e
677
- }].forEach((t) => {
678
- for (c = 0; o = t.regex.exec(e);) {
679
- let n = o[1].trim();
680
- if (s = u(n), s === void 0) if (typeof d == "function") {
681
- let t = d(e, o, i);
682
- s = r(t) ? t : "";
683
- } else if (i && Object.prototype.hasOwnProperty.call(i, n)) s = "";
684
- else if (f) {
685
- s = o[0];
686
- continue;
687
- } else this.logger.warn(`missed to pass in variable ${n} for interpolating ${e}`), s = "";
688
- else !r(s) && !this.useRawValueToEscape && (s = a(s));
689
- let l = t.safeValue(s);
690
- if (e = e.replace(o[0], B(l)), f ? (t.regex.lastIndex += l.length, t.regex.lastIndex -= o[0].length) : t.regex.lastIndex = 0, c++, c >= this.maxReplaces) break;
691
- }
692
- }), e;
693
- }
694
- nest(e, t, n = {}) {
695
- let i, o, s, c = (e, t) => {
696
- let n = this.nestingOptionsSeparator;
697
- if (!e.includes(n)) return e;
698
- let r = e.split(RegExp(`${g(n)}[ ]*{`)), i = `{${r[1]}`;
699
- e = r[0], i = this.interpolate(i, s);
700
- let a = i.match(/'/g), o = i.match(/"/g);
701
- ((a?.length ?? 0) % 2 == 0 && !o || (o?.length ?? 0) % 2 != 0) && (i = i.replace(/'/g, "\""));
702
- try {
703
- s = JSON.parse(i), t && (s = {
704
- ...t,
705
- ...s
706
- });
707
- } catch (t) {
708
- return this.logger.warn(`failed parsing options string in nesting for key ${e}`, t), `${e}${n}${i}`;
709
- }
710
- return s.defaultValue && s.defaultValue.includes(this.prefix) && delete s.defaultValue, e;
711
- };
712
- for (; i = this.nestingRegexp.exec(e);) {
713
- let l = [];
714
- s = { ...n }, s = s.replace && !r(s.replace) ? s.replace : s, s.applyPostProcessor = !1, delete s.defaultValue;
715
- let u = /{.*}/s.test(i[1]) ? i[1].lastIndexOf("}") + 1 : i[1].indexOf(this.formatSeparator);
716
- if (u !== -1 && (l = i[1].slice(u).split(this.formatSeparator).map((e) => e.trim()).filter(Boolean), i[1] = i[1].slice(0, u)), o = t(c.call(this, i[1].trim(), s), s), o && i[0] === e && !r(o)) return o;
717
- r(o) || (o = a(o)), o ||= (this.logger.warn(`missed to resolve ${i[1]} for nesting ${e}`), ""), l.length && (o = l.reduce((e, t) => this.format(e, t, n.lng, {
718
- ...n,
719
- interpolationkey: i[1].trim()
720
- }), o.trim())), e = e.replace(i[0], B(a(o))), this.regexp.lastIndex = 0;
721
- }
722
- return e;
723
- }
724
- }, H = (e) => {
725
- let t = e.toLowerCase().trim(), n = {};
726
- if (e.includes("(")) {
727
- let r = e.split("(");
728
- t = r[0].toLowerCase().trim();
729
- let i = r[1].slice(0, -1);
730
- t === "currency" && !i.includes(":") ? n.currency ||= i.trim() : t === "relativetime" && !i.includes(":") ? n.range ||= i.trim() : i.split(";").forEach((e) => {
731
- if (e) {
732
- let [t, ...r] = e.split(":"), i = r.join(":").trim().replace(/^'+|'+$/g, ""), a = t.trim();
733
- n[a] || (n[a] = i), i === "false" && (n[a] = !1), i === "true" && (n[a] = !0), isNaN(i) || (n[a] = parseInt(i, 10));
734
- }
735
- });
736
- }
737
- return {
738
- formatName: t,
739
- formatOptions: n
740
- };
741
- }, U = (e) => {
742
- let t = {};
743
- return (n, r, i) => {
744
- let a = i;
745
- i && i.interpolationkey && i.formatParams && i.formatParams[i.interpolationkey] && i[i.interpolationkey] && (a = {
746
- ...a,
747
- [i.interpolationkey]: void 0
748
- });
749
- let o = r + JSON.stringify(a), s = t[o];
750
- return s || (s = e(w(r), i), t[o] = s), s(n);
751
- };
752
- }, W = (e) => (t, n, r) => e(w(n), r)(t), G = class {
753
- constructor(e = {}) {
754
- this.logger = E.create("formatter"), this.options = e, this.init(e);
755
- }
756
- init(e, t = { interpolation: {} }) {
757
- this.formatSeparator = t.interpolation.formatSeparator || ",";
758
- let n = t.cacheInBuiltFormats ? U : W;
759
- this.formats = {
760
- number: n((e, t) => {
761
- let n = new Intl.NumberFormat(e, { ...t });
762
- return (e) => n.format(e);
763
- }),
764
- currency: n((e, t) => {
765
- let n = new Intl.NumberFormat(e, {
766
- ...t,
767
- style: "currency"
768
- });
769
- return (e) => n.format(e);
770
- }),
771
- datetime: n((e, t) => {
772
- let n = new Intl.DateTimeFormat(e, { ...t });
773
- return (e) => n.format(e);
774
- }),
775
- relativetime: n((e, t) => {
776
- let n = new Intl.RelativeTimeFormat(e, { ...t });
777
- return (e) => n.format(e, t.range || "day");
778
- }),
779
- list: n((e, t) => {
780
- let n = new Intl.ListFormat(e, { ...t });
781
- return (e) => n.format(e);
782
- })
783
- };
784
- }
785
- add(e, t) {
786
- this.formats[e.toLowerCase().trim()] = t;
787
- }
788
- addCached(e, t) {
789
- this.formats[e.toLowerCase().trim()] = U(t);
790
- }
791
- format(e, t, n, r = {}) {
792
- if (!t || e == null) return e;
793
- let i = t.split(this.formatSeparator), a = [];
794
- for (let e = 0; e < i.length; e++) {
795
- let t = i[e];
796
- for (; t.indexOf("(") > -1 && !t.includes(")") && e + 1 < i.length;) t = `${t}${this.formatSeparator}${i[++e]}`;
797
- a.push(t);
798
- }
799
- return a.reduce((e, t) => {
800
- let { formatName: i, formatOptions: a } = H(t);
801
- if (this.formats[i]) {
802
- let t = e;
803
- try {
804
- let o = r?.formatParams?.[r.interpolationkey] || {}, s = o.locale || o.lng || r.locale || r.lng || n;
805
- t = this.formats[i](e, s, {
806
- ...a,
807
- ...r,
808
- ...o
809
- });
810
- } catch (e) {
811
- this.logger.warn(e);
812
- }
813
- return t;
814
- } else this.logger.warn(`there was no format function for ${i}`);
815
- return e;
816
- }, e);
817
- }
818
- }, K = (e, t) => {
819
- e.pending[t] !== void 0 && (delete e.pending[t], e.pendingCount--);
820
- }, q = class extends D {
821
- constructor(e, t, n, r = {}) {
822
- super(), this.backend = e, this.store = t, this.services = n, this.languageUtils = n.languageUtils, this.options = r, this.logger = E.create("backendConnector"), this.waitingReads = [], this.maxParallelReads = r.maxParallelReads || 10, this.readingCalls = 0, this.maxRetries = r.maxRetries >= 0 ? r.maxRetries : 5, this.retryTimeout = r.retryTimeout >= 1 ? r.retryTimeout : 350, this.state = {}, this.queue = [], this.backend?.init?.(n, r.backend, r);
823
- }
824
- queueLoad(e, t, n, r) {
825
- let i = {}, a = {}, o = {}, s = {};
826
- return e.forEach((e) => {
827
- let r = !0;
828
- t.forEach((t) => {
829
- let o = `${e}|${t}`;
830
- !n.reload && this.store.hasResourceBundle(e, t) ? this.state[o] = 2 : this.state[o] < 0 || (this.state[o] === 1 ? a[o] === void 0 && (a[o] = !0) : (this.state[o] = 1, r = !1, a[o] === void 0 && (a[o] = !0), i[o] === void 0 && (i[o] = !0), s[t] === void 0 && (s[t] = !0)));
831
- }), r || (o[e] = !0);
832
- }), (Object.keys(i).length || Object.keys(a).length) && this.queue.push({
833
- pending: a,
834
- pendingCount: Object.keys(a).length,
835
- loaded: {},
836
- errors: [],
837
- callback: r
838
- }), {
839
- toLoad: Object.keys(i),
840
- pending: Object.keys(a),
841
- toLoadLanguages: Object.keys(o),
842
- toLoadNamespaces: Object.keys(s)
843
- };
844
- }
845
- loaded(e, t, n) {
846
- let r = e.split("|"), i = r[0], a = r[1];
847
- t && this.emit("failedLoading", i, a, t), !t && n && this.store.addResourceBundle(i, a, n, void 0, void 0, { skipCopy: !0 }), this.state[e] = t ? -1 : 2, t && n && (this.state[e] = 0);
848
- let o = {};
849
- this.queue.forEach((n) => {
850
- f(n.loaded, [i], a), K(n, e), t && n.errors.push(t), n.pendingCount === 0 && !n.done && (Object.keys(n.loaded).forEach((e) => {
851
- o[e] || (o[e] = {});
852
- let t = n.loaded[e];
853
- t.length && t.forEach((t) => {
854
- o[e][t] === void 0 && (o[e][t] = !0);
855
- });
856
- }), n.done = !0, n.errors.length ? n.callback(n.errors) : n.callback());
857
- }), this.emit("loaded", o), this.queue = this.queue.filter((e) => !e.done);
858
- }
859
- read(e, t, n, r = 0, i = this.retryTimeout, a) {
860
- if (!e.length) return a(null, {});
861
- if (this.readingCalls >= this.maxParallelReads) {
862
- this.waitingReads.push({
863
- lng: e,
864
- ns: t,
865
- fcName: n,
866
- tried: r,
867
- wait: i,
868
- callback: a
869
- });
870
- return;
871
- }
872
- this.readingCalls++;
873
- let o = (o, s) => {
874
- if (this.readingCalls--, this.waitingReads.length > 0) {
875
- let e = this.waitingReads.shift();
876
- this.read(e.lng, e.ns, e.fcName, e.tried, e.wait, e.callback);
877
- }
878
- if (o && s && r < this.maxRetries) {
879
- setTimeout(() => {
880
- this.read(e, t, n, r + 1, i * 2, a);
881
- }, i);
882
- return;
883
- }
884
- a(o, s);
885
- }, s = this.backend[n].bind(this.backend);
886
- if (s.length === 2) {
887
- try {
888
- let n = s(e, t);
889
- n && typeof n.then == "function" ? n.then((e) => o(null, e)).catch(o) : o(null, n);
890
- } catch (e) {
891
- o(e);
892
- }
893
- return;
894
- }
895
- return s(e, t, o);
896
- }
897
- prepareLoading(e, t, n = {}, i) {
898
- if (!this.backend) return this.logger.warn("No backend was added via i18next.use. Will not load resources."), i && i();
899
- r(e) && (e = this.languageUtils.toResolveHierarchy(e)), r(t) && (t = [t]);
900
- let a = this.queueLoad(e, t, n, i);
901
- if (!a.toLoad.length) return a.pending.length || i(), null;
902
- a.toLoad.forEach((e) => {
903
- this.loadOne(e);
904
- });
905
- }
906
- load(e, t, n) {
907
- this.prepareLoading(e, t, {}, n);
908
- }
909
- reload(e, t, n) {
910
- this.prepareLoading(e, t, { reload: !0 }, n);
911
- }
912
- loadOne(e, t = "") {
913
- let n = e.split("|"), r = n[0], i = n[1];
914
- this.read(r, i, "read", void 0, void 0, (n, a) => {
915
- n && this.logger.warn(`${t}loading namespace ${i} for language ${r} failed`, n), !n && a && this.logger.log(`${t}loaded namespace ${i} for language ${r}`, a), this.loaded(e, n, a);
916
- });
917
- }
918
- saveMissing(e, t, n, r, i, a = {}, o = () => {}) {
919
- if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(t)) {
920
- this.logger.warn(`did not save key "${n}" 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!!!");
921
- return;
922
- }
923
- if (!(n == null || n === "")) {
924
- if (this.backend?.create) {
925
- let s = {
926
- ...a,
927
- isUpdate: i
928
- }, c = this.backend.create.bind(this.backend);
929
- if (c.length < 6) try {
930
- let i;
931
- i = c.length === 5 ? c(e, t, n, r, s) : c(e, t, n, r), i && typeof i.then == "function" ? i.then((e) => o(null, e)).catch(o) : o(null, i);
932
- } catch (e) {
933
- o(e);
934
- }
935
- else c(e, t, n, r, o, s);
936
- }
937
- !e || !e[0] || this.store.addResource(e[0], t, n, r);
938
- }
939
- }
940
- }, J = () => ({
941
- debug: !1,
942
- initAsync: !0,
943
- ns: ["translation"],
944
- defaultNS: ["translation"],
945
- fallbackLng: ["dev"],
946
- fallbackNS: !1,
947
- supportedLngs: !1,
948
- nonExplicitSupportedLngs: !1,
949
- load: "all",
950
- preload: !1,
951
- keySeparator: ".",
952
- nsSeparator: ":",
953
- pluralSeparator: "_",
954
- contextSeparator: "_",
955
- enableSelector: !1,
956
- partialBundledLanguages: !1,
957
- saveMissing: !1,
958
- updateMissing: !1,
959
- saveMissingTo: "fallback",
960
- saveMissingPlurals: !0,
961
- missingKeyHandler: !1,
962
- missingInterpolationHandler: !1,
963
- postProcess: !1,
964
- postProcessPassResolved: !1,
965
- returnNull: !1,
966
- returnEmptyString: !0,
967
- returnObjects: !1,
968
- joinArrays: !1,
969
- returnedObjectHandler: !1,
970
- parseMissingKeyHandler: !1,
971
- appendNamespaceToMissingKey: !1,
972
- appendNamespaceToCIMode: !1,
973
- overloadTranslationOptionHandler: (e) => {
974
- let t = {};
975
- if (typeof e[1] == "object" && (t = e[1]), r(e[1]) && (t.defaultValue = e[1]), r(e[2]) && (t.tDescription = e[2]), typeof e[2] == "object" || typeof e[3] == "object") {
976
- let n = e[3] || e[2];
977
- Object.keys(n).forEach((e) => {
978
- t[e] = n[e];
979
- });
980
- }
981
- return t;
982
- },
983
- interpolation: {
984
- escapeValue: !0,
985
- prefix: "{{",
986
- suffix: "}}",
987
- formatSeparator: ",",
988
- unescapePrefix: "-",
989
- nestingPrefix: "$t(",
990
- nestingSuffix: ")",
991
- nestingOptionsSeparator: ",",
992
- maxReplaces: 1e3,
993
- skipOnVariables: !0
994
- },
995
- cacheInBuiltFormats: !0
996
- }), Y = (e) => (r(e.ns) && (e.ns = [e.ns]), r(e.fallbackLng) && (e.fallbackLng = [e.fallbackLng]), r(e.fallbackNS) && (e.fallbackNS = [e.fallbackNS]), e.supportedLngs && !e.supportedLngs.includes("cimode") && (e.supportedLngs = e.supportedLngs.concat(["cimode"])), e), X = () => {}, Z = (e) => {
997
- Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach((t) => {
998
- typeof e[t] == "function" && (e[t] = e[t].bind(e));
999
- });
1000
- }, Q = class e extends D {
1001
- constructor(e = {}, t) {
1002
- if (super(), this.options = Y(e), this.services = {}, this.logger = E, this.modules = { external: [] }, Z(this), t && !this.isInitialized && !e.isClone) {
1003
- if (!this.options.initAsync) return this.init(e, t), this;
1004
- setTimeout(() => {
1005
- this.init(e, t);
1006
- }, 0);
1007
- }
1008
- }
1009
- init(e = {}, t) {
1010
- this.isInitializing = !0, typeof e == "function" && (t = e, e = {}), e.defaultNS == null && e.ns && (r(e.ns) ? e.defaultNS = e.ns : e.ns.includes("translation") || (e.defaultNS = e.ns[0]));
1011
- let n = J();
1012
- this.options = {
1013
- ...n,
1014
- ...this.options,
1015
- ...Y(e)
1016
- }, this.options.interpolation = {
1017
- ...n.interpolation,
1018
- ...this.options.interpolation
1019
- }, e.keySeparator !== void 0 && (this.options.userDefinedKeySeparator = e.keySeparator), e.nsSeparator !== void 0 && (this.options.userDefinedNsSeparator = e.nsSeparator), typeof this.options.overloadTranslationOptionHandler != "function" && (this.options.overloadTranslationOptionHandler = n.overloadTranslationOptionHandler);
1020
- let a = (e) => e ? typeof e == "function" ? new e() : e : null;
1021
- if (!this.options.isClone) {
1022
- this.modules.logger ? E.init(a(this.modules.logger), this.options) : E.init(null, this.options);
1023
- let e;
1024
- e = this.modules.formatter ? this.modules.formatter : G;
1025
- let t = new F(this.options);
1026
- this.store = new O(this.options.resources, this.options);
1027
- let n = this.services;
1028
- n.logger = E, n.resourceStore = this.store, n.languageUtils = t, n.pluralResolver = new R(t, { prepend: this.options.pluralSeparator }), e && (n.formatter = a(e), n.formatter.init && n.formatter.init(n, this.options), this.options.interpolation.format = n.formatter.format.bind(n.formatter)), n.interpolator = new V(this.options), n.utils = { hasLoadedNamespace: this.hasLoadedNamespace.bind(this) }, n.backendConnector = new q(a(this.modules.backend), n.resourceStore, n, this.options), n.backendConnector.on("*", (e, ...t) => {
1029
- this.emit(e, ...t);
1030
- }), this.modules.languageDetector && (n.languageDetector = a(this.modules.languageDetector), n.languageDetector.init && n.languageDetector.init(n, this.options.detection, this.options)), this.modules.i18nFormat && (n.i18nFormat = a(this.modules.i18nFormat), n.i18nFormat.init && n.i18nFormat.init(this)), this.translator = new P(this.services, this.options), this.translator.on("*", (e, ...t) => {
1031
- this.emit(e, ...t);
1032
- }), this.modules.external.forEach((e) => {
1033
- e.init && e.init(this);
1034
- });
1035
- }
1036
- if (this.format = this.options.interpolation.format, t ||= X, this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
1037
- let e = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1038
- e.length > 0 && e[0] !== "dev" && (this.options.lng = e[0]);
1039
- }
1040
- !this.services.languageDetector && !this.options.lng && this.logger.warn("init: no languageDetector is used and no lng is defined"), [
1041
- "getResource",
1042
- "hasResourceBundle",
1043
- "getResourceBundle",
1044
- "getDataByLanguage"
1045
- ].forEach((e) => {
1046
- this[e] = (...t) => this.store[e](...t);
1047
- }), [
1048
- "addResource",
1049
- "addResources",
1050
- "addResourceBundle",
1051
- "removeResourceBundle"
1052
- ].forEach((e) => {
1053
- this[e] = (...t) => (this.store[e](...t), this);
1054
- });
1055
- let o = i(), s = () => {
1056
- let e = (e, n) => {
1057
- 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), o.resolve(n), t(e, n);
1058
- };
1059
- if ((this.languages || this.isLanguageChangingTo) && !this.isInitialized) return e(null, this.t.bind(this));
1060
- this.changeLanguage(this.options.lng, e);
1061
- };
1062
- return this.options.resources || !this.options.initAsync ? s() : setTimeout(s, 0), o;
1063
- }
1064
- loadResources(e, t = X) {
1065
- let n = t, i = r(e) ? e : this.language;
1066
- if (typeof e == "function" && (n = e), !this.options.resources || this.options.partialBundledLanguages) {
1067
- if (i?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return n();
1068
- let e = [], t = (t) => {
1069
- t && t !== "cimode" && this.services.languageUtils.toResolveHierarchy(t).forEach((t) => {
1070
- t !== "cimode" && (e.includes(t) || e.push(t));
1071
- });
1072
- };
1073
- i ? t(i) : this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach((e) => t(e)), this.options.preload?.forEach?.((e) => t(e)), this.services.backendConnector.load(e, this.options.ns, (e) => {
1074
- !e && !this.resolvedLanguage && this.language && this.setResolvedLanguage(this.language), n(e);
1075
- });
1076
- } else n(null);
1077
- }
1078
- reloadResources(e, t, n) {
1079
- let r = i();
1080
- return typeof e == "function" && (n = e, e = void 0), typeof t == "function" && (n = t, t = void 0), e ||= this.languages, t ||= this.options.ns, n ||= X, this.services.backendConnector.reload(e, t, (e) => {
1081
- r.resolve(), n(e);
1082
- }), r;
1083
- }
1084
- use(e) {
1085
- if (!e) throw Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
1086
- if (!e.type) throw Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
1087
- 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" && k.addPostProcessor(e), e.type === "formatter" && (this.modules.formatter = e), e.type === "3rdParty" && this.modules.external.push(e), this;
1088
- }
1089
- setResolvedLanguage(e) {
1090
- if (!(!e || !this.languages) && !["cimode", "dev"].includes(e)) {
1091
- for (let e = 0; e < this.languages.length; e++) {
1092
- let t = this.languages[e];
1093
- if (!["cimode", "dev"].includes(t) && this.store.hasLanguageSomeTranslations(t)) {
1094
- this.resolvedLanguage = t;
1095
- break;
1096
- }
1097
- }
1098
- !this.resolvedLanguage && !this.languages.includes(e) && this.store.hasLanguageSomeTranslations(e) && (this.resolvedLanguage = e, this.languages.unshift(e));
1099
- }
1100
- }
1101
- changeLanguage(e, t) {
1102
- this.isLanguageChangingTo = e;
1103
- let n = i();
1104
- this.emit("languageChanging", e);
1105
- let a = (e) => {
1106
- this.language = e, this.languages = this.services.languageUtils.toResolveHierarchy(e), this.resolvedLanguage = void 0, this.setResolvedLanguage(e);
1107
- }, o = (r, i) => {
1108
- i ? this.isLanguageChangingTo === e && (a(i), this.translator.changeLanguage(i), this.isLanguageChangingTo = void 0, this.emit("languageChanged", i), this.logger.log("languageChanged", i)) : this.isLanguageChangingTo = void 0, n.resolve((...e) => this.t(...e)), t && t(r, (...e) => this.t(...e));
1109
- }, s = (t) => {
1110
- !e && !t && this.services.languageDetector && (t = []);
1111
- let n = r(t) ? t : t && t[0], i = this.store.hasLanguageSomeTranslations(n) ? n : this.services.languageUtils.getBestMatchFromCodes(r(t) ? [t] : t);
1112
- i && (this.language || a(i), this.translator.language || this.translator.changeLanguage(i), this.services.languageDetector?.cacheUserLanguage?.(i)), this.loadResources(i, (e) => {
1113
- o(e, i);
1114
- });
1115
- };
1116
- return !e && this.services.languageDetector && !this.services.languageDetector.async ? s(this.services.languageDetector.detect()) : !e && this.services.languageDetector && this.services.languageDetector.async ? this.services.languageDetector.detect.length === 0 ? this.services.languageDetector.detect().then(s) : this.services.languageDetector.detect(s) : s(e), n;
1117
- }
1118
- getFixedT(e, t, n, i) {
1119
- let a = i?.scopeNs, o = (e, t, ...r) => {
1120
- let i;
1121
- i = typeof t == "object" ? { ...t } : this.options.overloadTranslationOptionHandler([e, t].concat(r)), i.lng = i.lng || o.lng, i.lngs = i.lngs || o.lngs;
1122
- let s = i.ns !== void 0 && i.ns !== null;
1123
- i.ns = i.ns || o.ns, i.keyPrefix !== "" && (i.keyPrefix = i.keyPrefix || n || o.keyPrefix);
1124
- let c = {
1125
- ...this.options,
1126
- ...i
1127
- };
1128
- Array.isArray(a) && !s && (c.ns = a), typeof i.keyPrefix == "function" && (i.keyPrefix = M(i.keyPrefix, c));
1129
- let l = this.options.keySeparator || ".", u;
1130
- return i.keyPrefix && Array.isArray(e) ? u = e.map((e) => (typeof e == "function" && (e = M(e, c)), `${i.keyPrefix}${l}${e}`)) : (typeof e == "function" && (e = M(e, c)), u = i.keyPrefix ? `${i.keyPrefix}${l}${e}` : e), this.t(u, i);
1131
- };
1132
- return r(e) ? o.lng = e : o.lngs = e, o.ns = t, o.keyPrefix = n, o;
1133
- }
1134
- t(...e) {
1135
- return this.translator?.translate(...e);
1136
- }
1137
- exists(...e) {
1138
- return this.translator?.exists(...e);
1139
- }
1140
- setDefaultNamespace(e) {
1141
- this.options.defaultNS = e;
1142
- }
1143
- hasLoadedNamespace(e, t = {}) {
1144
- if (!this.isInitialized) return this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages), !1;
1145
- if (!this.languages || !this.languages.length) return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages), !1;
1146
- let n = t.lng || this.resolvedLanguage || this.languages[0], r = this.options ? this.options.fallbackLng : !1, i = this.languages[this.languages.length - 1];
1147
- if (n.toLowerCase() === "cimode") return !0;
1148
- let a = (e, t) => {
1149
- let n = this.services.backendConnector.state[`${e}|${t}`];
1150
- return n === -1 || n === 0 || n === 2;
1151
- };
1152
- if (t.precheck) {
1153
- let e = t.precheck(this, a);
1154
- if (e !== void 0) return e;
1155
- }
1156
- return !!(this.hasResourceBundle(n, e) || !this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages || a(n, e) && (!r || a(i, e)));
1157
- }
1158
- loadNamespaces(e, t) {
1159
- let n = i();
1160
- return this.options.ns ? (r(e) && (e = [e]), e.forEach((e) => {
1161
- this.options.ns.includes(e) || this.options.ns.push(e);
1162
- }), this.loadResources((e) => {
1163
- n.resolve(), t && t(e);
1164
- }), n) : (t && t(), Promise.resolve());
1165
- }
1166
- loadLanguages(e, t) {
1167
- let n = i();
1168
- r(e) && (e = [e]);
1169
- let a = this.options.preload || [], o = e.filter((e) => !a.includes(e) && this.services.languageUtils.isSupportedCode(e));
1170
- return o.length ? (this.options.preload = a.concat(o), this.loadResources((e) => {
1171
- n.resolve(), t && t(e);
1172
- }), n) : (t && t(), Promise.resolve());
1173
- }
1174
- dir(e) {
1175
- if (e ||= this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language), !e) return "rtl";
1176
- try {
1177
- let t = new Intl.Locale(e);
1178
- if (t && t.getTextInfo) {
1179
- let e = t.getTextInfo();
1180
- if (e && e.direction) return e.direction;
1181
- }
1182
- } catch {}
1183
- let t = /* @__PURE__ */ "ar.shu.sqr.ssh.xaa.yhd.yud.aao.abh.abv.acm.acq.acw.acx.acy.adf.ads.aeb.aec.afb.ajp.apc.apd.arb.arq.ars.ary.arz.auz.avl.ayh.ayl.ayn.ayp.bbz.pga.he.iw.ps.pbt.pbu.pst.prp.prd.ug.ur.ydd.yds.yih.ji.yi.hbo.men.xmn.fa.jpr.peo.pes.prs.dv.sam.ckb".split("."), n = this.services?.languageUtils || new F(J());
1184
- return e.toLowerCase().indexOf("-latn") > 1 ? "ltr" : t.includes(n.getLanguagePartFromCode(e)) || e.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
1185
- }
1186
- static createInstance(t = {}, n) {
1187
- let r = new e(t, n);
1188
- return r.createInstance = e.createInstance, r;
1189
- }
1190
- cloneInstance(t = {}, n = X) {
1191
- let r = t.forkResourceStore;
1192
- r && delete t.forkResourceStore;
1193
- let i = {
1194
- ...this.options,
1195
- ...t,
1196
- isClone: !0
1197
- }, a = new e(i);
1198
- if ((t.debug !== void 0 || t.prefix !== void 0) && (a.logger = a.logger.clone(t)), [
1199
- "store",
1200
- "services",
1201
- "language"
1202
- ].forEach((e) => {
1203
- a[e] = this[e];
1204
- }), a.services = { ...this.services }, a.services.utils = { hasLoadedNamespace: a.hasLoadedNamespace.bind(a) }, r && (a.store = new O(Object.keys(this.store.data).reduce((e, t) => (e[t] = { ...this.store.data[t] }, e[t] = Object.keys(e[t]).reduce((n, r) => (n[r] = { ...e[t][r] }, n), e[t]), e), {}), i), a.services.resourceStore = a.store), t.interpolation) {
1205
- let e = {
1206
- ...J().interpolation,
1207
- ...this.options.interpolation,
1208
- ...t.interpolation
1209
- }, n = {
1210
- ...i,
1211
- interpolation: e
1212
- };
1213
- a.services.interpolator = new V(n);
1214
- }
1215
- return a.translator = new P(a.services, i), a.translator.on("*", (e, ...t) => {
1216
- a.emit(e, ...t);
1217
- }), a.init(i, n), a.translator.options = i, a.translator.backendConnector.services.utils = { hasLoadedNamespace: a.hasLoadedNamespace.bind(a) }, a;
1218
- }
1219
- toJSON() {
1220
- return {
1221
- options: this.options,
1222
- store: this.store,
1223
- language: this.language,
1224
- languages: this.languages,
1225
- resolvedLanguage: this.resolvedLanguage
1226
- };
1227
- }
1228
- }.createInstance();
1229
- Q.createInstance, Q.dir, Q.init, Q.loadResources, Q.reloadResources, Q.use, Q.changeLanguage, Q.getFixedT, Q.t, Q.exists, Q.setDefaultNamespace, Q.hasLoadedNamespace, Q.loadNamespaces, Q.loadLanguages;
1230
- //#endregion
1231
- export { n, Q as t };