@deriv-com/translations 1.4.2 → 1.4.3

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