wcz-test 6.24.3 → 6.24.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/chunks/{DialogsHooks-DOT0O_b4.js → DialogsHooks-DVnj8xmz.js} +178 -3
  2. package/dist/chunks/DialogsHooks-DVnj8xmz.js.map +1 -0
  3. package/dist/chunks/FileHooks-GprjzNKW.js +3554 -0
  4. package/dist/chunks/FileHooks-GprjzNKW.js.map +1 -0
  5. package/dist/chunks/RouterListItemButton-BvsZysDL.js +959 -0
  6. package/dist/chunks/RouterListItemButton-BvsZysDL.js.map +1 -0
  7. package/dist/chunks/_commonjsHelpers-BGn2FbsY.js +35 -0
  8. package/dist/chunks/_commonjsHelpers-BGn2FbsY.js.map +1 -0
  9. package/dist/chunks/env-Di2sjb5X.js +104 -0
  10. package/dist/chunks/env-Di2sjb5X.js.map +1 -0
  11. package/dist/chunks/i18next-Dx0Bahhj.js +2203 -0
  12. package/dist/chunks/i18next-Dx0Bahhj.js.map +1 -0
  13. package/dist/chunks/index-BrFiyyyk.js +327 -0
  14. package/dist/chunks/index-BrFiyyyk.js.map +1 -0
  15. package/dist/chunks/session-CPSUX_HJ.js +12970 -0
  16. package/dist/chunks/session-CPSUX_HJ.js.map +1 -0
  17. package/dist/chunks/useTranslation-D7I_DXWv.js +406 -0
  18. package/dist/chunks/useTranslation-D7I_DXWv.js.map +1 -0
  19. package/dist/chunks/utils-DtlCJSvY.js +2582 -0
  20. package/dist/chunks/utils-DtlCJSvY.js.map +1 -0
  21. package/dist/client.js +4 -4
  22. package/dist/components.js +2418 -7
  23. package/dist/components.js.map +1 -1
  24. package/dist/hooks.js +1011 -5
  25. package/dist/hooks.js.map +1 -1
  26. package/dist/index.js +448 -951
  27. package/dist/index.js.map +1 -1
  28. package/dist/queries.js +3 -3
  29. package/dist/server.js +5213 -4
  30. package/dist/server.js.map +1 -1
  31. package/dist/utils.js +5 -5
  32. package/package.json +1 -1
  33. package/dist/chunks/DialogsHooks-DOT0O_b4.js.map +0 -1
  34. package/dist/chunks/FileHooks-CF1bPDoe.js +0 -493
  35. package/dist/chunks/FileHooks-CF1bPDoe.js.map +0 -1
  36. package/dist/chunks/RouterListItemButton-DTYXk1kh.js +0 -35
  37. package/dist/chunks/RouterListItemButton-DTYXk1kh.js.map +0 -1
  38. package/dist/chunks/env-gsqZ6zZD.js +0 -30
  39. package/dist/chunks/env-gsqZ6zZD.js.map +0 -1
  40. package/dist/chunks/session-vW7WZadj.js +0 -91
  41. package/dist/chunks/session-vW7WZadj.js.map +0 -1
  42. package/dist/chunks/utils-MD9YwOtu.js +0 -91
  43. package/dist/chunks/utils-MD9YwOtu.js.map +0 -1
@@ -0,0 +1,2203 @@
1
+ const isString = (obj) => typeof obj === "string";
2
+ const defer = () => {
3
+ let res;
4
+ let rej;
5
+ const promise = new Promise((resolve, reject) => {
6
+ res = resolve;
7
+ rej = reject;
8
+ });
9
+ promise.resolve = res;
10
+ promise.reject = rej;
11
+ return promise;
12
+ };
13
+ const makeString = (object) => {
14
+ if (object == null) return "";
15
+ return "" + object;
16
+ };
17
+ const copy = (a, s, t2) => {
18
+ a.forEach((m) => {
19
+ if (s[m]) t2[m] = s[m];
20
+ });
21
+ };
22
+ const lastOfPathSeparatorRegExp = /###/g;
23
+ const cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
24
+ const canNotTraverseDeeper = (object) => !object || isString(object);
25
+ const getLastOfPath = (object, path, Empty) => {
26
+ const stack = !isString(path) ? path : path.split(".");
27
+ let stackIndex = 0;
28
+ while (stackIndex < stack.length - 1) {
29
+ if (canNotTraverseDeeper(object)) return {};
30
+ const key = cleanKey(stack[stackIndex]);
31
+ if (!object[key] && Empty) object[key] = new Empty();
32
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
33
+ object = object[key];
34
+ } else {
35
+ object = {};
36
+ }
37
+ ++stackIndex;
38
+ }
39
+ if (canNotTraverseDeeper(object)) return {};
40
+ return {
41
+ obj: object,
42
+ k: cleanKey(stack[stackIndex])
43
+ };
44
+ };
45
+ const setPath = (object, path, newValue) => {
46
+ const {
47
+ obj,
48
+ k
49
+ } = getLastOfPath(object, path, Object);
50
+ if (obj !== void 0 || path.length === 1) {
51
+ obj[k] = newValue;
52
+ return;
53
+ }
54
+ let e = path[path.length - 1];
55
+ let p = path.slice(0, path.length - 1);
56
+ let last = getLastOfPath(object, p, Object);
57
+ while (last.obj === void 0 && p.length) {
58
+ e = `${p[p.length - 1]}.${e}`;
59
+ p = p.slice(0, p.length - 1);
60
+ last = getLastOfPath(object, p, Object);
61
+ if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
62
+ last.obj = void 0;
63
+ }
64
+ }
65
+ last.obj[`${last.k}.${e}`] = newValue;
66
+ };
67
+ const pushPath = (object, path, newValue, concat) => {
68
+ const {
69
+ obj,
70
+ k
71
+ } = getLastOfPath(object, path, Object);
72
+ obj[k] = obj[k] || [];
73
+ obj[k].push(newValue);
74
+ };
75
+ const getPath = (object, path) => {
76
+ const {
77
+ obj,
78
+ k
79
+ } = getLastOfPath(object, path);
80
+ if (!obj) return void 0;
81
+ if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
82
+ return obj[k];
83
+ };
84
+ const getPathWithDefaults = (data, defaultData, key) => {
85
+ const value = getPath(data, key);
86
+ if (value !== void 0) {
87
+ return value;
88
+ }
89
+ return getPath(defaultData, key);
90
+ };
91
+ const deepExtend = (target, source, overwrite) => {
92
+ for (const prop in source) {
93
+ if (prop !== "__proto__" && prop !== "constructor") {
94
+ if (prop in target) {
95
+ if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
96
+ if (overwrite) target[prop] = source[prop];
97
+ } else {
98
+ deepExtend(target[prop], source[prop], overwrite);
99
+ }
100
+ } else {
101
+ target[prop] = source[prop];
102
+ }
103
+ }
104
+ }
105
+ return target;
106
+ };
107
+ const regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
108
+ var _entityMap = {
109
+ "&": "&amp;",
110
+ "<": "&lt;",
111
+ ">": "&gt;",
112
+ '"': "&quot;",
113
+ "'": "&#39;",
114
+ "/": "&#x2F;"
115
+ };
116
+ const escape = (data) => {
117
+ if (isString(data)) {
118
+ return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
119
+ }
120
+ return data;
121
+ };
122
+ class RegExpCache {
123
+ constructor(capacity) {
124
+ this.capacity = capacity;
125
+ this.regExpMap = /* @__PURE__ */ new Map();
126
+ this.regExpQueue = [];
127
+ }
128
+ getRegExp(pattern) {
129
+ const regExpFromCache = this.regExpMap.get(pattern);
130
+ if (regExpFromCache !== void 0) {
131
+ return regExpFromCache;
132
+ }
133
+ const regExpNew = new RegExp(pattern);
134
+ if (this.regExpQueue.length === this.capacity) {
135
+ this.regExpMap.delete(this.regExpQueue.shift());
136
+ }
137
+ this.regExpMap.set(pattern, regExpNew);
138
+ this.regExpQueue.push(pattern);
139
+ return regExpNew;
140
+ }
141
+ }
142
+ const chars = [" ", ",", "?", "!", ";"];
143
+ const looksLikeObjectPathRegExpCache = new RegExpCache(20);
144
+ const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
145
+ nsSeparator = nsSeparator || "";
146
+ keySeparator = keySeparator || "";
147
+ const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
148
+ if (possibleChars.length === 0) return true;
149
+ const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
150
+ let matched = !r.test(key);
151
+ if (!matched) {
152
+ const ki = key.indexOf(keySeparator);
153
+ if (ki > 0 && !r.test(key.substring(0, ki))) {
154
+ matched = true;
155
+ }
156
+ }
157
+ return matched;
158
+ };
159
+ const deepFind = (obj, path, keySeparator = ".") => {
160
+ if (!obj) return void 0;
161
+ if (obj[path]) {
162
+ if (!Object.prototype.hasOwnProperty.call(obj, path)) return void 0;
163
+ return obj[path];
164
+ }
165
+ const tokens = path.split(keySeparator);
166
+ let current = obj;
167
+ for (let i = 0; i < tokens.length; ) {
168
+ if (!current || typeof current !== "object") {
169
+ return void 0;
170
+ }
171
+ let next;
172
+ let nextPath = "";
173
+ for (let j = i; j < tokens.length; ++j) {
174
+ if (j !== i) {
175
+ nextPath += keySeparator;
176
+ }
177
+ nextPath += tokens[j];
178
+ next = current[nextPath];
179
+ if (next !== void 0) {
180
+ if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
181
+ continue;
182
+ }
183
+ i += j - i + 1;
184
+ break;
185
+ }
186
+ }
187
+ current = next;
188
+ }
189
+ return current;
190
+ };
191
+ const getCleanedCode = (code) => code?.replace("_", "-");
192
+ const consoleLogger = {
193
+ type: "logger",
194
+ log(args) {
195
+ this.output("log", args);
196
+ },
197
+ warn(args) {
198
+ this.output("warn", args);
199
+ },
200
+ error(args) {
201
+ this.output("error", args);
202
+ },
203
+ output(type, args) {
204
+ console?.[type]?.apply?.(console, args);
205
+ }
206
+ };
207
+ class Logger {
208
+ constructor(concreteLogger, options = {}) {
209
+ this.init(concreteLogger, options);
210
+ }
211
+ init(concreteLogger, options = {}) {
212
+ this.prefix = options.prefix || "i18next:";
213
+ this.logger = concreteLogger || consoleLogger;
214
+ this.options = options;
215
+ this.debug = options.debug;
216
+ }
217
+ log(...args) {
218
+ return this.forward(args, "log", "", true);
219
+ }
220
+ warn(...args) {
221
+ return this.forward(args, "warn", "", true);
222
+ }
223
+ error(...args) {
224
+ return this.forward(args, "error", "");
225
+ }
226
+ deprecate(...args) {
227
+ return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
228
+ }
229
+ forward(args, lvl, prefix, debugOnly) {
230
+ if (debugOnly && !this.debug) return null;
231
+ if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
232
+ return this.logger[lvl](args);
233
+ }
234
+ create(moduleName) {
235
+ return new Logger(this.logger, {
236
+ ...{
237
+ prefix: `${this.prefix}:${moduleName}:`
238
+ },
239
+ ...this.options
240
+ });
241
+ }
242
+ clone(options) {
243
+ options = options || this.options;
244
+ options.prefix = options.prefix || this.prefix;
245
+ return new Logger(this.logger, options);
246
+ }
247
+ }
248
+ var baseLogger = new Logger();
249
+ class EventEmitter {
250
+ constructor() {
251
+ this.observers = {};
252
+ }
253
+ on(events, listener) {
254
+ events.split(" ").forEach((event) => {
255
+ if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
256
+ const numListeners = this.observers[event].get(listener) || 0;
257
+ this.observers[event].set(listener, numListeners + 1);
258
+ });
259
+ return this;
260
+ }
261
+ off(event, listener) {
262
+ if (!this.observers[event]) return;
263
+ if (!listener) {
264
+ delete this.observers[event];
265
+ return;
266
+ }
267
+ this.observers[event].delete(listener);
268
+ }
269
+ emit(event, ...args) {
270
+ if (this.observers[event]) {
271
+ const cloned = Array.from(this.observers[event].entries());
272
+ cloned.forEach(([observer, numTimesAdded]) => {
273
+ for (let i = 0; i < numTimesAdded; i++) {
274
+ observer(...args);
275
+ }
276
+ });
277
+ }
278
+ if (this.observers["*"]) {
279
+ const cloned = Array.from(this.observers["*"].entries());
280
+ cloned.forEach(([observer, numTimesAdded]) => {
281
+ for (let i = 0; i < numTimesAdded; i++) {
282
+ observer.apply(observer, [event, ...args]);
283
+ }
284
+ });
285
+ }
286
+ }
287
+ }
288
+ class ResourceStore extends EventEmitter {
289
+ constructor(data, options = {
290
+ ns: ["translation"],
291
+ defaultNS: "translation"
292
+ }) {
293
+ super();
294
+ this.data = data || {};
295
+ this.options = options;
296
+ if (this.options.keySeparator === void 0) {
297
+ this.options.keySeparator = ".";
298
+ }
299
+ if (this.options.ignoreJSONStructure === void 0) {
300
+ this.options.ignoreJSONStructure = true;
301
+ }
302
+ }
303
+ addNamespaces(ns) {
304
+ if (this.options.ns.indexOf(ns) < 0) {
305
+ this.options.ns.push(ns);
306
+ }
307
+ }
308
+ removeNamespaces(ns) {
309
+ const index = this.options.ns.indexOf(ns);
310
+ if (index > -1) {
311
+ this.options.ns.splice(index, 1);
312
+ }
313
+ }
314
+ getResource(lng, ns, key, options = {}) {
315
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
316
+ const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
317
+ let path;
318
+ if (lng.indexOf(".") > -1) {
319
+ path = lng.split(".");
320
+ } else {
321
+ path = [lng, ns];
322
+ if (key) {
323
+ if (Array.isArray(key)) {
324
+ path.push(...key);
325
+ } else if (isString(key) && keySeparator) {
326
+ path.push(...key.split(keySeparator));
327
+ } else {
328
+ path.push(key);
329
+ }
330
+ }
331
+ }
332
+ const result = getPath(this.data, path);
333
+ if (!result && !ns && !key && lng.indexOf(".") > -1) {
334
+ lng = path[0];
335
+ ns = path[1];
336
+ key = path.slice(2).join(".");
337
+ }
338
+ if (result || !ignoreJSONStructure || !isString(key)) return result;
339
+ return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
340
+ }
341
+ addResource(lng, ns, key, value, options = {
342
+ silent: false
343
+ }) {
344
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
345
+ let path = [lng, ns];
346
+ if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
347
+ if (lng.indexOf(".") > -1) {
348
+ path = lng.split(".");
349
+ value = ns;
350
+ ns = path[1];
351
+ }
352
+ this.addNamespaces(ns);
353
+ setPath(this.data, path, value);
354
+ if (!options.silent) this.emit("added", lng, ns, key, value);
355
+ }
356
+ addResources(lng, ns, resources, options = {
357
+ silent: false
358
+ }) {
359
+ for (const m in resources) {
360
+ if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
361
+ silent: true
362
+ });
363
+ }
364
+ if (!options.silent) this.emit("added", lng, ns, resources);
365
+ }
366
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
367
+ silent: false,
368
+ skipCopy: false
369
+ }) {
370
+ let path = [lng, ns];
371
+ if (lng.indexOf(".") > -1) {
372
+ path = lng.split(".");
373
+ deep = resources;
374
+ resources = ns;
375
+ ns = path[1];
376
+ }
377
+ this.addNamespaces(ns);
378
+ let pack = getPath(this.data, path) || {};
379
+ if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
380
+ if (deep) {
381
+ deepExtend(pack, resources, overwrite);
382
+ } else {
383
+ pack = {
384
+ ...pack,
385
+ ...resources
386
+ };
387
+ }
388
+ setPath(this.data, path, pack);
389
+ if (!options.silent) this.emit("added", lng, ns, resources);
390
+ }
391
+ removeResourceBundle(lng, ns) {
392
+ if (this.hasResourceBundle(lng, ns)) {
393
+ delete this.data[lng][ns];
394
+ }
395
+ this.removeNamespaces(ns);
396
+ this.emit("removed", lng, ns);
397
+ }
398
+ hasResourceBundle(lng, ns) {
399
+ return this.getResource(lng, ns) !== void 0;
400
+ }
401
+ getResourceBundle(lng, ns) {
402
+ if (!ns) ns = this.options.defaultNS;
403
+ return this.getResource(lng, ns);
404
+ }
405
+ getDataByLanguage(lng) {
406
+ return this.data[lng];
407
+ }
408
+ hasLanguageSomeTranslations(lng) {
409
+ const data = this.getDataByLanguage(lng);
410
+ const n = data && Object.keys(data) || [];
411
+ return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
412
+ }
413
+ toJSON() {
414
+ return this.data;
415
+ }
416
+ }
417
+ var postProcessor = {
418
+ processors: {},
419
+ addPostProcessor(module) {
420
+ this.processors[module.name] = module;
421
+ },
422
+ handle(processors, value, key, options, translator) {
423
+ processors.forEach((processor) => {
424
+ value = this.processors[processor]?.process(value, key, options, translator) ?? value;
425
+ });
426
+ return value;
427
+ }
428
+ };
429
+ const PATH_KEY = /* @__PURE__ */ Symbol("i18next/PATH_KEY");
430
+ function createProxy() {
431
+ const state = [];
432
+ const handler = /* @__PURE__ */ Object.create(null);
433
+ let proxy;
434
+ handler.get = (target, key) => {
435
+ proxy?.revoke?.();
436
+ if (key === PATH_KEY) return state;
437
+ state.push(key);
438
+ proxy = Proxy.revocable(target, handler);
439
+ return proxy.proxy;
440
+ };
441
+ return Proxy.revocable(/* @__PURE__ */ Object.create(null), handler).proxy;
442
+ }
443
+ function keysFromSelector(selector, opts) {
444
+ const {
445
+ [PATH_KEY]: path
446
+ } = selector(createProxy());
447
+ return path.join(opts?.keySeparator ?? ".");
448
+ }
449
+ const checkedLoadedFor = {};
450
+ const shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
451
+ class Translator extends EventEmitter {
452
+ constructor(services, options = {}) {
453
+ super();
454
+ copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
455
+ this.options = options;
456
+ if (this.options.keySeparator === void 0) {
457
+ this.options.keySeparator = ".";
458
+ }
459
+ this.logger = baseLogger.create("translator");
460
+ }
461
+ changeLanguage(lng) {
462
+ if (lng) this.language = lng;
463
+ }
464
+ exists(key, o = {
465
+ interpolation: {}
466
+ }) {
467
+ const opt = {
468
+ ...o
469
+ };
470
+ if (key == null) return false;
471
+ const resolved = this.resolve(key, opt);
472
+ if (resolved?.res === void 0) return false;
473
+ const isObject = shouldHandleAsObject(resolved.res);
474
+ if (opt.returnObjects === false && isObject) {
475
+ return false;
476
+ }
477
+ return true;
478
+ }
479
+ extractFromKey(key, opt) {
480
+ let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
481
+ if (nsSeparator === void 0) nsSeparator = ":";
482
+ const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
483
+ let namespaces = opt.ns || this.options.defaultNS || [];
484
+ const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
485
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
486
+ if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
487
+ const m = key.match(this.interpolator.nestingRegexp);
488
+ if (m && m.length > 0) {
489
+ return {
490
+ key,
491
+ namespaces: isString(namespaces) ? [namespaces] : namespaces
492
+ };
493
+ }
494
+ const parts = key.split(nsSeparator);
495
+ if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
496
+ key = parts.join(keySeparator);
497
+ }
498
+ return {
499
+ key,
500
+ namespaces: isString(namespaces) ? [namespaces] : namespaces
501
+ };
502
+ }
503
+ translate(keys, o, lastKey) {
504
+ let opt = typeof o === "object" ? {
505
+ ...o
506
+ } : o;
507
+ if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) {
508
+ opt = this.options.overloadTranslationOptionHandler(arguments);
509
+ }
510
+ if (typeof opt === "object") opt = {
511
+ ...opt
512
+ };
513
+ if (!opt) opt = {};
514
+ if (keys == null) return "";
515
+ if (typeof keys === "function") keys = keysFromSelector(keys, {
516
+ ...this.options,
517
+ ...opt
518
+ });
519
+ if (!Array.isArray(keys)) keys = [String(keys)];
520
+ const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
521
+ const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
522
+ const {
523
+ key,
524
+ namespaces
525
+ } = this.extractFromKey(keys[keys.length - 1], opt);
526
+ const namespace = namespaces[namespaces.length - 1];
527
+ let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
528
+ if (nsSeparator === void 0) nsSeparator = ":";
529
+ const lng = opt.lng || this.language;
530
+ const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
531
+ if (lng?.toLowerCase() === "cimode") {
532
+ if (appendNamespaceToCIMode) {
533
+ if (returnDetails) {
534
+ return {
535
+ res: `${namespace}${nsSeparator}${key}`,
536
+ usedKey: key,
537
+ exactUsedKey: key,
538
+ usedLng: lng,
539
+ usedNS: namespace,
540
+ usedParams: this.getUsedParamsDetails(opt)
541
+ };
542
+ }
543
+ return `${namespace}${nsSeparator}${key}`;
544
+ }
545
+ if (returnDetails) {
546
+ return {
547
+ res: key,
548
+ usedKey: key,
549
+ exactUsedKey: key,
550
+ usedLng: lng,
551
+ usedNS: namespace,
552
+ usedParams: this.getUsedParamsDetails(opt)
553
+ };
554
+ }
555
+ return key;
556
+ }
557
+ const resolved = this.resolve(keys, opt);
558
+ let res = resolved?.res;
559
+ const resUsedKey = resolved?.usedKey || key;
560
+ const resExactUsedKey = resolved?.exactUsedKey || key;
561
+ const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
562
+ const joinArrays = opt.joinArrays !== void 0 ? opt.joinArrays : this.options.joinArrays;
563
+ const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
564
+ const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
565
+ const hasDefaultValue = Translator.hasDefaultValue(opt);
566
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
567
+ const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
568
+ ordinal: false
569
+ }) : "";
570
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
571
+ const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
572
+ let resForObjHndl = res;
573
+ if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
574
+ resForObjHndl = defaultValue;
575
+ }
576
+ const handleAsObject = shouldHandleAsObject(resForObjHndl);
577
+ const resType = Object.prototype.toString.apply(resForObjHndl);
578
+ if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
579
+ if (!opt.returnObjects && !this.options.returnObjects) {
580
+ if (!this.options.returnedObjectHandler) {
581
+ this.logger.warn("accessing an object - but returnObjects options is not enabled!");
582
+ }
583
+ const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
584
+ ...opt,
585
+ ns: namespaces
586
+ }) : `key '${key} (${this.language})' returned an object instead of string.`;
587
+ if (returnDetails) {
588
+ resolved.res = r;
589
+ resolved.usedParams = this.getUsedParamsDetails(opt);
590
+ return resolved;
591
+ }
592
+ return r;
593
+ }
594
+ if (keySeparator) {
595
+ const resTypeIsArray = Array.isArray(resForObjHndl);
596
+ const copy2 = resTypeIsArray ? [] : {};
597
+ const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
598
+ for (const m in resForObjHndl) {
599
+ if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
600
+ const deepKey = `${newKeyToUse}${keySeparator}${m}`;
601
+ if (hasDefaultValue && !res) {
602
+ copy2[m] = this.translate(deepKey, {
603
+ ...opt,
604
+ defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
605
+ ...{
606
+ joinArrays: false,
607
+ ns: namespaces
608
+ }
609
+ });
610
+ } else {
611
+ copy2[m] = this.translate(deepKey, {
612
+ ...opt,
613
+ ...{
614
+ joinArrays: false,
615
+ ns: namespaces
616
+ }
617
+ });
618
+ }
619
+ if (copy2[m] === deepKey) copy2[m] = resForObjHndl[m];
620
+ }
621
+ }
622
+ res = copy2;
623
+ }
624
+ } else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
625
+ res = res.join(joinArrays);
626
+ if (res) res = this.extendTranslation(res, keys, opt, lastKey);
627
+ } else {
628
+ let usedDefault = false;
629
+ let usedKey = false;
630
+ if (!this.isValidLookup(res) && hasDefaultValue) {
631
+ usedDefault = true;
632
+ res = defaultValue;
633
+ }
634
+ if (!this.isValidLookup(res)) {
635
+ usedKey = true;
636
+ res = key;
637
+ }
638
+ const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
639
+ const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
640
+ const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
641
+ if (usedKey || usedDefault || updateMissing) {
642
+ this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
643
+ if (keySeparator) {
644
+ const fk = this.resolve(key, {
645
+ ...opt,
646
+ keySeparator: false
647
+ });
648
+ if (fk && fk.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.");
649
+ }
650
+ let lngs = [];
651
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
652
+ if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
653
+ for (let i = 0; i < fallbackLngs.length; i++) {
654
+ lngs.push(fallbackLngs[i]);
655
+ }
656
+ } else if (this.options.saveMissingTo === "all") {
657
+ lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
658
+ } else {
659
+ lngs.push(opt.lng || this.language);
660
+ }
661
+ const send = (l, k, specificDefaultValue) => {
662
+ const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
663
+ if (this.options.missingKeyHandler) {
664
+ this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
665
+ } else if (this.backendConnector?.saveMissing) {
666
+ this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
667
+ }
668
+ this.emit("missingKey", l, namespace, k, res);
669
+ };
670
+ if (this.options.saveMissing) {
671
+ if (this.options.saveMissingPlurals && needsPluralHandling) {
672
+ lngs.forEach((language) => {
673
+ const suffixes = this.pluralResolver.getSuffixes(language, opt);
674
+ if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
675
+ suffixes.push(`${this.options.pluralSeparator}zero`);
676
+ }
677
+ suffixes.forEach((suffix) => {
678
+ send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
679
+ });
680
+ });
681
+ } else {
682
+ send(lngs, key, defaultValue);
683
+ }
684
+ }
685
+ }
686
+ res = this.extendTranslation(res, keys, opt, resolved, lastKey);
687
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
688
+ res = `${namespace}${nsSeparator}${key}`;
689
+ }
690
+ if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
691
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : void 0, opt);
692
+ }
693
+ }
694
+ if (returnDetails) {
695
+ resolved.res = res;
696
+ resolved.usedParams = this.getUsedParamsDetails(opt);
697
+ return resolved;
698
+ }
699
+ return res;
700
+ }
701
+ extendTranslation(res, key, opt, resolved, lastKey) {
702
+ if (this.i18nFormat?.parse) {
703
+ res = this.i18nFormat.parse(res, {
704
+ ...this.options.interpolation.defaultVariables,
705
+ ...opt
706
+ }, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
707
+ resolved
708
+ });
709
+ } else if (!opt.skipInterpolation) {
710
+ if (opt.interpolation) this.interpolator.init({
711
+ ...opt,
712
+ ...{
713
+ interpolation: {
714
+ ...this.options.interpolation,
715
+ ...opt.interpolation
716
+ }
717
+ }
718
+ });
719
+ const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== void 0 ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
720
+ let nestBef;
721
+ if (skipOnVariables) {
722
+ const nb = res.match(this.interpolator.nestingRegexp);
723
+ nestBef = nb && nb.length;
724
+ }
725
+ let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
726
+ if (this.options.interpolation.defaultVariables) data = {
727
+ ...this.options.interpolation.defaultVariables,
728
+ ...data
729
+ };
730
+ res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
731
+ if (skipOnVariables) {
732
+ const na = res.match(this.interpolator.nestingRegexp);
733
+ const nestAft = na && na.length;
734
+ if (nestBef < nestAft) opt.nest = false;
735
+ }
736
+ if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
737
+ if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
738
+ if (lastKey?.[0] === args[0] && !opt.context) {
739
+ this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
740
+ return null;
741
+ }
742
+ return this.translate(...args, key);
743
+ }, opt);
744
+ if (opt.interpolation) this.interpolator.reset();
745
+ }
746
+ const postProcess = opt.postProcess || this.options.postProcess;
747
+ const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
748
+ if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) {
749
+ res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
750
+ i18nResolved: {
751
+ ...resolved,
752
+ usedParams: this.getUsedParamsDetails(opt)
753
+ },
754
+ ...opt
755
+ } : opt, this);
756
+ }
757
+ return res;
758
+ }
759
+ resolve(keys, opt = {}) {
760
+ let found;
761
+ let usedKey;
762
+ let exactUsedKey;
763
+ let usedLng;
764
+ let usedNS;
765
+ if (isString(keys)) keys = [keys];
766
+ keys.forEach((k) => {
767
+ if (this.isValidLookup(found)) return;
768
+ const extracted = this.extractFromKey(k, opt);
769
+ const key = extracted.key;
770
+ usedKey = key;
771
+ let namespaces = extracted.namespaces;
772
+ if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
773
+ const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
774
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
775
+ const needsContextHandling = opt.context !== void 0 && (isString(opt.context) || typeof opt.context === "number") && opt.context !== "";
776
+ const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
777
+ namespaces.forEach((ns) => {
778
+ if (this.isValidLookup(found)) return;
779
+ usedNS = ns;
780
+ if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
781
+ checkedLoadedFor[`${codes[0]}-${ns}`] = true;
782
+ this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" 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!!!");
783
+ }
784
+ codes.forEach((code) => {
785
+ if (this.isValidLookup(found)) return;
786
+ usedLng = code;
787
+ const finalKeys = [key];
788
+ if (this.i18nFormat?.addLookupKeys) {
789
+ this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
790
+ } else {
791
+ let pluralSuffix;
792
+ if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
793
+ const zeroSuffix = `${this.options.pluralSeparator}zero`;
794
+ const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
795
+ if (needsPluralHandling) {
796
+ if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
797
+ finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
798
+ }
799
+ finalKeys.push(key + pluralSuffix);
800
+ if (needsZeroSuffixLookup) {
801
+ finalKeys.push(key + zeroSuffix);
802
+ }
803
+ }
804
+ if (needsContextHandling) {
805
+ const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
806
+ finalKeys.push(contextKey);
807
+ if (needsPluralHandling) {
808
+ if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
809
+ finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
810
+ }
811
+ finalKeys.push(contextKey + pluralSuffix);
812
+ if (needsZeroSuffixLookup) {
813
+ finalKeys.push(contextKey + zeroSuffix);
814
+ }
815
+ }
816
+ }
817
+ }
818
+ let possibleKey;
819
+ while (possibleKey = finalKeys.pop()) {
820
+ if (!this.isValidLookup(found)) {
821
+ exactUsedKey = possibleKey;
822
+ found = this.getResource(code, ns, possibleKey, opt);
823
+ }
824
+ }
825
+ });
826
+ });
827
+ });
828
+ return {
829
+ res: found,
830
+ usedKey,
831
+ exactUsedKey,
832
+ usedLng,
833
+ usedNS
834
+ };
835
+ }
836
+ isValidLookup(res) {
837
+ return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
838
+ }
839
+ getResource(code, ns, key, options = {}) {
840
+ if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
841
+ return this.resourceStore.getResource(code, ns, key, options);
842
+ }
843
+ getUsedParamsDetails(options = {}) {
844
+ const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
845
+ const useOptionsReplaceForData = options.replace && !isString(options.replace);
846
+ let data = useOptionsReplaceForData ? options.replace : options;
847
+ if (useOptionsReplaceForData && typeof options.count !== "undefined") {
848
+ data.count = options.count;
849
+ }
850
+ if (this.options.interpolation.defaultVariables) {
851
+ data = {
852
+ ...this.options.interpolation.defaultVariables,
853
+ ...data
854
+ };
855
+ }
856
+ if (!useOptionsReplaceForData) {
857
+ data = {
858
+ ...data
859
+ };
860
+ for (const key of optionsKeys) {
861
+ delete data[key];
862
+ }
863
+ }
864
+ return data;
865
+ }
866
+ static hasDefaultValue(options) {
867
+ const prefix = "defaultValue";
868
+ for (const option in options) {
869
+ if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
870
+ return true;
871
+ }
872
+ }
873
+ return false;
874
+ }
875
+ }
876
+ class LanguageUtil {
877
+ constructor(options) {
878
+ this.options = options;
879
+ this.supportedLngs = this.options.supportedLngs || false;
880
+ this.logger = baseLogger.create("languageUtils");
881
+ }
882
+ getScriptPartFromCode(code) {
883
+ code = getCleanedCode(code);
884
+ if (!code || code.indexOf("-") < 0) return null;
885
+ const p = code.split("-");
886
+ if (p.length === 2) return null;
887
+ p.pop();
888
+ if (p[p.length - 1].toLowerCase() === "x") return null;
889
+ return this.formatLanguageCode(p.join("-"));
890
+ }
891
+ getLanguagePartFromCode(code) {
892
+ code = getCleanedCode(code);
893
+ if (!code || code.indexOf("-") < 0) return code;
894
+ const p = code.split("-");
895
+ return this.formatLanguageCode(p[0]);
896
+ }
897
+ formatLanguageCode(code) {
898
+ if (isString(code) && code.indexOf("-") > -1) {
899
+ let formattedCode;
900
+ try {
901
+ formattedCode = Intl.getCanonicalLocales(code)[0];
902
+ } catch (e) {
903
+ }
904
+ if (formattedCode && this.options.lowerCaseLng) {
905
+ formattedCode = formattedCode.toLowerCase();
906
+ }
907
+ if (formattedCode) return formattedCode;
908
+ if (this.options.lowerCaseLng) {
909
+ return code.toLowerCase();
910
+ }
911
+ return code;
912
+ }
913
+ return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
914
+ }
915
+ isSupportedCode(code) {
916
+ if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
917
+ code = this.getLanguagePartFromCode(code);
918
+ }
919
+ return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
920
+ }
921
+ getBestMatchFromCodes(codes) {
922
+ if (!codes) return null;
923
+ let found;
924
+ codes.forEach((code) => {
925
+ if (found) return;
926
+ const cleanedLng = this.formatLanguageCode(code);
927
+ if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
928
+ });
929
+ if (!found && this.options.supportedLngs) {
930
+ codes.forEach((code) => {
931
+ if (found) return;
932
+ const lngScOnly = this.getScriptPartFromCode(code);
933
+ if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
934
+ const lngOnly = this.getLanguagePartFromCode(code);
935
+ if (this.isSupportedCode(lngOnly)) return found = lngOnly;
936
+ found = this.options.supportedLngs.find((supportedLng) => {
937
+ if (supportedLng === lngOnly) return supportedLng;
938
+ if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
939
+ if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
940
+ if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
941
+ });
942
+ });
943
+ }
944
+ if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
945
+ return found;
946
+ }
947
+ getFallbackCodes(fallbacks, code) {
948
+ if (!fallbacks) return [];
949
+ if (typeof fallbacks === "function") fallbacks = fallbacks(code);
950
+ if (isString(fallbacks)) fallbacks = [fallbacks];
951
+ if (Array.isArray(fallbacks)) return fallbacks;
952
+ if (!code) return fallbacks.default || [];
953
+ let found = fallbacks[code];
954
+ if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
955
+ if (!found) found = fallbacks[this.formatLanguageCode(code)];
956
+ if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
957
+ if (!found) found = fallbacks.default;
958
+ return found || [];
959
+ }
960
+ toResolveHierarchy(code, fallbackCode) {
961
+ const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
962
+ const codes = [];
963
+ const addCode = (c) => {
964
+ if (!c) return;
965
+ if (this.isSupportedCode(c)) {
966
+ codes.push(c);
967
+ } else {
968
+ this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
969
+ }
970
+ };
971
+ if (isString(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
972
+ if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
973
+ if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
974
+ if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
975
+ } else if (isString(code)) {
976
+ addCode(this.formatLanguageCode(code));
977
+ }
978
+ fallbackCodes.forEach((fc) => {
979
+ if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
980
+ });
981
+ return codes;
982
+ }
983
+ }
984
+ const suffixesOrder = {
985
+ zero: 0,
986
+ one: 1,
987
+ two: 2,
988
+ few: 3,
989
+ many: 4,
990
+ other: 5
991
+ };
992
+ const dummyRule = {
993
+ select: (count) => count === 1 ? "one" : "other",
994
+ resolvedOptions: () => ({
995
+ pluralCategories: ["one", "other"]
996
+ })
997
+ };
998
+ class PluralResolver {
999
+ constructor(languageUtils, options = {}) {
1000
+ this.languageUtils = languageUtils;
1001
+ this.options = options;
1002
+ this.logger = baseLogger.create("pluralResolver");
1003
+ this.pluralRulesCache = {};
1004
+ }
1005
+ addRule(lng, obj) {
1006
+ this.rules[lng] = obj;
1007
+ }
1008
+ clearCache() {
1009
+ this.pluralRulesCache = {};
1010
+ }
1011
+ getRule(code, options = {}) {
1012
+ const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
1013
+ const type = options.ordinal ? "ordinal" : "cardinal";
1014
+ const cacheKey = JSON.stringify({
1015
+ cleanedCode,
1016
+ type
1017
+ });
1018
+ if (cacheKey in this.pluralRulesCache) {
1019
+ return this.pluralRulesCache[cacheKey];
1020
+ }
1021
+ let rule;
1022
+ try {
1023
+ rule = new Intl.PluralRules(cleanedCode, {
1024
+ type
1025
+ });
1026
+ } catch (err) {
1027
+ if (!Intl) {
1028
+ this.logger.error("No Intl support, please use an Intl polyfill!");
1029
+ return dummyRule;
1030
+ }
1031
+ if (!code.match(/-|_/)) return dummyRule;
1032
+ const lngPart = this.languageUtils.getLanguagePartFromCode(code);
1033
+ rule = this.getRule(lngPart, options);
1034
+ }
1035
+ this.pluralRulesCache[cacheKey] = rule;
1036
+ return rule;
1037
+ }
1038
+ needsPlural(code, options = {}) {
1039
+ let rule = this.getRule(code, options);
1040
+ if (!rule) rule = this.getRule("dev", options);
1041
+ return rule?.resolvedOptions().pluralCategories.length > 1;
1042
+ }
1043
+ getPluralFormsOfKey(code, key, options = {}) {
1044
+ return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
1045
+ }
1046
+ getSuffixes(code, options = {}) {
1047
+ let rule = this.getRule(code, options);
1048
+ if (!rule) rule = this.getRule("dev", options);
1049
+ if (!rule) return [];
1050
+ return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
1051
+ }
1052
+ getSuffix(code, count, options = {}) {
1053
+ const rule = this.getRule(code, options);
1054
+ if (rule) {
1055
+ return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
1056
+ }
1057
+ this.logger.warn(`no plural rule found for: ${code}`);
1058
+ return this.getSuffix("dev", count, options);
1059
+ }
1060
+ }
1061
+ const deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
1062
+ let path = getPathWithDefaults(data, defaultData, key);
1063
+ if (!path && ignoreJSONStructure && isString(key)) {
1064
+ path = deepFind(data, key, keySeparator);
1065
+ if (path === void 0) path = deepFind(defaultData, key, keySeparator);
1066
+ }
1067
+ return path;
1068
+ };
1069
+ const regexSafe = (val) => val.replace(/\$/g, "$$$$");
1070
+ class Interpolator {
1071
+ constructor(options = {}) {
1072
+ this.logger = baseLogger.create("interpolator");
1073
+ this.options = options;
1074
+ this.format = options?.interpolation?.format || ((value) => value);
1075
+ this.init(options);
1076
+ }
1077
+ init(options = {}) {
1078
+ if (!options.interpolation) options.interpolation = {
1079
+ escapeValue: true
1080
+ };
1081
+ const {
1082
+ escape: escape$1,
1083
+ escapeValue,
1084
+ useRawValueToEscape,
1085
+ prefix,
1086
+ prefixEscaped,
1087
+ suffix,
1088
+ suffixEscaped,
1089
+ formatSeparator,
1090
+ unescapeSuffix,
1091
+ unescapePrefix,
1092
+ nestingPrefix,
1093
+ nestingPrefixEscaped,
1094
+ nestingSuffix,
1095
+ nestingSuffixEscaped,
1096
+ nestingOptionsSeparator,
1097
+ maxReplaces,
1098
+ alwaysFormat
1099
+ } = options.interpolation;
1100
+ this.escape = escape$1 !== void 0 ? escape$1 : escape;
1101
+ this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
1102
+ this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
1103
+ this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
1104
+ this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
1105
+ this.formatSeparator = formatSeparator || ",";
1106
+ this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
1107
+ this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
1108
+ this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
1109
+ this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
1110
+ this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
1111
+ this.maxReplaces = maxReplaces || 1e3;
1112
+ this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
1113
+ this.resetRegExp();
1114
+ }
1115
+ reset() {
1116
+ if (this.options) this.init(this.options);
1117
+ }
1118
+ resetRegExp() {
1119
+ const getOrResetRegExp = (existingRegExp, pattern) => {
1120
+ if (existingRegExp?.source === pattern) {
1121
+ existingRegExp.lastIndex = 0;
1122
+ return existingRegExp;
1123
+ }
1124
+ return new RegExp(pattern, "g");
1125
+ };
1126
+ this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
1127
+ this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
1128
+ this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
1129
+ }
1130
+ interpolate(str, data, lng, options) {
1131
+ let match;
1132
+ let value;
1133
+ let replaces;
1134
+ const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
1135
+ const handleFormat = (key) => {
1136
+ if (key.indexOf(this.formatSeparator) < 0) {
1137
+ const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
1138
+ return this.alwaysFormat ? this.format(path, void 0, lng, {
1139
+ ...options,
1140
+ ...data,
1141
+ interpolationkey: key
1142
+ }) : path;
1143
+ }
1144
+ const p = key.split(this.formatSeparator);
1145
+ const k = p.shift().trim();
1146
+ const f = p.join(this.formatSeparator).trim();
1147
+ return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
1148
+ ...options,
1149
+ ...data,
1150
+ interpolationkey: k
1151
+ });
1152
+ };
1153
+ this.resetRegExp();
1154
+ const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
1155
+ const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
1156
+ const todos = [{
1157
+ regex: this.regexpUnescape,
1158
+ safeValue: (val) => regexSafe(val)
1159
+ }, {
1160
+ regex: this.regexp,
1161
+ safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
1162
+ }];
1163
+ todos.forEach((todo) => {
1164
+ replaces = 0;
1165
+ while (match = todo.regex.exec(str)) {
1166
+ const matchedVar = match[1].trim();
1167
+ value = handleFormat(matchedVar);
1168
+ if (value === void 0) {
1169
+ if (typeof missingInterpolationHandler === "function") {
1170
+ const temp = missingInterpolationHandler(str, match, options);
1171
+ value = isString(temp) ? temp : "";
1172
+ } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
1173
+ value = "";
1174
+ } else if (skipOnVariables) {
1175
+ value = match[0];
1176
+ continue;
1177
+ } else {
1178
+ this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
1179
+ value = "";
1180
+ }
1181
+ } else if (!isString(value) && !this.useRawValueToEscape) {
1182
+ value = makeString(value);
1183
+ }
1184
+ const safeValue = todo.safeValue(value);
1185
+ str = str.replace(match[0], safeValue);
1186
+ if (skipOnVariables) {
1187
+ todo.regex.lastIndex += value.length;
1188
+ todo.regex.lastIndex -= match[0].length;
1189
+ } else {
1190
+ todo.regex.lastIndex = 0;
1191
+ }
1192
+ replaces++;
1193
+ if (replaces >= this.maxReplaces) {
1194
+ break;
1195
+ }
1196
+ }
1197
+ });
1198
+ return str;
1199
+ }
1200
+ nest(str, fc, options = {}) {
1201
+ let match;
1202
+ let value;
1203
+ let clonedOptions;
1204
+ const handleHasOptions = (key, inheritedOptions) => {
1205
+ const sep = this.nestingOptionsSeparator;
1206
+ if (key.indexOf(sep) < 0) return key;
1207
+ const c = key.split(new RegExp(`${sep}[ ]*{`));
1208
+ let optionsString = `{${c[1]}`;
1209
+ key = c[0];
1210
+ optionsString = this.interpolate(optionsString, clonedOptions);
1211
+ const matchedSingleQuotes = optionsString.match(/'/g);
1212
+ const matchedDoubleQuotes = optionsString.match(/"/g);
1213
+ if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
1214
+ optionsString = optionsString.replace(/'/g, '"');
1215
+ }
1216
+ try {
1217
+ clonedOptions = JSON.parse(optionsString);
1218
+ if (inheritedOptions) clonedOptions = {
1219
+ ...inheritedOptions,
1220
+ ...clonedOptions
1221
+ };
1222
+ } catch (e) {
1223
+ this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
1224
+ return `${key}${sep}${optionsString}`;
1225
+ }
1226
+ if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
1227
+ return key;
1228
+ };
1229
+ while (match = this.nestingRegexp.exec(str)) {
1230
+ let formatters = [];
1231
+ clonedOptions = {
1232
+ ...options
1233
+ };
1234
+ clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
1235
+ clonedOptions.applyPostProcessor = false;
1236
+ delete clonedOptions.defaultValue;
1237
+ const keyEndIndex = /{.*}/.test(match[1]) ? match[1].lastIndexOf("}") + 1 : match[1].indexOf(this.formatSeparator);
1238
+ if (keyEndIndex !== -1) {
1239
+ formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
1240
+ match[1] = match[1].slice(0, keyEndIndex);
1241
+ }
1242
+ value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
1243
+ if (value && match[0] === str && !isString(value)) return value;
1244
+ if (!isString(value)) value = makeString(value);
1245
+ if (!value) {
1246
+ this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
1247
+ value = "";
1248
+ }
1249
+ if (formatters.length) {
1250
+ value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
1251
+ ...options,
1252
+ interpolationkey: match[1].trim()
1253
+ }), value.trim());
1254
+ }
1255
+ str = str.replace(match[0], value);
1256
+ this.regexp.lastIndex = 0;
1257
+ }
1258
+ return str;
1259
+ }
1260
+ }
1261
+ const parseFormatStr = (formatStr) => {
1262
+ let formatName = formatStr.toLowerCase().trim();
1263
+ const formatOptions = {};
1264
+ if (formatStr.indexOf("(") > -1) {
1265
+ const p = formatStr.split("(");
1266
+ formatName = p[0].toLowerCase().trim();
1267
+ const optStr = p[1].substring(0, p[1].length - 1);
1268
+ if (formatName === "currency" && optStr.indexOf(":") < 0) {
1269
+ if (!formatOptions.currency) formatOptions.currency = optStr.trim();
1270
+ } else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
1271
+ if (!formatOptions.range) formatOptions.range = optStr.trim();
1272
+ } else {
1273
+ const opts = optStr.split(";");
1274
+ opts.forEach((opt) => {
1275
+ if (opt) {
1276
+ const [key, ...rest] = opt.split(":");
1277
+ const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
1278
+ const trimmedKey = key.trim();
1279
+ if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
1280
+ if (val === "false") formatOptions[trimmedKey] = false;
1281
+ if (val === "true") formatOptions[trimmedKey] = true;
1282
+ if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
1283
+ }
1284
+ });
1285
+ }
1286
+ }
1287
+ return {
1288
+ formatName,
1289
+ formatOptions
1290
+ };
1291
+ };
1292
+ const createCachedFormatter = (fn) => {
1293
+ const cache = {};
1294
+ return (v, l, o) => {
1295
+ let optForCache = o;
1296
+ if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
1297
+ optForCache = {
1298
+ ...optForCache,
1299
+ [o.interpolationkey]: void 0
1300
+ };
1301
+ }
1302
+ const key = l + JSON.stringify(optForCache);
1303
+ let frm = cache[key];
1304
+ if (!frm) {
1305
+ frm = fn(getCleanedCode(l), o);
1306
+ cache[key] = frm;
1307
+ }
1308
+ return frm(v);
1309
+ };
1310
+ };
1311
+ const createNonCachedFormatter = (fn) => (v, l, o) => fn(getCleanedCode(l), o)(v);
1312
+ class Formatter {
1313
+ constructor(options = {}) {
1314
+ this.logger = baseLogger.create("formatter");
1315
+ this.options = options;
1316
+ this.init(options);
1317
+ }
1318
+ init(services, options = {
1319
+ interpolation: {}
1320
+ }) {
1321
+ this.formatSeparator = options.interpolation.formatSeparator || ",";
1322
+ const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
1323
+ this.formats = {
1324
+ number: cf((lng, opt) => {
1325
+ const formatter = new Intl.NumberFormat(lng, {
1326
+ ...opt
1327
+ });
1328
+ return (val) => formatter.format(val);
1329
+ }),
1330
+ currency: cf((lng, opt) => {
1331
+ const formatter = new Intl.NumberFormat(lng, {
1332
+ ...opt,
1333
+ style: "currency"
1334
+ });
1335
+ return (val) => formatter.format(val);
1336
+ }),
1337
+ datetime: cf((lng, opt) => {
1338
+ const formatter = new Intl.DateTimeFormat(lng, {
1339
+ ...opt
1340
+ });
1341
+ return (val) => formatter.format(val);
1342
+ }),
1343
+ relativetime: cf((lng, opt) => {
1344
+ const formatter = new Intl.RelativeTimeFormat(lng, {
1345
+ ...opt
1346
+ });
1347
+ return (val) => formatter.format(val, opt.range || "day");
1348
+ }),
1349
+ list: cf((lng, opt) => {
1350
+ const formatter = new Intl.ListFormat(lng, {
1351
+ ...opt
1352
+ });
1353
+ return (val) => formatter.format(val);
1354
+ })
1355
+ };
1356
+ }
1357
+ add(name, fc) {
1358
+ this.formats[name.toLowerCase().trim()] = fc;
1359
+ }
1360
+ addCached(name, fc) {
1361
+ this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1362
+ }
1363
+ format(value, format, lng, options = {}) {
1364
+ const formats = format.split(this.formatSeparator);
1365
+ if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
1366
+ const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
1367
+ formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
1368
+ }
1369
+ const result = formats.reduce((mem, f) => {
1370
+ const {
1371
+ formatName,
1372
+ formatOptions
1373
+ } = parseFormatStr(f);
1374
+ if (this.formats[formatName]) {
1375
+ let formatted = mem;
1376
+ try {
1377
+ const valOptions = options?.formatParams?.[options.interpolationkey] || {};
1378
+ const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
1379
+ formatted = this.formats[formatName](mem, l, {
1380
+ ...formatOptions,
1381
+ ...options,
1382
+ ...valOptions
1383
+ });
1384
+ } catch (error) {
1385
+ this.logger.warn(error);
1386
+ }
1387
+ return formatted;
1388
+ } else {
1389
+ this.logger.warn(`there was no format function for ${formatName}`);
1390
+ }
1391
+ return mem;
1392
+ }, value);
1393
+ return result;
1394
+ }
1395
+ }
1396
+ const removePending = (q, name) => {
1397
+ if (q.pending[name] !== void 0) {
1398
+ delete q.pending[name];
1399
+ q.pendingCount--;
1400
+ }
1401
+ };
1402
+ class Connector extends EventEmitter {
1403
+ constructor(backend, store, services, options = {}) {
1404
+ super();
1405
+ this.backend = backend;
1406
+ this.store = store;
1407
+ this.services = services;
1408
+ this.languageUtils = services.languageUtils;
1409
+ this.options = options;
1410
+ this.logger = baseLogger.create("backendConnector");
1411
+ this.waitingReads = [];
1412
+ this.maxParallelReads = options.maxParallelReads || 10;
1413
+ this.readingCalls = 0;
1414
+ this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
1415
+ this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
1416
+ this.state = {};
1417
+ this.queue = [];
1418
+ this.backend?.init?.(services, options.backend, options);
1419
+ }
1420
+ queueLoad(languages, namespaces, options, callback) {
1421
+ const toLoad = {};
1422
+ const pending = {};
1423
+ const toLoadLanguages = {};
1424
+ const toLoadNamespaces = {};
1425
+ languages.forEach((lng) => {
1426
+ let hasAllNamespaces = true;
1427
+ namespaces.forEach((ns) => {
1428
+ const name = `${lng}|${ns}`;
1429
+ if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
1430
+ this.state[name] = 2;
1431
+ } else if (this.state[name] < 0) ;
1432
+ else if (this.state[name] === 1) {
1433
+ if (pending[name] === void 0) pending[name] = true;
1434
+ } else {
1435
+ this.state[name] = 1;
1436
+ hasAllNamespaces = false;
1437
+ if (pending[name] === void 0) pending[name] = true;
1438
+ if (toLoad[name] === void 0) toLoad[name] = true;
1439
+ if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
1440
+ }
1441
+ });
1442
+ if (!hasAllNamespaces) toLoadLanguages[lng] = true;
1443
+ });
1444
+ if (Object.keys(toLoad).length || Object.keys(pending).length) {
1445
+ this.queue.push({
1446
+ pending,
1447
+ pendingCount: Object.keys(pending).length,
1448
+ loaded: {},
1449
+ errors: [],
1450
+ callback
1451
+ });
1452
+ }
1453
+ return {
1454
+ toLoad: Object.keys(toLoad),
1455
+ pending: Object.keys(pending),
1456
+ toLoadLanguages: Object.keys(toLoadLanguages),
1457
+ toLoadNamespaces: Object.keys(toLoadNamespaces)
1458
+ };
1459
+ }
1460
+ loaded(name, err, data) {
1461
+ const s = name.split("|");
1462
+ const lng = s[0];
1463
+ const ns = s[1];
1464
+ if (err) this.emit("failedLoading", lng, ns, err);
1465
+ if (!err && data) {
1466
+ this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
1467
+ skipCopy: true
1468
+ });
1469
+ }
1470
+ this.state[name] = err ? -1 : 2;
1471
+ if (err && data) this.state[name] = 0;
1472
+ const loaded = {};
1473
+ this.queue.forEach((q) => {
1474
+ pushPath(q.loaded, [lng], ns);
1475
+ removePending(q, name);
1476
+ if (err) q.errors.push(err);
1477
+ if (q.pendingCount === 0 && !q.done) {
1478
+ Object.keys(q.loaded).forEach((l) => {
1479
+ if (!loaded[l]) loaded[l] = {};
1480
+ const loadedKeys = q.loaded[l];
1481
+ if (loadedKeys.length) {
1482
+ loadedKeys.forEach((n) => {
1483
+ if (loaded[l][n] === void 0) loaded[l][n] = true;
1484
+ });
1485
+ }
1486
+ });
1487
+ q.done = true;
1488
+ if (q.errors.length) {
1489
+ q.callback(q.errors);
1490
+ } else {
1491
+ q.callback();
1492
+ }
1493
+ }
1494
+ });
1495
+ this.emit("loaded", loaded);
1496
+ this.queue = this.queue.filter((q) => !q.done);
1497
+ }
1498
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
1499
+ if (!lng.length) return callback(null, {});
1500
+ if (this.readingCalls >= this.maxParallelReads) {
1501
+ this.waitingReads.push({
1502
+ lng,
1503
+ ns,
1504
+ fcName,
1505
+ tried,
1506
+ wait,
1507
+ callback
1508
+ });
1509
+ return;
1510
+ }
1511
+ this.readingCalls++;
1512
+ const resolver = (err, data) => {
1513
+ this.readingCalls--;
1514
+ if (this.waitingReads.length > 0) {
1515
+ const next = this.waitingReads.shift();
1516
+ this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
1517
+ }
1518
+ if (err && data && tried < this.maxRetries) {
1519
+ setTimeout(() => {
1520
+ this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
1521
+ }, wait);
1522
+ return;
1523
+ }
1524
+ callback(err, data);
1525
+ };
1526
+ const fc = this.backend[fcName].bind(this.backend);
1527
+ if (fc.length === 2) {
1528
+ try {
1529
+ const r = fc(lng, ns);
1530
+ if (r && typeof r.then === "function") {
1531
+ r.then((data) => resolver(null, data)).catch(resolver);
1532
+ } else {
1533
+ resolver(null, r);
1534
+ }
1535
+ } catch (err) {
1536
+ resolver(err);
1537
+ }
1538
+ return;
1539
+ }
1540
+ return fc(lng, ns, resolver);
1541
+ }
1542
+ prepareLoading(languages, namespaces, options = {}, callback) {
1543
+ if (!this.backend) {
1544
+ this.logger.warn("No backend was added via i18next.use. Will not load resources.");
1545
+ return callback && callback();
1546
+ }
1547
+ if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
1548
+ if (isString(namespaces)) namespaces = [namespaces];
1549
+ const toLoad = this.queueLoad(languages, namespaces, options, callback);
1550
+ if (!toLoad.toLoad.length) {
1551
+ if (!toLoad.pending.length) callback();
1552
+ return null;
1553
+ }
1554
+ toLoad.toLoad.forEach((name) => {
1555
+ this.loadOne(name);
1556
+ });
1557
+ }
1558
+ load(languages, namespaces, callback) {
1559
+ this.prepareLoading(languages, namespaces, {}, callback);
1560
+ }
1561
+ reload(languages, namespaces, callback) {
1562
+ this.prepareLoading(languages, namespaces, {
1563
+ reload: true
1564
+ }, callback);
1565
+ }
1566
+ loadOne(name, prefix = "") {
1567
+ const s = name.split("|");
1568
+ const lng = s[0];
1569
+ const ns = s[1];
1570
+ this.read(lng, ns, "read", void 0, void 0, (err, data) => {
1571
+ if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
1572
+ if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
1573
+ this.loaded(name, err, data);
1574
+ });
1575
+ }
1576
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {
1577
+ }) {
1578
+ if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
1579
+ this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" 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!!!");
1580
+ return;
1581
+ }
1582
+ if (key === void 0 || key === null || key === "") return;
1583
+ if (this.backend?.create) {
1584
+ const opts = {
1585
+ ...options,
1586
+ isUpdate
1587
+ };
1588
+ const fc = this.backend.create.bind(this.backend);
1589
+ if (fc.length < 6) {
1590
+ try {
1591
+ let r;
1592
+ if (fc.length === 5) {
1593
+ r = fc(languages, namespace, key, fallbackValue, opts);
1594
+ } else {
1595
+ r = fc(languages, namespace, key, fallbackValue);
1596
+ }
1597
+ if (r && typeof r.then === "function") {
1598
+ r.then((data) => clb(null, data)).catch(clb);
1599
+ } else {
1600
+ clb(null, r);
1601
+ }
1602
+ } catch (err) {
1603
+ clb(err);
1604
+ }
1605
+ } else {
1606
+ fc(languages, namespace, key, fallbackValue, clb, opts);
1607
+ }
1608
+ }
1609
+ if (!languages || !languages[0]) return;
1610
+ this.store.addResource(languages[0], namespace, key, fallbackValue);
1611
+ }
1612
+ }
1613
+ const get = () => ({
1614
+ debug: false,
1615
+ initAsync: true,
1616
+ ns: ["translation"],
1617
+ defaultNS: ["translation"],
1618
+ fallbackLng: ["dev"],
1619
+ fallbackNS: false,
1620
+ supportedLngs: false,
1621
+ nonExplicitSupportedLngs: false,
1622
+ load: "all",
1623
+ preload: false,
1624
+ simplifyPluralSuffix: true,
1625
+ keySeparator: ".",
1626
+ nsSeparator: ":",
1627
+ pluralSeparator: "_",
1628
+ contextSeparator: "_",
1629
+ partialBundledLanguages: false,
1630
+ saveMissing: false,
1631
+ updateMissing: false,
1632
+ saveMissingTo: "fallback",
1633
+ saveMissingPlurals: true,
1634
+ missingKeyHandler: false,
1635
+ missingInterpolationHandler: false,
1636
+ postProcess: false,
1637
+ postProcessPassResolved: false,
1638
+ returnNull: false,
1639
+ returnEmptyString: true,
1640
+ returnObjects: false,
1641
+ joinArrays: false,
1642
+ returnedObjectHandler: false,
1643
+ parseMissingKeyHandler: false,
1644
+ appendNamespaceToMissingKey: false,
1645
+ appendNamespaceToCIMode: false,
1646
+ overloadTranslationOptionHandler: (args) => {
1647
+ let ret = {};
1648
+ if (typeof args[1] === "object") ret = args[1];
1649
+ if (isString(args[1])) ret.defaultValue = args[1];
1650
+ if (isString(args[2])) ret.tDescription = args[2];
1651
+ if (typeof args[2] === "object" || typeof args[3] === "object") {
1652
+ const options = args[3] || args[2];
1653
+ Object.keys(options).forEach((key) => {
1654
+ ret[key] = options[key];
1655
+ });
1656
+ }
1657
+ return ret;
1658
+ },
1659
+ interpolation: {
1660
+ escapeValue: true,
1661
+ format: (value) => value,
1662
+ prefix: "{{",
1663
+ suffix: "}}",
1664
+ formatSeparator: ",",
1665
+ unescapePrefix: "-",
1666
+ nestingPrefix: "$t(",
1667
+ nestingSuffix: ")",
1668
+ nestingOptionsSeparator: ",",
1669
+ maxReplaces: 1e3,
1670
+ skipOnVariables: true
1671
+ },
1672
+ cacheInBuiltFormats: true
1673
+ });
1674
+ const transformOptions = (options) => {
1675
+ if (isString(options.ns)) options.ns = [options.ns];
1676
+ if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
1677
+ if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
1678
+ if (options.supportedLngs?.indexOf?.("cimode") < 0) {
1679
+ options.supportedLngs = options.supportedLngs.concat(["cimode"]);
1680
+ }
1681
+ if (typeof options.initImmediate === "boolean") options.initAsync = options.initImmediate;
1682
+ return options;
1683
+ };
1684
+ const noop = () => {
1685
+ };
1686
+ const bindMemberFunctions = (inst) => {
1687
+ const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
1688
+ mems.forEach((mem) => {
1689
+ if (typeof inst[mem] === "function") {
1690
+ inst[mem] = inst[mem].bind(inst);
1691
+ }
1692
+ });
1693
+ };
1694
+ class I18n extends EventEmitter {
1695
+ constructor(options = {}, callback) {
1696
+ super();
1697
+ this.options = transformOptions(options);
1698
+ this.services = {};
1699
+ this.logger = baseLogger;
1700
+ this.modules = {
1701
+ external: []
1702
+ };
1703
+ bindMemberFunctions(this);
1704
+ if (callback && !this.isInitialized && !options.isClone) {
1705
+ if (!this.options.initAsync) {
1706
+ this.init(options, callback);
1707
+ return this;
1708
+ }
1709
+ setTimeout(() => {
1710
+ this.init(options, callback);
1711
+ }, 0);
1712
+ }
1713
+ }
1714
+ init(options = {}, callback) {
1715
+ this.isInitializing = true;
1716
+ if (typeof options === "function") {
1717
+ callback = options;
1718
+ options = {};
1719
+ }
1720
+ if (options.defaultNS == null && options.ns) {
1721
+ if (isString(options.ns)) {
1722
+ options.defaultNS = options.ns;
1723
+ } else if (options.ns.indexOf("translation") < 0) {
1724
+ options.defaultNS = options.ns[0];
1725
+ }
1726
+ }
1727
+ const defOpts = get();
1728
+ this.options = {
1729
+ ...defOpts,
1730
+ ...this.options,
1731
+ ...transformOptions(options)
1732
+ };
1733
+ this.options.interpolation = {
1734
+ ...defOpts.interpolation,
1735
+ ...this.options.interpolation
1736
+ };
1737
+ if (options.keySeparator !== void 0) {
1738
+ this.options.userDefinedKeySeparator = options.keySeparator;
1739
+ }
1740
+ if (options.nsSeparator !== void 0) {
1741
+ this.options.userDefinedNsSeparator = options.nsSeparator;
1742
+ }
1743
+ if (typeof this.options.overloadTranslationOptionHandler !== "function") {
1744
+ this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
1745
+ }
1746
+ const createClassOnDemand = (ClassOrObject) => {
1747
+ if (!ClassOrObject) return null;
1748
+ if (typeof ClassOrObject === "function") return new ClassOrObject();
1749
+ return ClassOrObject;
1750
+ };
1751
+ if (!this.options.isClone) {
1752
+ if (this.modules.logger) {
1753
+ baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
1754
+ } else {
1755
+ baseLogger.init(null, this.options);
1756
+ }
1757
+ let formatter;
1758
+ if (this.modules.formatter) {
1759
+ formatter = this.modules.formatter;
1760
+ } else {
1761
+ formatter = Formatter;
1762
+ }
1763
+ const lu = new LanguageUtil(this.options);
1764
+ this.store = new ResourceStore(this.options.resources, this.options);
1765
+ const s = this.services;
1766
+ s.logger = baseLogger;
1767
+ s.resourceStore = this.store;
1768
+ s.languageUtils = lu;
1769
+ s.pluralResolver = new PluralResolver(lu, {
1770
+ prepend: this.options.pluralSeparator,
1771
+ simplifyPluralSuffix: this.options.simplifyPluralSuffix
1772
+ });
1773
+ const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
1774
+ if (usingLegacyFormatFunction) {
1775
+ this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
1776
+ }
1777
+ if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
1778
+ s.formatter = createClassOnDemand(formatter);
1779
+ if (s.formatter.init) s.formatter.init(s, this.options);
1780
+ this.options.interpolation.format = s.formatter.format.bind(s.formatter);
1781
+ }
1782
+ s.interpolator = new Interpolator(this.options);
1783
+ s.utils = {
1784
+ hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1785
+ };
1786
+ s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
1787
+ s.backendConnector.on("*", (event, ...args) => {
1788
+ this.emit(event, ...args);
1789
+ });
1790
+ if (this.modules.languageDetector) {
1791
+ s.languageDetector = createClassOnDemand(this.modules.languageDetector);
1792
+ if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
1793
+ }
1794
+ if (this.modules.i18nFormat) {
1795
+ s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
1796
+ if (s.i18nFormat.init) s.i18nFormat.init(this);
1797
+ }
1798
+ this.translator = new Translator(this.services, this.options);
1799
+ this.translator.on("*", (event, ...args) => {
1800
+ this.emit(event, ...args);
1801
+ });
1802
+ this.modules.external.forEach((m) => {
1803
+ if (m.init) m.init(this);
1804
+ });
1805
+ }
1806
+ this.format = this.options.interpolation.format;
1807
+ if (!callback) callback = noop;
1808
+ if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
1809
+ const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1810
+ if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
1811
+ }
1812
+ if (!this.services.languageDetector && !this.options.lng) {
1813
+ this.logger.warn("init: no languageDetector is used and no lng is defined");
1814
+ }
1815
+ const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
1816
+ storeApi.forEach((fcName) => {
1817
+ this[fcName] = (...args) => this.store[fcName](...args);
1818
+ });
1819
+ const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
1820
+ storeApiChained.forEach((fcName) => {
1821
+ this[fcName] = (...args) => {
1822
+ this.store[fcName](...args);
1823
+ return this;
1824
+ };
1825
+ });
1826
+ const deferred = defer();
1827
+ const load = () => {
1828
+ const finish = (err, t2) => {
1829
+ this.isInitializing = false;
1830
+ if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
1831
+ this.isInitialized = true;
1832
+ if (!this.options.isClone) this.logger.log("initialized", this.options);
1833
+ this.emit("initialized", this.options);
1834
+ deferred.resolve(t2);
1835
+ callback(err, t2);
1836
+ };
1837
+ if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
1838
+ this.changeLanguage(this.options.lng, finish);
1839
+ };
1840
+ if (this.options.resources || !this.options.initAsync) {
1841
+ load();
1842
+ } else {
1843
+ setTimeout(load, 0);
1844
+ }
1845
+ return deferred;
1846
+ }
1847
+ loadResources(language, callback = noop) {
1848
+ let usedCallback = callback;
1849
+ const usedLng = isString(language) ? language : this.language;
1850
+ if (typeof language === "function") usedCallback = language;
1851
+ if (!this.options.resources || this.options.partialBundledLanguages) {
1852
+ if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
1853
+ const toLoad = [];
1854
+ const append = (lng) => {
1855
+ if (!lng) return;
1856
+ if (lng === "cimode") return;
1857
+ const lngs = this.services.languageUtils.toResolveHierarchy(lng);
1858
+ lngs.forEach((l) => {
1859
+ if (l === "cimode") return;
1860
+ if (toLoad.indexOf(l) < 0) toLoad.push(l);
1861
+ });
1862
+ };
1863
+ if (!usedLng) {
1864
+ const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1865
+ fallbacks.forEach((l) => append(l));
1866
+ } else {
1867
+ append(usedLng);
1868
+ }
1869
+ this.options.preload?.forEach?.((l) => append(l));
1870
+ this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
1871
+ if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
1872
+ usedCallback(e);
1873
+ });
1874
+ } else {
1875
+ usedCallback(null);
1876
+ }
1877
+ }
1878
+ reloadResources(lngs, ns, callback) {
1879
+ const deferred = defer();
1880
+ if (typeof lngs === "function") {
1881
+ callback = lngs;
1882
+ lngs = void 0;
1883
+ }
1884
+ if (typeof ns === "function") {
1885
+ callback = ns;
1886
+ ns = void 0;
1887
+ }
1888
+ if (!lngs) lngs = this.languages;
1889
+ if (!ns) ns = this.options.ns;
1890
+ if (!callback) callback = noop;
1891
+ this.services.backendConnector.reload(lngs, ns, (err) => {
1892
+ deferred.resolve();
1893
+ callback(err);
1894
+ });
1895
+ return deferred;
1896
+ }
1897
+ use(module) {
1898
+ if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
1899
+ if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
1900
+ if (module.type === "backend") {
1901
+ this.modules.backend = module;
1902
+ }
1903
+ if (module.type === "logger" || module.log && module.warn && module.error) {
1904
+ this.modules.logger = module;
1905
+ }
1906
+ if (module.type === "languageDetector") {
1907
+ this.modules.languageDetector = module;
1908
+ }
1909
+ if (module.type === "i18nFormat") {
1910
+ this.modules.i18nFormat = module;
1911
+ }
1912
+ if (module.type === "postProcessor") {
1913
+ postProcessor.addPostProcessor(module);
1914
+ }
1915
+ if (module.type === "formatter") {
1916
+ this.modules.formatter = module;
1917
+ }
1918
+ if (module.type === "3rdParty") {
1919
+ this.modules.external.push(module);
1920
+ }
1921
+ return this;
1922
+ }
1923
+ setResolvedLanguage(l) {
1924
+ if (!l || !this.languages) return;
1925
+ if (["cimode", "dev"].indexOf(l) > -1) return;
1926
+ for (let li = 0; li < this.languages.length; li++) {
1927
+ const lngInLngs = this.languages[li];
1928
+ if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
1929
+ if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
1930
+ this.resolvedLanguage = lngInLngs;
1931
+ break;
1932
+ }
1933
+ }
1934
+ if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
1935
+ this.resolvedLanguage = l;
1936
+ this.languages.unshift(l);
1937
+ }
1938
+ }
1939
+ changeLanguage(lng, callback) {
1940
+ this.isLanguageChangingTo = lng;
1941
+ const deferred = defer();
1942
+ this.emit("languageChanging", lng);
1943
+ const setLngProps = (l) => {
1944
+ this.language = l;
1945
+ this.languages = this.services.languageUtils.toResolveHierarchy(l);
1946
+ this.resolvedLanguage = void 0;
1947
+ this.setResolvedLanguage(l);
1948
+ };
1949
+ const done = (err, l) => {
1950
+ if (l) {
1951
+ if (this.isLanguageChangingTo === lng) {
1952
+ setLngProps(l);
1953
+ this.translator.changeLanguage(l);
1954
+ this.isLanguageChangingTo = void 0;
1955
+ this.emit("languageChanged", l);
1956
+ this.logger.log("languageChanged", l);
1957
+ }
1958
+ } else {
1959
+ this.isLanguageChangingTo = void 0;
1960
+ }
1961
+ deferred.resolve((...args) => this.t(...args));
1962
+ if (callback) callback(err, (...args) => this.t(...args));
1963
+ };
1964
+ const setLng = (lngs) => {
1965
+ if (!lng && !lngs && this.services.languageDetector) lngs = [];
1966
+ const fl = isString(lngs) ? lngs : lngs && lngs[0];
1967
+ const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
1968
+ if (l) {
1969
+ if (!this.language) {
1970
+ setLngProps(l);
1971
+ }
1972
+ if (!this.translator.language) this.translator.changeLanguage(l);
1973
+ this.services.languageDetector?.cacheUserLanguage?.(l);
1974
+ }
1975
+ this.loadResources(l, (err) => {
1976
+ done(err, l);
1977
+ });
1978
+ };
1979
+ if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
1980
+ setLng(this.services.languageDetector.detect());
1981
+ } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
1982
+ if (this.services.languageDetector.detect.length === 0) {
1983
+ this.services.languageDetector.detect().then(setLng);
1984
+ } else {
1985
+ this.services.languageDetector.detect(setLng);
1986
+ }
1987
+ } else {
1988
+ setLng(lng);
1989
+ }
1990
+ return deferred;
1991
+ }
1992
+ getFixedT(lng, ns, keyPrefix) {
1993
+ const fixedT = (key, opts, ...rest) => {
1994
+ let o;
1995
+ if (typeof opts !== "object") {
1996
+ o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
1997
+ } else {
1998
+ o = {
1999
+ ...opts
2000
+ };
2001
+ }
2002
+ o.lng = o.lng || fixedT.lng;
2003
+ o.lngs = o.lngs || fixedT.lngs;
2004
+ o.ns = o.ns || fixedT.ns;
2005
+ if (o.keyPrefix !== "") o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
2006
+ const keySeparator = this.options.keySeparator || ".";
2007
+ let resultKey;
2008
+ if (o.keyPrefix && Array.isArray(key)) {
2009
+ resultKey = key.map((k) => {
2010
+ if (typeof k === "function") k = keysFromSelector(k, {
2011
+ ...this.options,
2012
+ ...opts
2013
+ });
2014
+ return `${o.keyPrefix}${keySeparator}${k}`;
2015
+ });
2016
+ } else {
2017
+ if (typeof key === "function") key = keysFromSelector(key, {
2018
+ ...this.options,
2019
+ ...opts
2020
+ });
2021
+ resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
2022
+ }
2023
+ return this.t(resultKey, o);
2024
+ };
2025
+ if (isString(lng)) {
2026
+ fixedT.lng = lng;
2027
+ } else {
2028
+ fixedT.lngs = lng;
2029
+ }
2030
+ fixedT.ns = ns;
2031
+ fixedT.keyPrefix = keyPrefix;
2032
+ return fixedT;
2033
+ }
2034
+ t(...args) {
2035
+ return this.translator?.translate(...args);
2036
+ }
2037
+ exists(...args) {
2038
+ return this.translator?.exists(...args);
2039
+ }
2040
+ setDefaultNamespace(ns) {
2041
+ this.options.defaultNS = ns;
2042
+ }
2043
+ hasLoadedNamespace(ns, options = {}) {
2044
+ if (!this.isInitialized) {
2045
+ this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
2046
+ return false;
2047
+ }
2048
+ if (!this.languages || !this.languages.length) {
2049
+ this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
2050
+ return false;
2051
+ }
2052
+ const lng = options.lng || this.resolvedLanguage || this.languages[0];
2053
+ const fallbackLng = this.options ? this.options.fallbackLng : false;
2054
+ const lastLng = this.languages[this.languages.length - 1];
2055
+ if (lng.toLowerCase() === "cimode") return true;
2056
+ const loadNotPending = (l, n) => {
2057
+ const loadState = this.services.backendConnector.state[`${l}|${n}`];
2058
+ return loadState === -1 || loadState === 0 || loadState === 2;
2059
+ };
2060
+ if (options.precheck) {
2061
+ const preResult = options.precheck(this, loadNotPending);
2062
+ if (preResult !== void 0) return preResult;
2063
+ }
2064
+ if (this.hasResourceBundle(lng, ns)) return true;
2065
+ if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
2066
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
2067
+ return false;
2068
+ }
2069
+ loadNamespaces(ns, callback) {
2070
+ const deferred = defer();
2071
+ if (!this.options.ns) {
2072
+ if (callback) callback();
2073
+ return Promise.resolve();
2074
+ }
2075
+ if (isString(ns)) ns = [ns];
2076
+ ns.forEach((n) => {
2077
+ if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
2078
+ });
2079
+ this.loadResources((err) => {
2080
+ deferred.resolve();
2081
+ if (callback) callback(err);
2082
+ });
2083
+ return deferred;
2084
+ }
2085
+ loadLanguages(lngs, callback) {
2086
+ const deferred = defer();
2087
+ if (isString(lngs)) lngs = [lngs];
2088
+ const preloaded = this.options.preload || [];
2089
+ const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
2090
+ if (!newLngs.length) {
2091
+ if (callback) callback();
2092
+ return Promise.resolve();
2093
+ }
2094
+ this.options.preload = preloaded.concat(newLngs);
2095
+ this.loadResources((err) => {
2096
+ deferred.resolve();
2097
+ if (callback) callback(err);
2098
+ });
2099
+ return deferred;
2100
+ }
2101
+ dir(lng) {
2102
+ if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
2103
+ if (!lng) return "rtl";
2104
+ try {
2105
+ const l = new Intl.Locale(lng);
2106
+ if (l && l.getTextInfo) {
2107
+ const ti = l.getTextInfo();
2108
+ if (ti && ti.direction) return ti.direction;
2109
+ }
2110
+ } catch (e) {
2111
+ }
2112
+ const rtlLngs = ["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"];
2113
+ const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
2114
+ if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
2115
+ return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
2116
+ }
2117
+ static createInstance(options = {}, callback) {
2118
+ const instance2 = new I18n(options, callback);
2119
+ instance2.createInstance = I18n.createInstance;
2120
+ return instance2;
2121
+ }
2122
+ cloneInstance(options = {}, callback = noop) {
2123
+ const forkResourceStore = options.forkResourceStore;
2124
+ if (forkResourceStore) delete options.forkResourceStore;
2125
+ const mergedOptions = {
2126
+ ...this.options,
2127
+ ...options,
2128
+ ...{
2129
+ isClone: true
2130
+ }
2131
+ };
2132
+ const clone = new I18n(mergedOptions);
2133
+ if (options.debug !== void 0 || options.prefix !== void 0) {
2134
+ clone.logger = clone.logger.clone(options);
2135
+ }
2136
+ const membersToCopy = ["store", "services", "language"];
2137
+ membersToCopy.forEach((m) => {
2138
+ clone[m] = this[m];
2139
+ });
2140
+ clone.services = {
2141
+ ...this.services
2142
+ };
2143
+ clone.services.utils = {
2144
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2145
+ };
2146
+ if (forkResourceStore) {
2147
+ const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
2148
+ prev[l] = {
2149
+ ...this.store.data[l]
2150
+ };
2151
+ prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
2152
+ acc[n] = {
2153
+ ...prev[l][n]
2154
+ };
2155
+ return acc;
2156
+ }, prev[l]);
2157
+ return prev;
2158
+ }, {});
2159
+ clone.store = new ResourceStore(clonedData, mergedOptions);
2160
+ clone.services.resourceStore = clone.store;
2161
+ }
2162
+ if (options.interpolation) clone.services.interpolator = new Interpolator(mergedOptions);
2163
+ clone.translator = new Translator(clone.services, mergedOptions);
2164
+ clone.translator.on("*", (event, ...args) => {
2165
+ clone.emit(event, ...args);
2166
+ });
2167
+ clone.init(mergedOptions, callback);
2168
+ clone.translator.options = mergedOptions;
2169
+ clone.translator.backendConnector.services.utils = {
2170
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2171
+ };
2172
+ return clone;
2173
+ }
2174
+ toJSON() {
2175
+ return {
2176
+ options: this.options,
2177
+ store: this.store,
2178
+ language: this.language,
2179
+ languages: this.languages,
2180
+ resolvedLanguage: this.resolvedLanguage
2181
+ };
2182
+ }
2183
+ }
2184
+ const instance = I18n.createInstance();
2185
+ instance.createInstance;
2186
+ instance.dir;
2187
+ instance.init;
2188
+ instance.loadResources;
2189
+ instance.reloadResources;
2190
+ instance.use;
2191
+ instance.changeLanguage;
2192
+ instance.getFixedT;
2193
+ const t = instance.t;
2194
+ instance.exists;
2195
+ instance.setDefaultNamespace;
2196
+ instance.hasLoadedNamespace;
2197
+ instance.loadNamespaces;
2198
+ instance.loadLanguages;
2199
+ export {
2200
+ instance as i,
2201
+ t
2202
+ };
2203
+ //# sourceMappingURL=i18next-Dx0Bahhj.js.map