@bigbinary/neeto-api-keys-frontend 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,4 @@
1
- import i18n, { t } from 'i18next';
2
- import { initReactI18next, useTranslation, Trans } from 'react-i18next';
3
- import React, { useRef, useState, useEffect } from 'react';
1
+ import React, { createElement, isValidElement, cloneElement, createContext, useContext, useState, useRef, useEffect } from 'react';
4
2
  import { DEFAULT_PAGE_INDEX, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
5
3
  import { isPresent, isNotPresent, isNotEmpty } from '@bigbinary/neeto-commons-frontend/pure';
6
4
  import { useMutationWithInvalidation, useDebounce, withTitle } from '@bigbinary/neeto-commons-frontend/react-utils';
@@ -18,6 +16,2846 @@ import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
18
16
  import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
19
17
  import { useHistory } from 'react-router-dom';
20
18
 
19
+ const consoleLogger = {
20
+ type: 'logger',
21
+ log(args) {
22
+ this.output('log', args);
23
+ },
24
+ warn(args) {
25
+ this.output('warn', args);
26
+ },
27
+ error(args) {
28
+ this.output('error', args);
29
+ },
30
+ output(type, args) {
31
+ if (console && console[type]) console[type].apply(console, args);
32
+ }
33
+ };
34
+ class Logger {
35
+ constructor(concreteLogger) {
36
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
37
+ this.init(concreteLogger, options);
38
+ }
39
+ init(concreteLogger) {
40
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
41
+ this.prefix = options.prefix || 'i18next:';
42
+ this.logger = concreteLogger || consoleLogger;
43
+ this.options = options;
44
+ this.debug = options.debug;
45
+ }
46
+ log() {
47
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
48
+ args[_key] = arguments[_key];
49
+ }
50
+ return this.forward(args, 'log', '', true);
51
+ }
52
+ warn() {
53
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
54
+ args[_key2] = arguments[_key2];
55
+ }
56
+ return this.forward(args, 'warn', '', true);
57
+ }
58
+ error() {
59
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
60
+ args[_key3] = arguments[_key3];
61
+ }
62
+ return this.forward(args, 'error', '');
63
+ }
64
+ deprecate() {
65
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
66
+ args[_key4] = arguments[_key4];
67
+ }
68
+ return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
69
+ }
70
+ forward(args, lvl, prefix, debugOnly) {
71
+ if (debugOnly && !this.debug) return null;
72
+ if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
73
+ return this.logger[lvl](args);
74
+ }
75
+ create(moduleName) {
76
+ return new Logger(this.logger, {
77
+ ...{
78
+ prefix: `${this.prefix}:${moduleName}:`
79
+ },
80
+ ...this.options
81
+ });
82
+ }
83
+ clone(options) {
84
+ options = options || this.options;
85
+ options.prefix = options.prefix || this.prefix;
86
+ return new Logger(this.logger, options);
87
+ }
88
+ }
89
+ var baseLogger = new Logger();
90
+
91
+ class EventEmitter {
92
+ constructor() {
93
+ this.observers = {};
94
+ }
95
+ on(events, listener) {
96
+ events.split(' ').forEach(event => {
97
+ this.observers[event] = this.observers[event] || [];
98
+ this.observers[event].push(listener);
99
+ });
100
+ return this;
101
+ }
102
+ off(event, listener) {
103
+ if (!this.observers[event]) return;
104
+ if (!listener) {
105
+ delete this.observers[event];
106
+ return;
107
+ }
108
+ this.observers[event] = this.observers[event].filter(l => l !== listener);
109
+ }
110
+ emit(event) {
111
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
112
+ args[_key - 1] = arguments[_key];
113
+ }
114
+ if (this.observers[event]) {
115
+ const cloned = [].concat(this.observers[event]);
116
+ cloned.forEach(observer => {
117
+ observer(...args);
118
+ });
119
+ }
120
+ if (this.observers['*']) {
121
+ const cloned = [].concat(this.observers['*']);
122
+ cloned.forEach(observer => {
123
+ observer.apply(observer, [event, ...args]);
124
+ });
125
+ }
126
+ }
127
+ }
128
+
129
+ function defer() {
130
+ let res;
131
+ let rej;
132
+ const promise = new Promise((resolve, reject) => {
133
+ res = resolve;
134
+ rej = reject;
135
+ });
136
+ promise.resolve = res;
137
+ promise.reject = rej;
138
+ return promise;
139
+ }
140
+ function makeString(object) {
141
+ if (object == null) return '';
142
+ return '' + object;
143
+ }
144
+ function copy(a, s, t) {
145
+ a.forEach(m => {
146
+ if (s[m]) t[m] = s[m];
147
+ });
148
+ }
149
+ function getLastOfPath(object, path, Empty) {
150
+ function cleanKey(key) {
151
+ return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
152
+ }
153
+ function canNotTraverseDeeper() {
154
+ return !object || typeof object === 'string';
155
+ }
156
+ const stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
157
+ while (stack.length > 1) {
158
+ if (canNotTraverseDeeper()) return {};
159
+ const key = cleanKey(stack.shift());
160
+ if (!object[key] && Empty) object[key] = new Empty();
161
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
162
+ object = object[key];
163
+ } else {
164
+ object = {};
165
+ }
166
+ }
167
+ if (canNotTraverseDeeper()) return {};
168
+ return {
169
+ obj: object,
170
+ k: cleanKey(stack.shift())
171
+ };
172
+ }
173
+ function setPath(object, path, newValue) {
174
+ const {
175
+ obj,
176
+ k
177
+ } = getLastOfPath(object, path, Object);
178
+ obj[k] = newValue;
179
+ }
180
+ function pushPath(object, path, newValue, concat) {
181
+ const {
182
+ obj,
183
+ k
184
+ } = getLastOfPath(object, path, Object);
185
+ obj[k] = obj[k] || [];
186
+ if (concat) obj[k] = obj[k].concat(newValue);
187
+ if (!concat) obj[k].push(newValue);
188
+ }
189
+ function getPath(object, path) {
190
+ const {
191
+ obj,
192
+ k
193
+ } = getLastOfPath(object, path);
194
+ if (!obj) return undefined;
195
+ return obj[k];
196
+ }
197
+ function getPathWithDefaults(data, defaultData, key) {
198
+ const value = getPath(data, key);
199
+ if (value !== undefined) {
200
+ return value;
201
+ }
202
+ return getPath(defaultData, key);
203
+ }
204
+ function deepExtend(target, source, overwrite) {
205
+ for (const prop in source) {
206
+ if (prop !== '__proto__' && prop !== 'constructor') {
207
+ if (prop in target) {
208
+ if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
209
+ if (overwrite) target[prop] = source[prop];
210
+ } else {
211
+ deepExtend(target[prop], source[prop], overwrite);
212
+ }
213
+ } else {
214
+ target[prop] = source[prop];
215
+ }
216
+ }
217
+ }
218
+ return target;
219
+ }
220
+ function regexEscape(str) {
221
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
222
+ }
223
+ var _entityMap = {
224
+ '&': '&amp;',
225
+ '<': '&lt;',
226
+ '>': '&gt;',
227
+ '"': '&quot;',
228
+ "'": '&#39;',
229
+ '/': '&#x2F;'
230
+ };
231
+ function escape(data) {
232
+ if (typeof data === 'string') {
233
+ return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
234
+ }
235
+ return data;
236
+ }
237
+ const chars = [' ', ',', '?', '!', ';'];
238
+ function looksLikeObjectPath(key, nsSeparator, keySeparator) {
239
+ nsSeparator = nsSeparator || '';
240
+ keySeparator = keySeparator || '';
241
+ const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
242
+ if (possibleChars.length === 0) return true;
243
+ const r = new RegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
244
+ let matched = !r.test(key);
245
+ if (!matched) {
246
+ const ki = key.indexOf(keySeparator);
247
+ if (ki > 0 && !r.test(key.substring(0, ki))) {
248
+ matched = true;
249
+ }
250
+ }
251
+ return matched;
252
+ }
253
+ function deepFind(obj, path) {
254
+ let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
255
+ if (!obj) return undefined;
256
+ if (obj[path]) return obj[path];
257
+ const paths = path.split(keySeparator);
258
+ let current = obj;
259
+ for (let i = 0; i < paths.length; ++i) {
260
+ if (!current) return undefined;
261
+ if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
262
+ return undefined;
263
+ }
264
+ if (current[paths[i]] === undefined) {
265
+ let j = 2;
266
+ let p = paths.slice(i, i + j).join(keySeparator);
267
+ let mix = current[p];
268
+ while (mix === undefined && paths.length > i + j) {
269
+ j++;
270
+ p = paths.slice(i, i + j).join(keySeparator);
271
+ mix = current[p];
272
+ }
273
+ if (mix === undefined) return undefined;
274
+ if (mix === null) return null;
275
+ if (path.endsWith(p)) {
276
+ if (typeof mix === 'string') return mix;
277
+ if (p && typeof mix[p] === 'string') return mix[p];
278
+ }
279
+ const joinedPath = paths.slice(i + j).join(keySeparator);
280
+ if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
281
+ return undefined;
282
+ }
283
+ current = current[paths[i]];
284
+ }
285
+ return current;
286
+ }
287
+ function getCleanedCode(code) {
288
+ if (code && code.indexOf('_') > 0) return code.replace('_', '-');
289
+ return code;
290
+ }
291
+
292
+ class ResourceStore extends EventEmitter {
293
+ constructor(data) {
294
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
295
+ ns: ['translation'],
296
+ defaultNS: 'translation'
297
+ };
298
+ super();
299
+ this.data = data || {};
300
+ this.options = options;
301
+ if (this.options.keySeparator === undefined) {
302
+ this.options.keySeparator = '.';
303
+ }
304
+ if (this.options.ignoreJSONStructure === undefined) {
305
+ this.options.ignoreJSONStructure = true;
306
+ }
307
+ }
308
+ addNamespaces(ns) {
309
+ if (this.options.ns.indexOf(ns) < 0) {
310
+ this.options.ns.push(ns);
311
+ }
312
+ }
313
+ removeNamespaces(ns) {
314
+ const index = this.options.ns.indexOf(ns);
315
+ if (index > -1) {
316
+ this.options.ns.splice(index, 1);
317
+ }
318
+ }
319
+ getResource(lng, ns, key) {
320
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
321
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
322
+ const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
323
+ let path = [lng, ns];
324
+ if (key && typeof key !== 'string') path = path.concat(key);
325
+ if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
326
+ if (lng.indexOf('.') > -1) {
327
+ path = lng.split('.');
328
+ }
329
+ const result = getPath(this.data, path);
330
+ if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
331
+ return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
332
+ }
333
+ addResource(lng, ns, key, value) {
334
+ let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
335
+ silent: false
336
+ };
337
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
338
+ let path = [lng, ns];
339
+ if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
340
+ if (lng.indexOf('.') > -1) {
341
+ path = lng.split('.');
342
+ value = ns;
343
+ ns = path[1];
344
+ }
345
+ this.addNamespaces(ns);
346
+ setPath(this.data, path, value);
347
+ if (!options.silent) this.emit('added', lng, ns, key, value);
348
+ }
349
+ addResources(lng, ns, resources) {
350
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
351
+ silent: false
352
+ };
353
+ for (const m in resources) {
354
+ if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
355
+ silent: true
356
+ });
357
+ }
358
+ if (!options.silent) this.emit('added', lng, ns, resources);
359
+ }
360
+ addResourceBundle(lng, ns, resources, deep, overwrite) {
361
+ let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
362
+ silent: false
363
+ };
364
+ let path = [lng, ns];
365
+ if (lng.indexOf('.') > -1) {
366
+ path = lng.split('.');
367
+ deep = resources;
368
+ resources = ns;
369
+ ns = path[1];
370
+ }
371
+ this.addNamespaces(ns);
372
+ let pack = getPath(this.data, path) || {};
373
+ if (deep) {
374
+ deepExtend(pack, resources, overwrite);
375
+ } else {
376
+ pack = {
377
+ ...pack,
378
+ ...resources
379
+ };
380
+ }
381
+ setPath(this.data, path, pack);
382
+ if (!options.silent) this.emit('added', lng, ns, resources);
383
+ }
384
+ removeResourceBundle(lng, ns) {
385
+ if (this.hasResourceBundle(lng, ns)) {
386
+ delete this.data[lng][ns];
387
+ }
388
+ this.removeNamespaces(ns);
389
+ this.emit('removed', lng, ns);
390
+ }
391
+ hasResourceBundle(lng, ns) {
392
+ return this.getResource(lng, ns) !== undefined;
393
+ }
394
+ getResourceBundle(lng, ns) {
395
+ if (!ns) ns = this.options.defaultNS;
396
+ if (this.options.compatibilityAPI === 'v1') return {
397
+ ...{},
398
+ ...this.getResource(lng, ns)
399
+ };
400
+ return this.getResource(lng, ns);
401
+ }
402
+ getDataByLanguage(lng) {
403
+ return this.data[lng];
404
+ }
405
+ hasLanguageSomeTranslations(lng) {
406
+ const data = this.getDataByLanguage(lng);
407
+ const n = data && Object.keys(data) || [];
408
+ return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
409
+ }
410
+ toJSON() {
411
+ return this.data;
412
+ }
413
+ }
414
+
415
+ var postProcessor = {
416
+ processors: {},
417
+ addPostProcessor(module) {
418
+ this.processors[module.name] = module;
419
+ },
420
+ handle(processors, value, key, options, translator) {
421
+ processors.forEach(processor => {
422
+ if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
423
+ });
424
+ return value;
425
+ }
426
+ };
427
+
428
+ const checkedLoadedFor = {};
429
+ class Translator extends EventEmitter {
430
+ constructor(services) {
431
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
432
+ super();
433
+ copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
434
+ this.options = options;
435
+ if (this.options.keySeparator === undefined) {
436
+ this.options.keySeparator = '.';
437
+ }
438
+ this.logger = baseLogger.create('translator');
439
+ }
440
+ changeLanguage(lng) {
441
+ if (lng) this.language = lng;
442
+ }
443
+ exists(key) {
444
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
445
+ interpolation: {}
446
+ };
447
+ if (key === undefined || key === null) {
448
+ return false;
449
+ }
450
+ const resolved = this.resolve(key, options);
451
+ return resolved && resolved.res !== undefined;
452
+ }
453
+ extractFromKey(key, options) {
454
+ let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
455
+ if (nsSeparator === undefined) nsSeparator = ':';
456
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
457
+ let namespaces = options.ns || this.options.defaultNS || [];
458
+ const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
459
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
460
+ if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
461
+ const m = key.match(this.interpolator.nestingRegexp);
462
+ if (m && m.length > 0) {
463
+ return {
464
+ key,
465
+ namespaces
466
+ };
467
+ }
468
+ const parts = key.split(nsSeparator);
469
+ if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
470
+ key = parts.join(keySeparator);
471
+ }
472
+ if (typeof namespaces === 'string') namespaces = [namespaces];
473
+ return {
474
+ key,
475
+ namespaces
476
+ };
477
+ }
478
+ translate(keys, options, lastKey) {
479
+ if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
480
+ options = this.options.overloadTranslationOptionHandler(arguments);
481
+ }
482
+ if (typeof options === 'object') options = {
483
+ ...options
484
+ };
485
+ if (!options) options = {};
486
+ if (keys === undefined || keys === null) return '';
487
+ if (!Array.isArray(keys)) keys = [String(keys)];
488
+ const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
489
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
490
+ const {
491
+ key,
492
+ namespaces
493
+ } = this.extractFromKey(keys[keys.length - 1], options);
494
+ const namespace = namespaces[namespaces.length - 1];
495
+ const lng = options.lng || this.language;
496
+ const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
497
+ if (lng && lng.toLowerCase() === 'cimode') {
498
+ if (appendNamespaceToCIMode) {
499
+ const nsSeparator = options.nsSeparator || this.options.nsSeparator;
500
+ if (returnDetails) {
501
+ return {
502
+ res: `${namespace}${nsSeparator}${key}`,
503
+ usedKey: key,
504
+ exactUsedKey: key,
505
+ usedLng: lng,
506
+ usedNS: namespace
507
+ };
508
+ }
509
+ return `${namespace}${nsSeparator}${key}`;
510
+ }
511
+ if (returnDetails) {
512
+ return {
513
+ res: key,
514
+ usedKey: key,
515
+ exactUsedKey: key,
516
+ usedLng: lng,
517
+ usedNS: namespace
518
+ };
519
+ }
520
+ return key;
521
+ }
522
+ const resolved = this.resolve(keys, options);
523
+ let res = resolved && resolved.res;
524
+ const resUsedKey = resolved && resolved.usedKey || key;
525
+ const resExactUsedKey = resolved && resolved.exactUsedKey || key;
526
+ const resType = Object.prototype.toString.apply(res);
527
+ const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
528
+ const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
529
+ const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
530
+ const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
531
+ if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
532
+ if (!options.returnObjects && !this.options.returnObjects) {
533
+ if (!this.options.returnedObjectHandler) {
534
+ this.logger.warn('accessing an object - but returnObjects options is not enabled!');
535
+ }
536
+ const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
537
+ ...options,
538
+ ns: namespaces
539
+ }) : `key '${key} (${this.language})' returned an object instead of string.`;
540
+ if (returnDetails) {
541
+ resolved.res = r;
542
+ return resolved;
543
+ }
544
+ return r;
545
+ }
546
+ if (keySeparator) {
547
+ const resTypeIsArray = resType === '[object Array]';
548
+ const copy = resTypeIsArray ? [] : {};
549
+ const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
550
+ for (const m in res) {
551
+ if (Object.prototype.hasOwnProperty.call(res, m)) {
552
+ const deepKey = `${newKeyToUse}${keySeparator}${m}`;
553
+ copy[m] = this.translate(deepKey, {
554
+ ...options,
555
+ ...{
556
+ joinArrays: false,
557
+ ns: namespaces
558
+ }
559
+ });
560
+ if (copy[m] === deepKey) copy[m] = res[m];
561
+ }
562
+ }
563
+ res = copy;
564
+ }
565
+ } else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
566
+ res = res.join(joinArrays);
567
+ if (res) res = this.extendTranslation(res, keys, options, lastKey);
568
+ } else {
569
+ let usedDefault = false;
570
+ let usedKey = false;
571
+ const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
572
+ const hasDefaultValue = Translator.hasDefaultValue(options);
573
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
574
+ const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
575
+ ordinal: false
576
+ }) : '';
577
+ const defaultValue = options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
578
+ if (!this.isValidLookup(res) && hasDefaultValue) {
579
+ usedDefault = true;
580
+ res = defaultValue;
581
+ }
582
+ if (!this.isValidLookup(res)) {
583
+ usedKey = true;
584
+ res = key;
585
+ }
586
+ const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
587
+ const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
588
+ const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
589
+ if (usedKey || usedDefault || updateMissing) {
590
+ this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
591
+ if (keySeparator) {
592
+ const fk = this.resolve(key, {
593
+ ...options,
594
+ keySeparator: false
595
+ });
596
+ 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.');
597
+ }
598
+ let lngs = [];
599
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
600
+ if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
601
+ for (let i = 0; i < fallbackLngs.length; i++) {
602
+ lngs.push(fallbackLngs[i]);
603
+ }
604
+ } else if (this.options.saveMissingTo === 'all') {
605
+ lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
606
+ } else {
607
+ lngs.push(options.lng || this.language);
608
+ }
609
+ const send = (l, k, specificDefaultValue) => {
610
+ const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
611
+ if (this.options.missingKeyHandler) {
612
+ this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
613
+ } else if (this.backendConnector && this.backendConnector.saveMissing) {
614
+ this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
615
+ }
616
+ this.emit('missingKey', l, namespace, k, res);
617
+ };
618
+ if (this.options.saveMissing) {
619
+ if (this.options.saveMissingPlurals && needsPluralHandling) {
620
+ lngs.forEach(language => {
621
+ this.pluralResolver.getSuffixes(language, options).forEach(suffix => {
622
+ send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
623
+ });
624
+ });
625
+ } else {
626
+ send(lngs, key, defaultValue);
627
+ }
628
+ }
629
+ }
630
+ res = this.extendTranslation(res, keys, options, resolved, lastKey);
631
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
632
+ if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
633
+ if (this.options.compatibilityAPI !== 'v1') {
634
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
635
+ } else {
636
+ res = this.options.parseMissingKeyHandler(res);
637
+ }
638
+ }
639
+ }
640
+ if (returnDetails) {
641
+ resolved.res = res;
642
+ return resolved;
643
+ }
644
+ return res;
645
+ }
646
+ extendTranslation(res, key, options, resolved, lastKey) {
647
+ var _this = this;
648
+ if (this.i18nFormat && this.i18nFormat.parse) {
649
+ res = this.i18nFormat.parse(res, {
650
+ ...this.options.interpolation.defaultVariables,
651
+ ...options
652
+ }, resolved.usedLng, resolved.usedNS, resolved.usedKey, {
653
+ resolved
654
+ });
655
+ } else if (!options.skipInterpolation) {
656
+ if (options.interpolation) this.interpolator.init({
657
+ ...options,
658
+ ...{
659
+ interpolation: {
660
+ ...this.options.interpolation,
661
+ ...options.interpolation
662
+ }
663
+ }
664
+ });
665
+ const skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
666
+ let nestBef;
667
+ if (skipOnVariables) {
668
+ const nb = res.match(this.interpolator.nestingRegexp);
669
+ nestBef = nb && nb.length;
670
+ }
671
+ let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
672
+ if (this.options.interpolation.defaultVariables) data = {
673
+ ...this.options.interpolation.defaultVariables,
674
+ ...data
675
+ };
676
+ res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
677
+ if (skipOnVariables) {
678
+ const na = res.match(this.interpolator.nestingRegexp);
679
+ const nestAft = na && na.length;
680
+ if (nestBef < nestAft) options.nest = false;
681
+ }
682
+ if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
683
+ if (options.nest !== false) res = this.interpolator.nest(res, function () {
684
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
685
+ args[_key] = arguments[_key];
686
+ }
687
+ if (lastKey && lastKey[0] === args[0] && !options.context) {
688
+ _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
689
+ return null;
690
+ }
691
+ return _this.translate(...args, key);
692
+ }, options);
693
+ if (options.interpolation) this.interpolator.reset();
694
+ }
695
+ const postProcess = options.postProcess || this.options.postProcess;
696
+ const postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
697
+ if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
698
+ res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
699
+ i18nResolved: resolved,
700
+ ...options
701
+ } : options, this);
702
+ }
703
+ return res;
704
+ }
705
+ resolve(keys) {
706
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
707
+ let found;
708
+ let usedKey;
709
+ let exactUsedKey;
710
+ let usedLng;
711
+ let usedNS;
712
+ if (typeof keys === 'string') keys = [keys];
713
+ keys.forEach(k => {
714
+ if (this.isValidLookup(found)) return;
715
+ const extracted = this.extractFromKey(k, options);
716
+ const key = extracted.key;
717
+ usedKey = key;
718
+ let namespaces = extracted.namespaces;
719
+ if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
720
+ const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
721
+ const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
722
+ const needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
723
+ const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
724
+ namespaces.forEach(ns => {
725
+ if (this.isValidLookup(found)) return;
726
+ usedNS = ns;
727
+ if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
728
+ checkedLoadedFor[`${codes[0]}-${ns}`] = true;
729
+ 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!!!');
730
+ }
731
+ codes.forEach(code => {
732
+ if (this.isValidLookup(found)) return;
733
+ usedLng = code;
734
+ const finalKeys = [key];
735
+ if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
736
+ this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
737
+ } else {
738
+ let pluralSuffix;
739
+ if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
740
+ const zeroSuffix = `${this.options.pluralSeparator}zero`;
741
+ const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
742
+ if (needsPluralHandling) {
743
+ finalKeys.push(key + pluralSuffix);
744
+ if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
745
+ finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
746
+ }
747
+ if (needsZeroSuffixLookup) {
748
+ finalKeys.push(key + zeroSuffix);
749
+ }
750
+ }
751
+ if (needsContextHandling) {
752
+ const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
753
+ finalKeys.push(contextKey);
754
+ if (needsPluralHandling) {
755
+ finalKeys.push(contextKey + pluralSuffix);
756
+ if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
757
+ finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
758
+ }
759
+ if (needsZeroSuffixLookup) {
760
+ finalKeys.push(contextKey + zeroSuffix);
761
+ }
762
+ }
763
+ }
764
+ }
765
+ let possibleKey;
766
+ while (possibleKey = finalKeys.pop()) {
767
+ if (!this.isValidLookup(found)) {
768
+ exactUsedKey = possibleKey;
769
+ found = this.getResource(code, ns, possibleKey, options);
770
+ }
771
+ }
772
+ });
773
+ });
774
+ });
775
+ return {
776
+ res: found,
777
+ usedKey,
778
+ exactUsedKey,
779
+ usedLng,
780
+ usedNS
781
+ };
782
+ }
783
+ isValidLookup(res) {
784
+ return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
785
+ }
786
+ getResource(code, ns, key) {
787
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
788
+ if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
789
+ return this.resourceStore.getResource(code, ns, key, options);
790
+ }
791
+ static hasDefaultValue(options) {
792
+ const prefix = 'defaultValue';
793
+ for (const option in options) {
794
+ if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
795
+ return true;
796
+ }
797
+ }
798
+ return false;
799
+ }
800
+ }
801
+
802
+ function capitalize(string) {
803
+ return string.charAt(0).toUpperCase() + string.slice(1);
804
+ }
805
+ class LanguageUtil {
806
+ constructor(options) {
807
+ this.options = options;
808
+ this.supportedLngs = this.options.supportedLngs || false;
809
+ this.logger = baseLogger.create('languageUtils');
810
+ }
811
+ getScriptPartFromCode(code) {
812
+ code = getCleanedCode(code);
813
+ if (!code || code.indexOf('-') < 0) return null;
814
+ const p = code.split('-');
815
+ if (p.length === 2) return null;
816
+ p.pop();
817
+ if (p[p.length - 1].toLowerCase() === 'x') return null;
818
+ return this.formatLanguageCode(p.join('-'));
819
+ }
820
+ getLanguagePartFromCode(code) {
821
+ code = getCleanedCode(code);
822
+ if (!code || code.indexOf('-') < 0) return code;
823
+ const p = code.split('-');
824
+ return this.formatLanguageCode(p[0]);
825
+ }
826
+ formatLanguageCode(code) {
827
+ if (typeof code === 'string' && code.indexOf('-') > -1) {
828
+ const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
829
+ let p = code.split('-');
830
+ if (this.options.lowerCaseLng) {
831
+ p = p.map(part => part.toLowerCase());
832
+ } else if (p.length === 2) {
833
+ p[0] = p[0].toLowerCase();
834
+ p[1] = p[1].toUpperCase();
835
+ if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
836
+ } else if (p.length === 3) {
837
+ p[0] = p[0].toLowerCase();
838
+ if (p[1].length === 2) p[1] = p[1].toUpperCase();
839
+ if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
840
+ if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
841
+ if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
842
+ }
843
+ return p.join('-');
844
+ }
845
+ return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
846
+ }
847
+ isSupportedCode(code) {
848
+ if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
849
+ code = this.getLanguagePartFromCode(code);
850
+ }
851
+ return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
852
+ }
853
+ getBestMatchFromCodes(codes) {
854
+ if (!codes) return null;
855
+ let found;
856
+ codes.forEach(code => {
857
+ if (found) return;
858
+ const cleanedLng = this.formatLanguageCode(code);
859
+ if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
860
+ });
861
+ if (!found && this.options.supportedLngs) {
862
+ codes.forEach(code => {
863
+ if (found) return;
864
+ const lngOnly = this.getLanguagePartFromCode(code);
865
+ if (this.isSupportedCode(lngOnly)) return found = lngOnly;
866
+ found = this.options.supportedLngs.find(supportedLng => {
867
+ if (supportedLng === lngOnly) return supportedLng;
868
+ if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
869
+ if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
870
+ });
871
+ });
872
+ }
873
+ if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
874
+ return found;
875
+ }
876
+ getFallbackCodes(fallbacks, code) {
877
+ if (!fallbacks) return [];
878
+ if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
879
+ if (typeof fallbacks === 'string') fallbacks = [fallbacks];
880
+ if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
881
+ if (!code) return fallbacks.default || [];
882
+ let found = fallbacks[code];
883
+ if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
884
+ if (!found) found = fallbacks[this.formatLanguageCode(code)];
885
+ if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
886
+ if (!found) found = fallbacks.default;
887
+ return found || [];
888
+ }
889
+ toResolveHierarchy(code, fallbackCode) {
890
+ const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
891
+ const codes = [];
892
+ const addCode = c => {
893
+ if (!c) return;
894
+ if (this.isSupportedCode(c)) {
895
+ codes.push(c);
896
+ } else {
897
+ this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
898
+ }
899
+ };
900
+ if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
901
+ if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
902
+ if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
903
+ if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
904
+ } else if (typeof code === 'string') {
905
+ addCode(this.formatLanguageCode(code));
906
+ }
907
+ fallbackCodes.forEach(fc => {
908
+ if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
909
+ });
910
+ return codes;
911
+ }
912
+ }
913
+
914
+ let sets = [{
915
+ lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
916
+ nr: [1, 2],
917
+ fc: 1
918
+ }, {
919
+ lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'hi', 'hu', 'hy', 'ia', 'it', 'kk', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt-PT', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'],
920
+ nr: [1, 2],
921
+ fc: 2
922
+ }, {
923
+ lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
924
+ nr: [1],
925
+ fc: 3
926
+ }, {
927
+ lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
928
+ nr: [1, 2, 5],
929
+ fc: 4
930
+ }, {
931
+ lngs: ['ar'],
932
+ nr: [0, 1, 2, 3, 11, 100],
933
+ fc: 5
934
+ }, {
935
+ lngs: ['cs', 'sk'],
936
+ nr: [1, 2, 5],
937
+ fc: 6
938
+ }, {
939
+ lngs: ['csb', 'pl'],
940
+ nr: [1, 2, 5],
941
+ fc: 7
942
+ }, {
943
+ lngs: ['cy'],
944
+ nr: [1, 2, 3, 8],
945
+ fc: 8
946
+ }, {
947
+ lngs: ['fr'],
948
+ nr: [1, 2],
949
+ fc: 9
950
+ }, {
951
+ lngs: ['ga'],
952
+ nr: [1, 2, 3, 7, 11],
953
+ fc: 10
954
+ }, {
955
+ lngs: ['gd'],
956
+ nr: [1, 2, 3, 20],
957
+ fc: 11
958
+ }, {
959
+ lngs: ['is'],
960
+ nr: [1, 2],
961
+ fc: 12
962
+ }, {
963
+ lngs: ['jv'],
964
+ nr: [0, 1],
965
+ fc: 13
966
+ }, {
967
+ lngs: ['kw'],
968
+ nr: [1, 2, 3, 4],
969
+ fc: 14
970
+ }, {
971
+ lngs: ['lt'],
972
+ nr: [1, 2, 10],
973
+ fc: 15
974
+ }, {
975
+ lngs: ['lv'],
976
+ nr: [1, 2, 0],
977
+ fc: 16
978
+ }, {
979
+ lngs: ['mk'],
980
+ nr: [1, 2],
981
+ fc: 17
982
+ }, {
983
+ lngs: ['mnk'],
984
+ nr: [0, 1, 2],
985
+ fc: 18
986
+ }, {
987
+ lngs: ['mt'],
988
+ nr: [1, 2, 11, 20],
989
+ fc: 19
990
+ }, {
991
+ lngs: ['or'],
992
+ nr: [2, 1],
993
+ fc: 2
994
+ }, {
995
+ lngs: ['ro'],
996
+ nr: [1, 2, 20],
997
+ fc: 20
998
+ }, {
999
+ lngs: ['sl'],
1000
+ nr: [5, 1, 2, 3],
1001
+ fc: 21
1002
+ }, {
1003
+ lngs: ['he', 'iw'],
1004
+ nr: [1, 2, 20, 21],
1005
+ fc: 22
1006
+ }];
1007
+ let _rulesPluralsTypes = {
1008
+ 1: function (n) {
1009
+ return Number(n > 1);
1010
+ },
1011
+ 2: function (n) {
1012
+ return Number(n != 1);
1013
+ },
1014
+ 3: function (n) {
1015
+ return 0;
1016
+ },
1017
+ 4: function (n) {
1018
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
1019
+ },
1020
+ 5: function (n) {
1021
+ return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
1022
+ },
1023
+ 6: function (n) {
1024
+ return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
1025
+ },
1026
+ 7: function (n) {
1027
+ return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
1028
+ },
1029
+ 8: function (n) {
1030
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
1031
+ },
1032
+ 9: function (n) {
1033
+ return Number(n >= 2);
1034
+ },
1035
+ 10: function (n) {
1036
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
1037
+ },
1038
+ 11: function (n) {
1039
+ return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
1040
+ },
1041
+ 12: function (n) {
1042
+ return Number(n % 10 != 1 || n % 100 == 11);
1043
+ },
1044
+ 13: function (n) {
1045
+ return Number(n !== 0);
1046
+ },
1047
+ 14: function (n) {
1048
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
1049
+ },
1050
+ 15: function (n) {
1051
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
1052
+ },
1053
+ 16: function (n) {
1054
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
1055
+ },
1056
+ 17: function (n) {
1057
+ return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
1058
+ },
1059
+ 18: function (n) {
1060
+ return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
1061
+ },
1062
+ 19: function (n) {
1063
+ return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
1064
+ },
1065
+ 20: function (n) {
1066
+ return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
1067
+ },
1068
+ 21: function (n) {
1069
+ return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
1070
+ },
1071
+ 22: function (n) {
1072
+ return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
1073
+ }
1074
+ };
1075
+ const nonIntlVersions = ['v1', 'v2', 'v3'];
1076
+ const intlVersions = ['v4'];
1077
+ const suffixesOrder = {
1078
+ zero: 0,
1079
+ one: 1,
1080
+ two: 2,
1081
+ few: 3,
1082
+ many: 4,
1083
+ other: 5
1084
+ };
1085
+ function createRules() {
1086
+ const rules = {};
1087
+ sets.forEach(set => {
1088
+ set.lngs.forEach(l => {
1089
+ rules[l] = {
1090
+ numbers: set.nr,
1091
+ plurals: _rulesPluralsTypes[set.fc]
1092
+ };
1093
+ });
1094
+ });
1095
+ return rules;
1096
+ }
1097
+ class PluralResolver {
1098
+ constructor(languageUtils) {
1099
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1100
+ this.languageUtils = languageUtils;
1101
+ this.options = options;
1102
+ this.logger = baseLogger.create('pluralResolver');
1103
+ if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
1104
+ this.options.compatibilityJSON = 'v3';
1105
+ this.logger.error('Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.');
1106
+ }
1107
+ this.rules = createRules();
1108
+ }
1109
+ addRule(lng, obj) {
1110
+ this.rules[lng] = obj;
1111
+ }
1112
+ getRule(code) {
1113
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1114
+ if (this.shouldUseIntlApi()) {
1115
+ try {
1116
+ return new Intl.PluralRules(getCleanedCode(code), {
1117
+ type: options.ordinal ? 'ordinal' : 'cardinal'
1118
+ });
1119
+ } catch {
1120
+ return;
1121
+ }
1122
+ }
1123
+ return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
1124
+ }
1125
+ needsPlural(code) {
1126
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1127
+ const rule = this.getRule(code, options);
1128
+ if (this.shouldUseIntlApi()) {
1129
+ return rule && rule.resolvedOptions().pluralCategories.length > 1;
1130
+ }
1131
+ return rule && rule.numbers.length > 1;
1132
+ }
1133
+ getPluralFormsOfKey(code, key) {
1134
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1135
+ return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
1136
+ }
1137
+ getSuffixes(code) {
1138
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1139
+ const rule = this.getRule(code, options);
1140
+ if (!rule) {
1141
+ return [];
1142
+ }
1143
+ if (this.shouldUseIntlApi()) {
1144
+ return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
1145
+ }
1146
+ return rule.numbers.map(number => this.getSuffix(code, number, options));
1147
+ }
1148
+ getSuffix(code, count) {
1149
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1150
+ const rule = this.getRule(code, options);
1151
+ if (rule) {
1152
+ if (this.shouldUseIntlApi()) {
1153
+ return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
1154
+ }
1155
+ return this.getSuffixRetroCompatible(rule, count);
1156
+ }
1157
+ this.logger.warn(`no plural rule found for: ${code}`);
1158
+ return '';
1159
+ }
1160
+ getSuffixRetroCompatible(rule, count) {
1161
+ const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
1162
+ let suffix = rule.numbers[idx];
1163
+ if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
1164
+ if (suffix === 2) {
1165
+ suffix = 'plural';
1166
+ } else if (suffix === 1) {
1167
+ suffix = '';
1168
+ }
1169
+ }
1170
+ const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
1171
+ if (this.options.compatibilityJSON === 'v1') {
1172
+ if (suffix === 1) return '';
1173
+ if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
1174
+ return returnSuffix();
1175
+ } else if (this.options.compatibilityJSON === 'v2') {
1176
+ return returnSuffix();
1177
+ } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
1178
+ return returnSuffix();
1179
+ }
1180
+ return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
1181
+ }
1182
+ shouldUseIntlApi() {
1183
+ return !nonIntlVersions.includes(this.options.compatibilityJSON);
1184
+ }
1185
+ }
1186
+
1187
+ function deepFindWithDefaults(data, defaultData, key) {
1188
+ let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
1189
+ let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1190
+ let path = getPathWithDefaults(data, defaultData, key);
1191
+ if (!path && ignoreJSONStructure && typeof key === 'string') {
1192
+ path = deepFind(data, key, keySeparator);
1193
+ if (path === undefined) path = deepFind(defaultData, key, keySeparator);
1194
+ }
1195
+ return path;
1196
+ }
1197
+ class Interpolator {
1198
+ constructor() {
1199
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1200
+ this.logger = baseLogger.create('interpolator');
1201
+ this.options = options;
1202
+ this.format = options.interpolation && options.interpolation.format || (value => value);
1203
+ this.init(options);
1204
+ }
1205
+ init() {
1206
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1207
+ if (!options.interpolation) options.interpolation = {
1208
+ escapeValue: true
1209
+ };
1210
+ const iOpts = options.interpolation;
1211
+ this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
1212
+ this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
1213
+ this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
1214
+ this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
1215
+ this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
1216
+ this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
1217
+ this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
1218
+ this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
1219
+ this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
1220
+ this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
1221
+ this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
1222
+ this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
1223
+ this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
1224
+ this.resetRegExp();
1225
+ }
1226
+ reset() {
1227
+ if (this.options) this.init(this.options);
1228
+ }
1229
+ resetRegExp() {
1230
+ const regexpStr = `${this.prefix}(.+?)${this.suffix}`;
1231
+ this.regexp = new RegExp(regexpStr, 'g');
1232
+ const regexpUnescapeStr = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
1233
+ this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
1234
+ const nestingRegexpStr = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
1235
+ this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
1236
+ }
1237
+ interpolate(str, data, lng, options) {
1238
+ let match;
1239
+ let value;
1240
+ let replaces;
1241
+ const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
1242
+ function regexSafe(val) {
1243
+ return val.replace(/\$/g, '$$$$');
1244
+ }
1245
+ const handleFormat = key => {
1246
+ if (key.indexOf(this.formatSeparator) < 0) {
1247
+ const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
1248
+ return this.alwaysFormat ? this.format(path, undefined, lng, {
1249
+ ...options,
1250
+ ...data,
1251
+ interpolationkey: key
1252
+ }) : path;
1253
+ }
1254
+ const p = key.split(this.formatSeparator);
1255
+ const k = p.shift().trim();
1256
+ const f = p.join(this.formatSeparator).trim();
1257
+ return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
1258
+ ...options,
1259
+ ...data,
1260
+ interpolationkey: k
1261
+ });
1262
+ };
1263
+ this.resetRegExp();
1264
+ const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
1265
+ const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
1266
+ const todos = [{
1267
+ regex: this.regexpUnescape,
1268
+ safeValue: val => regexSafe(val)
1269
+ }, {
1270
+ regex: this.regexp,
1271
+ safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
1272
+ }];
1273
+ todos.forEach(todo => {
1274
+ replaces = 0;
1275
+ while (match = todo.regex.exec(str)) {
1276
+ const matchedVar = match[1].trim();
1277
+ value = handleFormat(matchedVar);
1278
+ if (value === undefined) {
1279
+ if (typeof missingInterpolationHandler === 'function') {
1280
+ const temp = missingInterpolationHandler(str, match, options);
1281
+ value = typeof temp === 'string' ? temp : '';
1282
+ } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
1283
+ value = '';
1284
+ } else if (skipOnVariables) {
1285
+ value = match[0];
1286
+ continue;
1287
+ } else {
1288
+ this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
1289
+ value = '';
1290
+ }
1291
+ } else if (typeof value !== 'string' && !this.useRawValueToEscape) {
1292
+ value = makeString(value);
1293
+ }
1294
+ const safeValue = todo.safeValue(value);
1295
+ str = str.replace(match[0], safeValue);
1296
+ if (skipOnVariables) {
1297
+ todo.regex.lastIndex += value.length;
1298
+ todo.regex.lastIndex -= match[0].length;
1299
+ } else {
1300
+ todo.regex.lastIndex = 0;
1301
+ }
1302
+ replaces++;
1303
+ if (replaces >= this.maxReplaces) {
1304
+ break;
1305
+ }
1306
+ }
1307
+ });
1308
+ return str;
1309
+ }
1310
+ nest(str, fc) {
1311
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1312
+ let match;
1313
+ let value;
1314
+ let clonedOptions;
1315
+ function handleHasOptions(key, inheritedOptions) {
1316
+ const sep = this.nestingOptionsSeparator;
1317
+ if (key.indexOf(sep) < 0) return key;
1318
+ const c = key.split(new RegExp(`${sep}[ ]*{`));
1319
+ let optionsString = `{${c[1]}`;
1320
+ key = c[0];
1321
+ optionsString = this.interpolate(optionsString, clonedOptions);
1322
+ const matchedSingleQuotes = optionsString.match(/'/g);
1323
+ const matchedDoubleQuotes = optionsString.match(/"/g);
1324
+ if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
1325
+ optionsString = optionsString.replace(/'/g, '"');
1326
+ }
1327
+ try {
1328
+ clonedOptions = JSON.parse(optionsString);
1329
+ if (inheritedOptions) clonedOptions = {
1330
+ ...inheritedOptions,
1331
+ ...clonedOptions
1332
+ };
1333
+ } catch (e) {
1334
+ this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
1335
+ return `${key}${sep}${optionsString}`;
1336
+ }
1337
+ delete clonedOptions.defaultValue;
1338
+ return key;
1339
+ }
1340
+ while (match = this.nestingRegexp.exec(str)) {
1341
+ let formatters = [];
1342
+ clonedOptions = {
1343
+ ...options
1344
+ };
1345
+ clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
1346
+ clonedOptions.applyPostProcessor = false;
1347
+ delete clonedOptions.defaultValue;
1348
+ let doReduce = false;
1349
+ if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
1350
+ const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
1351
+ match[1] = r.shift();
1352
+ formatters = r;
1353
+ doReduce = true;
1354
+ }
1355
+ value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
1356
+ if (value && match[0] === str && typeof value !== 'string') return value;
1357
+ if (typeof value !== 'string') value = makeString(value);
1358
+ if (!value) {
1359
+ this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
1360
+ value = '';
1361
+ }
1362
+ if (doReduce) {
1363
+ value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
1364
+ ...options,
1365
+ interpolationkey: match[1].trim()
1366
+ }), value.trim());
1367
+ }
1368
+ str = str.replace(match[0], value);
1369
+ this.regexp.lastIndex = 0;
1370
+ }
1371
+ return str;
1372
+ }
1373
+ }
1374
+
1375
+ function parseFormatStr(formatStr) {
1376
+ let formatName = formatStr.toLowerCase().trim();
1377
+ const formatOptions = {};
1378
+ if (formatStr.indexOf('(') > -1) {
1379
+ const p = formatStr.split('(');
1380
+ formatName = p[0].toLowerCase().trim();
1381
+ const optStr = p[1].substring(0, p[1].length - 1);
1382
+ if (formatName === 'currency' && optStr.indexOf(':') < 0) {
1383
+ if (!formatOptions.currency) formatOptions.currency = optStr.trim();
1384
+ } else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
1385
+ if (!formatOptions.range) formatOptions.range = optStr.trim();
1386
+ } else {
1387
+ const opts = optStr.split(';');
1388
+ opts.forEach(opt => {
1389
+ if (!opt) return;
1390
+ const [key, ...rest] = opt.split(':');
1391
+ const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
1392
+ if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
1393
+ if (val === 'false') formatOptions[key.trim()] = false;
1394
+ if (val === 'true') formatOptions[key.trim()] = true;
1395
+ if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
1396
+ });
1397
+ }
1398
+ }
1399
+ return {
1400
+ formatName,
1401
+ formatOptions
1402
+ };
1403
+ }
1404
+ function createCachedFormatter(fn) {
1405
+ const cache = {};
1406
+ return function invokeFormatter(val, lng, options) {
1407
+ const key = lng + JSON.stringify(options);
1408
+ let formatter = cache[key];
1409
+ if (!formatter) {
1410
+ formatter = fn(getCleanedCode(lng), options);
1411
+ cache[key] = formatter;
1412
+ }
1413
+ return formatter(val);
1414
+ };
1415
+ }
1416
+ class Formatter {
1417
+ constructor() {
1418
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1419
+ this.logger = baseLogger.create('formatter');
1420
+ this.options = options;
1421
+ this.formats = {
1422
+ number: createCachedFormatter((lng, opt) => {
1423
+ const formatter = new Intl.NumberFormat(lng, {
1424
+ ...opt
1425
+ });
1426
+ return val => formatter.format(val);
1427
+ }),
1428
+ currency: createCachedFormatter((lng, opt) => {
1429
+ const formatter = new Intl.NumberFormat(lng, {
1430
+ ...opt,
1431
+ style: 'currency'
1432
+ });
1433
+ return val => formatter.format(val);
1434
+ }),
1435
+ datetime: createCachedFormatter((lng, opt) => {
1436
+ const formatter = new Intl.DateTimeFormat(lng, {
1437
+ ...opt
1438
+ });
1439
+ return val => formatter.format(val);
1440
+ }),
1441
+ relativetime: createCachedFormatter((lng, opt) => {
1442
+ const formatter = new Intl.RelativeTimeFormat(lng, {
1443
+ ...opt
1444
+ });
1445
+ return val => formatter.format(val, opt.range || 'day');
1446
+ }),
1447
+ list: createCachedFormatter((lng, opt) => {
1448
+ const formatter = new Intl.ListFormat(lng, {
1449
+ ...opt
1450
+ });
1451
+ return val => formatter.format(val);
1452
+ })
1453
+ };
1454
+ this.init(options);
1455
+ }
1456
+ init(services) {
1457
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
1458
+ interpolation: {}
1459
+ };
1460
+ const iOpts = options.interpolation;
1461
+ this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
1462
+ }
1463
+ add(name, fc) {
1464
+ this.formats[name.toLowerCase().trim()] = fc;
1465
+ }
1466
+ addCached(name, fc) {
1467
+ this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1468
+ }
1469
+ format(value, format, lng) {
1470
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1471
+ const formats = format.split(this.formatSeparator);
1472
+ const result = formats.reduce((mem, f) => {
1473
+ const {
1474
+ formatName,
1475
+ formatOptions
1476
+ } = parseFormatStr(f);
1477
+ if (this.formats[formatName]) {
1478
+ let formatted = mem;
1479
+ try {
1480
+ const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
1481
+ const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
1482
+ formatted = this.formats[formatName](mem, l, {
1483
+ ...formatOptions,
1484
+ ...options,
1485
+ ...valOptions
1486
+ });
1487
+ } catch (error) {
1488
+ this.logger.warn(error);
1489
+ }
1490
+ return formatted;
1491
+ } else {
1492
+ this.logger.warn(`there was no format function for ${formatName}`);
1493
+ }
1494
+ return mem;
1495
+ }, value);
1496
+ return result;
1497
+ }
1498
+ }
1499
+
1500
+ function removePending(q, name) {
1501
+ if (q.pending[name] !== undefined) {
1502
+ delete q.pending[name];
1503
+ q.pendingCount--;
1504
+ }
1505
+ }
1506
+ class Connector extends EventEmitter {
1507
+ constructor(backend, store, services) {
1508
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1509
+ super();
1510
+ this.backend = backend;
1511
+ this.store = store;
1512
+ this.services = services;
1513
+ this.languageUtils = services.languageUtils;
1514
+ this.options = options;
1515
+ this.logger = baseLogger.create('backendConnector');
1516
+ this.waitingReads = [];
1517
+ this.maxParallelReads = options.maxParallelReads || 10;
1518
+ this.readingCalls = 0;
1519
+ this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
1520
+ this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
1521
+ this.state = {};
1522
+ this.queue = [];
1523
+ if (this.backend && this.backend.init) {
1524
+ this.backend.init(services, options.backend, options);
1525
+ }
1526
+ }
1527
+ queueLoad(languages, namespaces, options, callback) {
1528
+ const toLoad = {};
1529
+ const pending = {};
1530
+ const toLoadLanguages = {};
1531
+ const toLoadNamespaces = {};
1532
+ languages.forEach(lng => {
1533
+ let hasAllNamespaces = true;
1534
+ namespaces.forEach(ns => {
1535
+ const name = `${lng}|${ns}`;
1536
+ if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
1537
+ this.state[name] = 2;
1538
+ } else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
1539
+ if (pending[name] === undefined) pending[name] = true;
1540
+ } else {
1541
+ this.state[name] = 1;
1542
+ hasAllNamespaces = false;
1543
+ if (pending[name] === undefined) pending[name] = true;
1544
+ if (toLoad[name] === undefined) toLoad[name] = true;
1545
+ if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
1546
+ }
1547
+ });
1548
+ if (!hasAllNamespaces) toLoadLanguages[lng] = true;
1549
+ });
1550
+ if (Object.keys(toLoad).length || Object.keys(pending).length) {
1551
+ this.queue.push({
1552
+ pending,
1553
+ pendingCount: Object.keys(pending).length,
1554
+ loaded: {},
1555
+ errors: [],
1556
+ callback
1557
+ });
1558
+ }
1559
+ return {
1560
+ toLoad: Object.keys(toLoad),
1561
+ pending: Object.keys(pending),
1562
+ toLoadLanguages: Object.keys(toLoadLanguages),
1563
+ toLoadNamespaces: Object.keys(toLoadNamespaces)
1564
+ };
1565
+ }
1566
+ loaded(name, err, data) {
1567
+ const s = name.split('|');
1568
+ const lng = s[0];
1569
+ const ns = s[1];
1570
+ if (err) this.emit('failedLoading', lng, ns, err);
1571
+ if (data) {
1572
+ this.store.addResourceBundle(lng, ns, data);
1573
+ }
1574
+ this.state[name] = err ? -1 : 2;
1575
+ const loaded = {};
1576
+ this.queue.forEach(q => {
1577
+ pushPath(q.loaded, [lng], ns);
1578
+ removePending(q, name);
1579
+ if (err) q.errors.push(err);
1580
+ if (q.pendingCount === 0 && !q.done) {
1581
+ Object.keys(q.loaded).forEach(l => {
1582
+ if (!loaded[l]) loaded[l] = {};
1583
+ const loadedKeys = q.loaded[l];
1584
+ if (loadedKeys.length) {
1585
+ loadedKeys.forEach(n => {
1586
+ if (loaded[l][n] === undefined) loaded[l][n] = true;
1587
+ });
1588
+ }
1589
+ });
1590
+ q.done = true;
1591
+ if (q.errors.length) {
1592
+ q.callback(q.errors);
1593
+ } else {
1594
+ q.callback();
1595
+ }
1596
+ }
1597
+ });
1598
+ this.emit('loaded', loaded);
1599
+ this.queue = this.queue.filter(q => !q.done);
1600
+ }
1601
+ read(lng, ns, fcName) {
1602
+ let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1603
+ let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
1604
+ let callback = arguments.length > 5 ? arguments[5] : undefined;
1605
+ if (!lng.length) return callback(null, {});
1606
+ if (this.readingCalls >= this.maxParallelReads) {
1607
+ this.waitingReads.push({
1608
+ lng,
1609
+ ns,
1610
+ fcName,
1611
+ tried,
1612
+ wait,
1613
+ callback
1614
+ });
1615
+ return;
1616
+ }
1617
+ this.readingCalls++;
1618
+ const resolver = (err, data) => {
1619
+ this.readingCalls--;
1620
+ if (this.waitingReads.length > 0) {
1621
+ const next = this.waitingReads.shift();
1622
+ this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
1623
+ }
1624
+ if (err && data && tried < this.maxRetries) {
1625
+ setTimeout(() => {
1626
+ this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
1627
+ }, wait);
1628
+ return;
1629
+ }
1630
+ callback(err, data);
1631
+ };
1632
+ const fc = this.backend[fcName].bind(this.backend);
1633
+ if (fc.length === 2) {
1634
+ try {
1635
+ const r = fc(lng, ns);
1636
+ if (r && typeof r.then === 'function') {
1637
+ r.then(data => resolver(null, data)).catch(resolver);
1638
+ } else {
1639
+ resolver(null, r);
1640
+ }
1641
+ } catch (err) {
1642
+ resolver(err);
1643
+ }
1644
+ return;
1645
+ }
1646
+ return fc(lng, ns, resolver);
1647
+ }
1648
+ prepareLoading(languages, namespaces) {
1649
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1650
+ let callback = arguments.length > 3 ? arguments[3] : undefined;
1651
+ if (!this.backend) {
1652
+ this.logger.warn('No backend was added via i18next.use. Will not load resources.');
1653
+ return callback && callback();
1654
+ }
1655
+ if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
1656
+ if (typeof namespaces === 'string') namespaces = [namespaces];
1657
+ const toLoad = this.queueLoad(languages, namespaces, options, callback);
1658
+ if (!toLoad.toLoad.length) {
1659
+ if (!toLoad.pending.length) callback();
1660
+ return null;
1661
+ }
1662
+ toLoad.toLoad.forEach(name => {
1663
+ this.loadOne(name);
1664
+ });
1665
+ }
1666
+ load(languages, namespaces, callback) {
1667
+ this.prepareLoading(languages, namespaces, {}, callback);
1668
+ }
1669
+ reload(languages, namespaces, callback) {
1670
+ this.prepareLoading(languages, namespaces, {
1671
+ reload: true
1672
+ }, callback);
1673
+ }
1674
+ loadOne(name) {
1675
+ let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1676
+ const s = name.split('|');
1677
+ const lng = s[0];
1678
+ const ns = s[1];
1679
+ this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
1680
+ if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
1681
+ if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
1682
+ this.loaded(name, err, data);
1683
+ });
1684
+ }
1685
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
1686
+ let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
1687
+ let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
1688
+ if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
1689
+ 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!!!');
1690
+ return;
1691
+ }
1692
+ if (key === undefined || key === null || key === '') return;
1693
+ if (this.backend && this.backend.create) {
1694
+ const opts = {
1695
+ ...options,
1696
+ isUpdate
1697
+ };
1698
+ const fc = this.backend.create.bind(this.backend);
1699
+ if (fc.length < 6) {
1700
+ try {
1701
+ let r;
1702
+ if (fc.length === 5) {
1703
+ r = fc(languages, namespace, key, fallbackValue, opts);
1704
+ } else {
1705
+ r = fc(languages, namespace, key, fallbackValue);
1706
+ }
1707
+ if (r && typeof r.then === 'function') {
1708
+ r.then(data => clb(null, data)).catch(clb);
1709
+ } else {
1710
+ clb(null, r);
1711
+ }
1712
+ } catch (err) {
1713
+ clb(err);
1714
+ }
1715
+ } else {
1716
+ fc(languages, namespace, key, fallbackValue, clb, opts);
1717
+ }
1718
+ }
1719
+ if (!languages || !languages[0]) return;
1720
+ this.store.addResource(languages[0], namespace, key, fallbackValue);
1721
+ }
1722
+ }
1723
+
1724
+ function get() {
1725
+ return {
1726
+ debug: false,
1727
+ initImmediate: true,
1728
+ ns: ['translation'],
1729
+ defaultNS: ['translation'],
1730
+ fallbackLng: ['dev'],
1731
+ fallbackNS: false,
1732
+ supportedLngs: false,
1733
+ nonExplicitSupportedLngs: false,
1734
+ load: 'all',
1735
+ preload: false,
1736
+ simplifyPluralSuffix: true,
1737
+ keySeparator: '.',
1738
+ nsSeparator: ':',
1739
+ pluralSeparator: '_',
1740
+ contextSeparator: '_',
1741
+ partialBundledLanguages: false,
1742
+ saveMissing: false,
1743
+ updateMissing: false,
1744
+ saveMissingTo: 'fallback',
1745
+ saveMissingPlurals: true,
1746
+ missingKeyHandler: false,
1747
+ missingInterpolationHandler: false,
1748
+ postProcess: false,
1749
+ postProcessPassResolved: false,
1750
+ returnNull: false,
1751
+ returnEmptyString: true,
1752
+ returnObjects: false,
1753
+ joinArrays: false,
1754
+ returnedObjectHandler: false,
1755
+ parseMissingKeyHandler: false,
1756
+ appendNamespaceToMissingKey: false,
1757
+ appendNamespaceToCIMode: false,
1758
+ overloadTranslationOptionHandler: function handle(args) {
1759
+ let ret = {};
1760
+ if (typeof args[1] === 'object') ret = args[1];
1761
+ if (typeof args[1] === 'string') ret.defaultValue = args[1];
1762
+ if (typeof args[2] === 'string') ret.tDescription = args[2];
1763
+ if (typeof args[2] === 'object' || typeof args[3] === 'object') {
1764
+ const options = args[3] || args[2];
1765
+ Object.keys(options).forEach(key => {
1766
+ ret[key] = options[key];
1767
+ });
1768
+ }
1769
+ return ret;
1770
+ },
1771
+ interpolation: {
1772
+ escapeValue: true,
1773
+ format: (value, format, lng, options) => value,
1774
+ prefix: '{{',
1775
+ suffix: '}}',
1776
+ formatSeparator: ',',
1777
+ unescapePrefix: '-',
1778
+ nestingPrefix: '$t(',
1779
+ nestingSuffix: ')',
1780
+ nestingOptionsSeparator: ',',
1781
+ maxReplaces: 1000,
1782
+ skipOnVariables: true
1783
+ }
1784
+ };
1785
+ }
1786
+ function transformOptions(options) {
1787
+ if (typeof options.ns === 'string') options.ns = [options.ns];
1788
+ if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
1789
+ if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
1790
+ if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
1791
+ options.supportedLngs = options.supportedLngs.concat(['cimode']);
1792
+ }
1793
+ return options;
1794
+ }
1795
+
1796
+ function noop() {}
1797
+ function bindMemberFunctions(inst) {
1798
+ const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
1799
+ mems.forEach(mem => {
1800
+ if (typeof inst[mem] === 'function') {
1801
+ inst[mem] = inst[mem].bind(inst);
1802
+ }
1803
+ });
1804
+ }
1805
+ class I18n extends EventEmitter {
1806
+ constructor() {
1807
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1808
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
1809
+ super();
1810
+ this.options = transformOptions(options);
1811
+ this.services = {};
1812
+ this.logger = baseLogger;
1813
+ this.modules = {
1814
+ external: []
1815
+ };
1816
+ bindMemberFunctions(this);
1817
+ if (callback && !this.isInitialized && !options.isClone) {
1818
+ if (!this.options.initImmediate) {
1819
+ this.init(options, callback);
1820
+ return this;
1821
+ }
1822
+ setTimeout(() => {
1823
+ this.init(options, callback);
1824
+ }, 0);
1825
+ }
1826
+ }
1827
+ init() {
1828
+ var _this = this;
1829
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1830
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
1831
+ if (typeof options === 'function') {
1832
+ callback = options;
1833
+ options = {};
1834
+ }
1835
+ if (!options.defaultNS && options.defaultNS !== false && options.ns) {
1836
+ if (typeof options.ns === 'string') {
1837
+ options.defaultNS = options.ns;
1838
+ } else if (options.ns.indexOf('translation') < 0) {
1839
+ options.defaultNS = options.ns[0];
1840
+ }
1841
+ }
1842
+ const defOpts = get();
1843
+ this.options = {
1844
+ ...defOpts,
1845
+ ...this.options,
1846
+ ...transformOptions(options)
1847
+ };
1848
+ if (this.options.compatibilityAPI !== 'v1') {
1849
+ this.options.interpolation = {
1850
+ ...defOpts.interpolation,
1851
+ ...this.options.interpolation
1852
+ };
1853
+ }
1854
+ if (options.keySeparator !== undefined) {
1855
+ this.options.userDefinedKeySeparator = options.keySeparator;
1856
+ }
1857
+ if (options.nsSeparator !== undefined) {
1858
+ this.options.userDefinedNsSeparator = options.nsSeparator;
1859
+ }
1860
+ function createClassOnDemand(ClassOrObject) {
1861
+ if (!ClassOrObject) return null;
1862
+ if (typeof ClassOrObject === 'function') return new ClassOrObject();
1863
+ return ClassOrObject;
1864
+ }
1865
+ if (!this.options.isClone) {
1866
+ if (this.modules.logger) {
1867
+ baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
1868
+ } else {
1869
+ baseLogger.init(null, this.options);
1870
+ }
1871
+ let formatter;
1872
+ if (this.modules.formatter) {
1873
+ formatter = this.modules.formatter;
1874
+ } else if (typeof Intl !== 'undefined') {
1875
+ formatter = Formatter;
1876
+ }
1877
+ const lu = new LanguageUtil(this.options);
1878
+ this.store = new ResourceStore(this.options.resources, this.options);
1879
+ const s = this.services;
1880
+ s.logger = baseLogger;
1881
+ s.resourceStore = this.store;
1882
+ s.languageUtils = lu;
1883
+ s.pluralResolver = new PluralResolver(lu, {
1884
+ prepend: this.options.pluralSeparator,
1885
+ compatibilityJSON: this.options.compatibilityJSON,
1886
+ simplifyPluralSuffix: this.options.simplifyPluralSuffix
1887
+ });
1888
+ if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
1889
+ s.formatter = createClassOnDemand(formatter);
1890
+ s.formatter.init(s, this.options);
1891
+ this.options.interpolation.format = s.formatter.format.bind(s.formatter);
1892
+ }
1893
+ s.interpolator = new Interpolator(this.options);
1894
+ s.utils = {
1895
+ hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1896
+ };
1897
+ s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
1898
+ s.backendConnector.on('*', function (event) {
1899
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1900
+ args[_key - 1] = arguments[_key];
1901
+ }
1902
+ _this.emit(event, ...args);
1903
+ });
1904
+ if (this.modules.languageDetector) {
1905
+ s.languageDetector = createClassOnDemand(this.modules.languageDetector);
1906
+ if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
1907
+ }
1908
+ if (this.modules.i18nFormat) {
1909
+ s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
1910
+ if (s.i18nFormat.init) s.i18nFormat.init(this);
1911
+ }
1912
+ this.translator = new Translator(this.services, this.options);
1913
+ this.translator.on('*', function (event) {
1914
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1915
+ args[_key2 - 1] = arguments[_key2];
1916
+ }
1917
+ _this.emit(event, ...args);
1918
+ });
1919
+ this.modules.external.forEach(m => {
1920
+ if (m.init) m.init(this);
1921
+ });
1922
+ }
1923
+ this.format = this.options.interpolation.format;
1924
+ if (!callback) callback = noop;
1925
+ if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
1926
+ const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1927
+ if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
1928
+ }
1929
+ if (!this.services.languageDetector && !this.options.lng) {
1930
+ this.logger.warn('init: no languageDetector is used and no lng is defined');
1931
+ }
1932
+ const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
1933
+ storeApi.forEach(fcName => {
1934
+ this[fcName] = function () {
1935
+ return _this.store[fcName](...arguments);
1936
+ };
1937
+ });
1938
+ const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
1939
+ storeApiChained.forEach(fcName => {
1940
+ this[fcName] = function () {
1941
+ _this.store[fcName](...arguments);
1942
+ return _this;
1943
+ };
1944
+ });
1945
+ const deferred = defer();
1946
+ const load = () => {
1947
+ const finish = (err, t) => {
1948
+ if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
1949
+ this.isInitialized = true;
1950
+ if (!this.options.isClone) this.logger.log('initialized', this.options);
1951
+ this.emit('initialized', this.options);
1952
+ deferred.resolve(t);
1953
+ callback(err, t);
1954
+ };
1955
+ if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
1956
+ this.changeLanguage(this.options.lng, finish);
1957
+ };
1958
+ if (this.options.resources || !this.options.initImmediate) {
1959
+ load();
1960
+ } else {
1961
+ setTimeout(load, 0);
1962
+ }
1963
+ return deferred;
1964
+ }
1965
+ loadResources(language) {
1966
+ let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
1967
+ let usedCallback = callback;
1968
+ const usedLng = typeof language === 'string' ? language : this.language;
1969
+ if (typeof language === 'function') usedCallback = language;
1970
+ if (!this.options.resources || this.options.partialBundledLanguages) {
1971
+ if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
1972
+ const toLoad = [];
1973
+ const append = lng => {
1974
+ if (!lng) return;
1975
+ const lngs = this.services.languageUtils.toResolveHierarchy(lng);
1976
+ lngs.forEach(l => {
1977
+ if (toLoad.indexOf(l) < 0) toLoad.push(l);
1978
+ });
1979
+ };
1980
+ if (!usedLng) {
1981
+ const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1982
+ fallbacks.forEach(l => append(l));
1983
+ } else {
1984
+ append(usedLng);
1985
+ }
1986
+ if (this.options.preload) {
1987
+ this.options.preload.forEach(l => append(l));
1988
+ }
1989
+ this.services.backendConnector.load(toLoad, this.options.ns, e => {
1990
+ if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
1991
+ usedCallback(e);
1992
+ });
1993
+ } else {
1994
+ usedCallback(null);
1995
+ }
1996
+ }
1997
+ reloadResources(lngs, ns, callback) {
1998
+ const deferred = defer();
1999
+ if (!lngs) lngs = this.languages;
2000
+ if (!ns) ns = this.options.ns;
2001
+ if (!callback) callback = noop;
2002
+ this.services.backendConnector.reload(lngs, ns, err => {
2003
+ deferred.resolve();
2004
+ callback(err);
2005
+ });
2006
+ return deferred;
2007
+ }
2008
+ use(module) {
2009
+ if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
2010
+ if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
2011
+ if (module.type === 'backend') {
2012
+ this.modules.backend = module;
2013
+ }
2014
+ if (module.type === 'logger' || module.log && module.warn && module.error) {
2015
+ this.modules.logger = module;
2016
+ }
2017
+ if (module.type === 'languageDetector') {
2018
+ this.modules.languageDetector = module;
2019
+ }
2020
+ if (module.type === 'i18nFormat') {
2021
+ this.modules.i18nFormat = module;
2022
+ }
2023
+ if (module.type === 'postProcessor') {
2024
+ postProcessor.addPostProcessor(module);
2025
+ }
2026
+ if (module.type === 'formatter') {
2027
+ this.modules.formatter = module;
2028
+ }
2029
+ if (module.type === '3rdParty') {
2030
+ this.modules.external.push(module);
2031
+ }
2032
+ return this;
2033
+ }
2034
+ setResolvedLanguage(l) {
2035
+ if (!l || !this.languages) return;
2036
+ if (['cimode', 'dev'].indexOf(l) > -1) return;
2037
+ for (let li = 0; li < this.languages.length; li++) {
2038
+ const lngInLngs = this.languages[li];
2039
+ if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
2040
+ if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
2041
+ this.resolvedLanguage = lngInLngs;
2042
+ break;
2043
+ }
2044
+ }
2045
+ }
2046
+ changeLanguage(lng, callback) {
2047
+ var _this2 = this;
2048
+ this.isLanguageChangingTo = lng;
2049
+ const deferred = defer();
2050
+ this.emit('languageChanging', lng);
2051
+ const setLngProps = l => {
2052
+ this.language = l;
2053
+ this.languages = this.services.languageUtils.toResolveHierarchy(l);
2054
+ this.resolvedLanguage = undefined;
2055
+ this.setResolvedLanguage(l);
2056
+ };
2057
+ const done = (err, l) => {
2058
+ if (l) {
2059
+ setLngProps(l);
2060
+ this.translator.changeLanguage(l);
2061
+ this.isLanguageChangingTo = undefined;
2062
+ this.emit('languageChanged', l);
2063
+ this.logger.log('languageChanged', l);
2064
+ } else {
2065
+ this.isLanguageChangingTo = undefined;
2066
+ }
2067
+ deferred.resolve(function () {
2068
+ return _this2.t(...arguments);
2069
+ });
2070
+ if (callback) callback(err, function () {
2071
+ return _this2.t(...arguments);
2072
+ });
2073
+ };
2074
+ const setLng = lngs => {
2075
+ if (!lng && !lngs && this.services.languageDetector) lngs = [];
2076
+ const l = typeof lngs === 'string' ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
2077
+ if (l) {
2078
+ if (!this.language) {
2079
+ setLngProps(l);
2080
+ }
2081
+ if (!this.translator.language) this.translator.changeLanguage(l);
2082
+ if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
2083
+ }
2084
+ this.loadResources(l, err => {
2085
+ done(err, l);
2086
+ });
2087
+ };
2088
+ if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
2089
+ setLng(this.services.languageDetector.detect());
2090
+ } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
2091
+ if (this.services.languageDetector.detect.length === 0) {
2092
+ this.services.languageDetector.detect().then(setLng);
2093
+ } else {
2094
+ this.services.languageDetector.detect(setLng);
2095
+ }
2096
+ } else {
2097
+ setLng(lng);
2098
+ }
2099
+ return deferred;
2100
+ }
2101
+ getFixedT(lng, ns, keyPrefix) {
2102
+ var _this3 = this;
2103
+ const fixedT = function (key, opts) {
2104
+ let options;
2105
+ if (typeof opts !== 'object') {
2106
+ for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2107
+ rest[_key3 - 2] = arguments[_key3];
2108
+ }
2109
+ options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2110
+ } else {
2111
+ options = {
2112
+ ...opts
2113
+ };
2114
+ }
2115
+ options.lng = options.lng || fixedT.lng;
2116
+ options.lngs = options.lngs || fixedT.lngs;
2117
+ options.ns = options.ns || fixedT.ns;
2118
+ options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
2119
+ const keySeparator = _this3.options.keySeparator || '.';
2120
+ let resultKey;
2121
+ if (options.keyPrefix && Array.isArray(key)) {
2122
+ resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
2123
+ } else {
2124
+ resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
2125
+ }
2126
+ return _this3.t(resultKey, options);
2127
+ };
2128
+ if (typeof lng === 'string') {
2129
+ fixedT.lng = lng;
2130
+ } else {
2131
+ fixedT.lngs = lng;
2132
+ }
2133
+ fixedT.ns = ns;
2134
+ fixedT.keyPrefix = keyPrefix;
2135
+ return fixedT;
2136
+ }
2137
+ t() {
2138
+ return this.translator && this.translator.translate(...arguments);
2139
+ }
2140
+ exists() {
2141
+ return this.translator && this.translator.exists(...arguments);
2142
+ }
2143
+ setDefaultNamespace(ns) {
2144
+ this.options.defaultNS = ns;
2145
+ }
2146
+ hasLoadedNamespace(ns) {
2147
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2148
+ if (!this.isInitialized) {
2149
+ this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
2150
+ return false;
2151
+ }
2152
+ if (!this.languages || !this.languages.length) {
2153
+ this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
2154
+ return false;
2155
+ }
2156
+ const lng = options.lng || this.resolvedLanguage || this.languages[0];
2157
+ const fallbackLng = this.options ? this.options.fallbackLng : false;
2158
+ const lastLng = this.languages[this.languages.length - 1];
2159
+ if (lng.toLowerCase() === 'cimode') return true;
2160
+ const loadNotPending = (l, n) => {
2161
+ const loadState = this.services.backendConnector.state[`${l}|${n}`];
2162
+ return loadState === -1 || loadState === 2;
2163
+ };
2164
+ if (options.precheck) {
2165
+ const preResult = options.precheck(this, loadNotPending);
2166
+ if (preResult !== undefined) return preResult;
2167
+ }
2168
+ if (this.hasResourceBundle(lng, ns)) return true;
2169
+ if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
2170
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
2171
+ return false;
2172
+ }
2173
+ loadNamespaces(ns, callback) {
2174
+ const deferred = defer();
2175
+ if (!this.options.ns) {
2176
+ if (callback) callback();
2177
+ return Promise.resolve();
2178
+ }
2179
+ if (typeof ns === 'string') ns = [ns];
2180
+ ns.forEach(n => {
2181
+ if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
2182
+ });
2183
+ this.loadResources(err => {
2184
+ deferred.resolve();
2185
+ if (callback) callback(err);
2186
+ });
2187
+ return deferred;
2188
+ }
2189
+ loadLanguages(lngs, callback) {
2190
+ const deferred = defer();
2191
+ if (typeof lngs === 'string') lngs = [lngs];
2192
+ const preloaded = this.options.preload || [];
2193
+ const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0);
2194
+ if (!newLngs.length) {
2195
+ if (callback) callback();
2196
+ return Promise.resolve();
2197
+ }
2198
+ this.options.preload = preloaded.concat(newLngs);
2199
+ this.loadResources(err => {
2200
+ deferred.resolve();
2201
+ if (callback) callback(err);
2202
+ });
2203
+ return deferred;
2204
+ }
2205
+ dir(lng) {
2206
+ if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
2207
+ if (!lng) return 'rtl';
2208
+ 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'];
2209
+ const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
2210
+ return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
2211
+ }
2212
+ static createInstance() {
2213
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2214
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
2215
+ return new I18n(options, callback);
2216
+ }
2217
+ cloneInstance() {
2218
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2219
+ let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
2220
+ const forkResourceStore = options.forkResourceStore;
2221
+ if (forkResourceStore) delete options.forkResourceStore;
2222
+ const mergedOptions = {
2223
+ ...this.options,
2224
+ ...options,
2225
+ ...{
2226
+ isClone: true
2227
+ }
2228
+ };
2229
+ const clone = new I18n(mergedOptions);
2230
+ if (options.debug !== undefined || options.prefix !== undefined) {
2231
+ clone.logger = clone.logger.clone(options);
2232
+ }
2233
+ const membersToCopy = ['store', 'services', 'language'];
2234
+ membersToCopy.forEach(m => {
2235
+ clone[m] = this[m];
2236
+ });
2237
+ clone.services = {
2238
+ ...this.services
2239
+ };
2240
+ clone.services.utils = {
2241
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2242
+ };
2243
+ if (forkResourceStore) {
2244
+ clone.store = new ResourceStore(this.store.data, mergedOptions);
2245
+ clone.services.resourceStore = clone.store;
2246
+ }
2247
+ clone.translator = new Translator(clone.services, mergedOptions);
2248
+ clone.translator.on('*', function (event) {
2249
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
2250
+ args[_key4 - 1] = arguments[_key4];
2251
+ }
2252
+ clone.emit(event, ...args);
2253
+ });
2254
+ clone.init(mergedOptions, callback);
2255
+ clone.translator.options = mergedOptions;
2256
+ clone.translator.backendConnector.services.utils = {
2257
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2258
+ };
2259
+ return clone;
2260
+ }
2261
+ toJSON() {
2262
+ return {
2263
+ options: this.options,
2264
+ store: this.store,
2265
+ language: this.language,
2266
+ languages: this.languages,
2267
+ resolvedLanguage: this.resolvedLanguage
2268
+ };
2269
+ }
2270
+ }
2271
+ const instance = I18n.createInstance();
2272
+ instance.createInstance = I18n.createInstance;
2273
+
2274
+ instance.createInstance;
2275
+ instance.dir;
2276
+ instance.init;
2277
+ instance.loadResources;
2278
+ instance.reloadResources;
2279
+ instance.use;
2280
+ instance.changeLanguage;
2281
+ instance.getFixedT;
2282
+ const t$1 = instance.t;
2283
+ instance.exists;
2284
+ instance.setDefaultNamespace;
2285
+ instance.hasLoadedNamespace;
2286
+ instance.loadNamespaces;
2287
+ instance.loadLanguages;
2288
+
2289
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2290
+
2291
+ function getDefaultExportFromCjs (x) {
2292
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
2293
+ }
2294
+
2295
+ /**
2296
+ * This file automatically generated from `pre-publish.js`.
2297
+ * Do not manually edit.
2298
+ */
2299
+
2300
+ var voidElements = {
2301
+ "area": true,
2302
+ "base": true,
2303
+ "br": true,
2304
+ "col": true,
2305
+ "embed": true,
2306
+ "hr": true,
2307
+ "img": true,
2308
+ "input": true,
2309
+ "link": true,
2310
+ "meta": true,
2311
+ "param": true,
2312
+ "source": true,
2313
+ "track": true,
2314
+ "wbr": true
2315
+ };
2316
+
2317
+ var e = /*@__PURE__*/getDefaultExportFromCjs(voidElements);
2318
+
2319
+ var t=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(e[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i=/^\s*$/,s=Object.create(null);function a(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c={parse:function(e,t){t||(t={}),t.components||(t.components=s);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a("",t)},"")}};
2320
+
2321
+ function warn() {
2322
+ if (console && console.warn) {
2323
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2324
+ args[_key] = arguments[_key];
2325
+ }
2326
+ if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
2327
+ console.warn(...args);
2328
+ }
2329
+ }
2330
+ const alreadyWarned = {};
2331
+ function warnOnce() {
2332
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2333
+ args[_key2] = arguments[_key2];
2334
+ }
2335
+ if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
2336
+ if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
2337
+ warn(...args);
2338
+ }
2339
+ const loadedClb = (i18n, cb) => () => {
2340
+ if (i18n.isInitialized) {
2341
+ cb();
2342
+ } else {
2343
+ const initialized = () => {
2344
+ setTimeout(() => {
2345
+ i18n.off('initialized', initialized);
2346
+ }, 0);
2347
+ cb();
2348
+ };
2349
+ i18n.on('initialized', initialized);
2350
+ }
2351
+ };
2352
+ function loadNamespaces(i18n, ns, cb) {
2353
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
2354
+ }
2355
+ function loadLanguages(i18n, lng, ns, cb) {
2356
+ if (typeof ns === 'string') ns = [ns];
2357
+ ns.forEach(n => {
2358
+ if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
2359
+ });
2360
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
2361
+ }
2362
+ function oldI18nextHasLoadedNamespace(ns, i18n) {
2363
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2364
+ const lng = i18n.languages[0];
2365
+ const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
2366
+ const lastLng = i18n.languages[i18n.languages.length - 1];
2367
+ if (lng.toLowerCase() === 'cimode') return true;
2368
+ const loadNotPending = (l, n) => {
2369
+ const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
2370
+ return loadState === -1 || loadState === 2;
2371
+ };
2372
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
2373
+ if (i18n.hasResourceBundle(lng, ns)) return true;
2374
+ if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
2375
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
2376
+ return false;
2377
+ }
2378
+ function hasLoadedNamespace(ns, i18n) {
2379
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2380
+ if (!i18n.languages || !i18n.languages.length) {
2381
+ warnOnce('i18n.languages were undefined or empty', i18n.languages);
2382
+ return true;
2383
+ }
2384
+ const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
2385
+ if (!isNewerI18next) {
2386
+ return oldI18nextHasLoadedNamespace(ns, i18n, options);
2387
+ }
2388
+ return i18n.hasLoadedNamespace(ns, {
2389
+ lng: options.lng,
2390
+ precheck: (i18nInstance, loadNotPending) => {
2391
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
2392
+ }
2393
+ });
2394
+ }
2395
+
2396
+ const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
2397
+ const htmlEntities = {
2398
+ '&amp;': '&',
2399
+ '&#38;': '&',
2400
+ '&lt;': '<',
2401
+ '&#60;': '<',
2402
+ '&gt;': '>',
2403
+ '&#62;': '>',
2404
+ '&apos;': "'",
2405
+ '&#39;': "'",
2406
+ '&quot;': '"',
2407
+ '&#34;': '"',
2408
+ '&nbsp;': ' ',
2409
+ '&#160;': ' ',
2410
+ '&copy;': '©',
2411
+ '&#169;': '©',
2412
+ '&reg;': '®',
2413
+ '&#174;': '®',
2414
+ '&hellip;': '…',
2415
+ '&#8230;': '…',
2416
+ '&#x2F;': '/',
2417
+ '&#47;': '/'
2418
+ };
2419
+ const unescapeHtmlEntity = m => htmlEntities[m];
2420
+ const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
2421
+
2422
+ let defaultOptions = {
2423
+ bindI18n: 'languageChanged',
2424
+ bindI18nStore: '',
2425
+ transEmptyNodeValue: '',
2426
+ transSupportBasicHtmlNodes: true,
2427
+ transWrapTextNodes: '',
2428
+ transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
2429
+ useSuspense: true,
2430
+ unescape
2431
+ };
2432
+ function setDefaults() {
2433
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2434
+ defaultOptions = {
2435
+ ...defaultOptions,
2436
+ ...options
2437
+ };
2438
+ }
2439
+ function getDefaults() {
2440
+ return defaultOptions;
2441
+ }
2442
+
2443
+ let i18nInstance;
2444
+ function setI18n(instance) {
2445
+ i18nInstance = instance;
2446
+ }
2447
+ function getI18n() {
2448
+ return i18nInstance;
2449
+ }
2450
+
2451
+ function hasChildren(node, checkLength) {
2452
+ if (!node) return false;
2453
+ const base = node.props ? node.props.children : node.children;
2454
+ if (checkLength) return base.length > 0;
2455
+ return !!base;
2456
+ }
2457
+ function getChildren(node) {
2458
+ if (!node) return [];
2459
+ return node.props ? node.props.children : node.children;
2460
+ }
2461
+ function hasValidReactChildren(children) {
2462
+ if (Object.prototype.toString.call(children) !== '[object Array]') return false;
2463
+ return children.every(child => isValidElement(child));
2464
+ }
2465
+ function getAsArray(data) {
2466
+ return Array.isArray(data) ? data : [data];
2467
+ }
2468
+ function mergeProps(source, target) {
2469
+ const newTarget = {
2470
+ ...target
2471
+ };
2472
+ newTarget.props = Object.assign(source.props, target.props);
2473
+ return newTarget;
2474
+ }
2475
+ function nodesToString(children, i18nOptions) {
2476
+ if (!children) return '';
2477
+ let stringNode = '';
2478
+ const childrenArray = getAsArray(children);
2479
+ const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
2480
+ childrenArray.forEach((child, childIndex) => {
2481
+ if (typeof child === 'string') {
2482
+ stringNode += `${child}`;
2483
+ } else if (isValidElement(child)) {
2484
+ const childPropsCount = Object.keys(child.props).length;
2485
+ const shouldKeepChild = keepArray.indexOf(child.type) > -1;
2486
+ const childChildren = child.props.children;
2487
+ if (!childChildren && shouldKeepChild && childPropsCount === 0) {
2488
+ stringNode += `<${child.type}/>`;
2489
+ } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
2490
+ stringNode += `<${childIndex}></${childIndex}>`;
2491
+ } else if (child.props.i18nIsDynamicList) {
2492
+ stringNode += `<${childIndex}></${childIndex}>`;
2493
+ } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
2494
+ stringNode += `<${child.type}>${childChildren}</${child.type}>`;
2495
+ } else {
2496
+ const content = nodesToString(childChildren, i18nOptions);
2497
+ stringNode += `<${childIndex}>${content}</${childIndex}>`;
2498
+ }
2499
+ } else if (child === null) {
2500
+ warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
2501
+ } else if (typeof child === 'object') {
2502
+ const {
2503
+ format,
2504
+ ...clone
2505
+ } = child;
2506
+ const keys = Object.keys(clone);
2507
+ if (keys.length === 1) {
2508
+ const value = format ? `${keys[0]}, ${format}` : keys[0];
2509
+ stringNode += `{{${value}}}`;
2510
+ } else {
2511
+ warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
2512
+ }
2513
+ } else {
2514
+ warn(`Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.`, child);
2515
+ }
2516
+ });
2517
+ return stringNode;
2518
+ }
2519
+ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
2520
+ if (targetString === '') return [];
2521
+ const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
2522
+ const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
2523
+ if (!children && !emptyChildrenButNeedsHandling) return [targetString];
2524
+ const data = {};
2525
+ function getData(childs) {
2526
+ const childrenArray = getAsArray(childs);
2527
+ childrenArray.forEach(child => {
2528
+ if (typeof child === 'string') return;
2529
+ if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !isValidElement(child)) Object.assign(data, child);
2530
+ });
2531
+ }
2532
+ getData(children);
2533
+ const ast = c.parse(`<0>${targetString}</0>`);
2534
+ const opts = {
2535
+ ...data,
2536
+ ...combinedTOpts
2537
+ };
2538
+ function renderInner(child, node, rootReactNode) {
2539
+ const childs = getChildren(child);
2540
+ const mappedChildren = mapAST(childs, node.children, rootReactNode);
2541
+ return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
2542
+ }
2543
+ function pushTranslatedJSX(child, inner, mem, i, isVoid) {
2544
+ if (child.dummy) child.children = inner;
2545
+ mem.push(cloneElement(child, {
2546
+ ...child.props,
2547
+ key: i
2548
+ }, isVoid ? undefined : inner));
2549
+ }
2550
+ function mapAST(reactNode, astNode, rootReactNode) {
2551
+ const reactNodes = getAsArray(reactNode);
2552
+ const astNodes = getAsArray(astNode);
2553
+ return astNodes.reduce((mem, node, i) => {
2554
+ const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
2555
+ if (node.type === 'tag') {
2556
+ let tmp = reactNodes[parseInt(node.name, 10)];
2557
+ if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
2558
+ if (!tmp) tmp = {};
2559
+ const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
2560
+ props: node.attrs
2561
+ }, tmp) : tmp;
2562
+ const isElement = isValidElement(child);
2563
+ const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
2564
+ const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
2565
+ const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
2566
+ if (typeof child === 'string') {
2567
+ const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
2568
+ mem.push(value);
2569
+ } else if (hasChildren(child) || isValidTranslationWithChildren) {
2570
+ const inner = renderInner(child, node, rootReactNode);
2571
+ pushTranslatedJSX(child, inner, mem, i);
2572
+ } else if (isEmptyTransWithHTML) {
2573
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
2574
+ mem.push(cloneElement(child, {
2575
+ ...child.props,
2576
+ key: i
2577
+ }, inner));
2578
+ } else if (Number.isNaN(parseFloat(node.name))) {
2579
+ if (isKnownComponent) {
2580
+ const inner = renderInner(child, node, rootReactNode);
2581
+ pushTranslatedJSX(child, inner, mem, i, node.voidElement);
2582
+ } else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
2583
+ if (node.voidElement) {
2584
+ mem.push(createElement(node.name, {
2585
+ key: `${node.name}-${i}`
2586
+ }));
2587
+ } else {
2588
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
2589
+ mem.push(createElement(node.name, {
2590
+ key: `${node.name}-${i}`
2591
+ }, inner));
2592
+ }
2593
+ } else if (node.voidElement) {
2594
+ mem.push(`<${node.name} />`);
2595
+ } else {
2596
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
2597
+ mem.push(`<${node.name}>${inner}</${node.name}>`);
2598
+ }
2599
+ } else if (typeof child === 'object' && !isElement) {
2600
+ const content = node.children[0] ? translationContent : null;
2601
+ if (content) mem.push(content);
2602
+ } else if (node.children.length === 1 && translationContent) {
2603
+ mem.push(cloneElement(child, {
2604
+ ...child.props,
2605
+ key: i
2606
+ }, translationContent));
2607
+ } else {
2608
+ mem.push(cloneElement(child, {
2609
+ ...child.props,
2610
+ key: i
2611
+ }));
2612
+ }
2613
+ } else if (node.type === 'text') {
2614
+ const wrapTextNodes = i18nOptions.transWrapTextNodes;
2615
+ const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
2616
+ if (wrapTextNodes) {
2617
+ mem.push(createElement(wrapTextNodes, {
2618
+ key: `${node.name}-${i}`
2619
+ }, content));
2620
+ } else {
2621
+ mem.push(content);
2622
+ }
2623
+ }
2624
+ return mem;
2625
+ }, []);
2626
+ }
2627
+ const result = mapAST([{
2628
+ dummy: true,
2629
+ children: children || []
2630
+ }], ast, getAsArray(children || []));
2631
+ return getChildren(result[0]);
2632
+ }
2633
+ function Trans$1(_ref) {
2634
+ let {
2635
+ children,
2636
+ count,
2637
+ parent,
2638
+ i18nKey,
2639
+ context,
2640
+ tOptions = {},
2641
+ values,
2642
+ defaults,
2643
+ components,
2644
+ ns,
2645
+ i18n: i18nFromProps,
2646
+ t: tFromProps,
2647
+ shouldUnescape,
2648
+ ...additionalProps
2649
+ } = _ref;
2650
+ const i18n = i18nFromProps || getI18n();
2651
+ if (!i18n) {
2652
+ warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
2653
+ return children;
2654
+ }
2655
+ const t = tFromProps || i18n.t.bind(i18n) || (k => k);
2656
+ if (context) tOptions.context = context;
2657
+ const reactI18nextOptions = {
2658
+ ...getDefaults(),
2659
+ ...(i18n.options && i18n.options.react)
2660
+ };
2661
+ let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
2662
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
2663
+ const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
2664
+ const {
2665
+ hashTransKey
2666
+ } = reactI18nextOptions;
2667
+ const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
2668
+ const interpolationOverride = values ? tOptions.interpolation : {
2669
+ interpolation: {
2670
+ ...tOptions.interpolation,
2671
+ prefix: '#$?',
2672
+ suffix: '?$#'
2673
+ }
2674
+ };
2675
+ const combinedTOpts = {
2676
+ ...tOptions,
2677
+ count,
2678
+ ...values,
2679
+ ...interpolationOverride,
2680
+ defaultValue,
2681
+ ns: namespaces
2682
+ };
2683
+ const translation = key ? t(key, combinedTOpts) : defaultValue;
2684
+ const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
2685
+ const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
2686
+ return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
2687
+ }
2688
+
2689
+ const initReactI18next = {
2690
+ type: '3rdParty',
2691
+ init(instance) {
2692
+ setDefaults(instance.options.react);
2693
+ setI18n(instance);
2694
+ }
2695
+ };
2696
+
2697
+ const I18nContext = createContext();
2698
+ class ReportNamespaces {
2699
+ constructor() {
2700
+ this.usedNamespaces = {};
2701
+ }
2702
+ addUsedNamespaces(namespaces) {
2703
+ namespaces.forEach(ns => {
2704
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
2705
+ });
2706
+ }
2707
+ getUsedNamespaces() {
2708
+ return Object.keys(this.usedNamespaces);
2709
+ }
2710
+ }
2711
+
2712
+ function Trans(_ref) {
2713
+ let {
2714
+ children,
2715
+ count,
2716
+ parent,
2717
+ i18nKey,
2718
+ context,
2719
+ tOptions = {},
2720
+ values,
2721
+ defaults,
2722
+ components,
2723
+ ns,
2724
+ i18n: i18nFromProps,
2725
+ t: tFromProps,
2726
+ shouldUnescape,
2727
+ ...additionalProps
2728
+ } = _ref;
2729
+ const {
2730
+ i18n: i18nFromContext,
2731
+ defaultNS: defaultNSFromContext
2732
+ } = useContext(I18nContext) || {};
2733
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
2734
+ const t = tFromProps || i18n && i18n.t.bind(i18n);
2735
+ return Trans$1({
2736
+ children,
2737
+ count,
2738
+ parent,
2739
+ i18nKey,
2740
+ context,
2741
+ tOptions,
2742
+ values,
2743
+ defaults,
2744
+ components,
2745
+ ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
2746
+ i18n,
2747
+ t: tFromProps,
2748
+ shouldUnescape,
2749
+ ...additionalProps
2750
+ });
2751
+ }
2752
+
2753
+ const usePrevious = (value, ignore) => {
2754
+ const ref = useRef();
2755
+ useEffect(() => {
2756
+ ref.current = ignore ? ref.current : value;
2757
+ }, [value, ignore]);
2758
+ return ref.current;
2759
+ };
2760
+ function useTranslation(ns) {
2761
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2762
+ const {
2763
+ i18n: i18nFromProps
2764
+ } = props;
2765
+ const {
2766
+ i18n: i18nFromContext,
2767
+ defaultNS: defaultNSFromContext
2768
+ } = useContext(I18nContext) || {};
2769
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
2770
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
2771
+ if (!i18n) {
2772
+ warnOnce('You will need to pass in an i18next instance by using initReactI18next');
2773
+ const notReadyT = (k, optsOrDefaultValue) => {
2774
+ if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
2775
+ if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
2776
+ return Array.isArray(k) ? k[k.length - 1] : k;
2777
+ };
2778
+ const retNotReady = [notReadyT, {}, false];
2779
+ retNotReady.t = notReadyT;
2780
+ retNotReady.i18n = {};
2781
+ retNotReady.ready = false;
2782
+ return retNotReady;
2783
+ }
2784
+ if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
2785
+ const i18nOptions = {
2786
+ ...getDefaults(),
2787
+ ...i18n.options.react,
2788
+ ...props
2789
+ };
2790
+ const {
2791
+ useSuspense,
2792
+ keyPrefix
2793
+ } = i18nOptions;
2794
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
2795
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
2796
+ if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
2797
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
2798
+ function getT() {
2799
+ return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
2800
+ }
2801
+ const [t, setT] = useState(getT);
2802
+ let joinedNS = namespaces.join();
2803
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
2804
+ const previousJoinedNS = usePrevious(joinedNS);
2805
+ const isMounted = useRef(true);
2806
+ useEffect(() => {
2807
+ const {
2808
+ bindI18n,
2809
+ bindI18nStore
2810
+ } = i18nOptions;
2811
+ isMounted.current = true;
2812
+ if (!ready && !useSuspense) {
2813
+ if (props.lng) {
2814
+ loadLanguages(i18n, props.lng, namespaces, () => {
2815
+ if (isMounted.current) setT(getT);
2816
+ });
2817
+ } else {
2818
+ loadNamespaces(i18n, namespaces, () => {
2819
+ if (isMounted.current) setT(getT);
2820
+ });
2821
+ }
2822
+ }
2823
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
2824
+ setT(getT);
2825
+ }
2826
+ function boundReset() {
2827
+ if (isMounted.current) setT(getT);
2828
+ }
2829
+ if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
2830
+ if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
2831
+ return () => {
2832
+ isMounted.current = false;
2833
+ if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
2834
+ if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
2835
+ };
2836
+ }, [i18n, joinedNS]);
2837
+ const isInitial = useRef(true);
2838
+ useEffect(() => {
2839
+ if (isMounted.current && !isInitial.current) {
2840
+ setT(getT);
2841
+ }
2842
+ isInitial.current = false;
2843
+ }, [i18n, keyPrefix]);
2844
+ const ret = [t, i18n, ready];
2845
+ ret.t = t;
2846
+ ret.i18n = i18n;
2847
+ ret.ready = ready;
2848
+ if (ready) return ret;
2849
+ if (!ready && !useSuspense) return ret;
2850
+ throw new Promise(resolve => {
2851
+ if (props.lng) {
2852
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
2853
+ } else {
2854
+ loadNamespaces(i18n, namespaces, () => resolve());
2855
+ }
2856
+ });
2857
+ }
2858
+
21
2859
  var common = {
22
2860
  apiKey_one: "API key",
23
2861
  apiKey_other: "API keys",
@@ -93,7 +2931,7 @@ var en = {
93
2931
  tags: tags
94
2932
  };
95
2933
 
96
- i18n.use(initReactI18next).init({
2934
+ instance.use(initReactI18next).init({
97
2935
  resources: {
98
2936
  en: {
99
2937
  translation: en
@@ -238,18 +3076,12 @@ var useDeleteApiKey = function useDeleteApiKey(onSuccess) {
238
3076
  });
239
3077
  };
240
3078
 
241
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
242
-
243
- function getDefaultExportFromCjs (x) {
244
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
245
- }
246
-
247
3079
  var dayjs_min = {exports: {}};
248
3080
 
249
3081
  dayjs_min.exports;
250
3082
 
251
3083
  (function (module, exports) {
252
- !function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return "["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p=function(t){return t instanceof b},S=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(g=i),i||!r&&g},w=function(t,e){if(p(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new b(n)},O=v;O.l=S,O.i=p,O.w=function(t,e){return w(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var b=function(){function M(t){this.$L=S(t.locale,null,!0),this.parse(t);}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(O.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.$x=t.x||{},this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return O},m.isValid=function(){return !(this.$d.toString()===l)},m.isSame=function(t,e){var n=w(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return w(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<w(t)},m.$g=function(t,e,n){return O.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!O.u(e)||e,f=O.p(t),l=function(t,e){var i=O.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return O.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=O.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[O.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=O.p(f),y=function(t){var e=w(l);return O.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return O.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=O.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return O.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return O.s(e.$y,4,"0");case"M":return a+1;case"MM":return O.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return O.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return O.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return O.s(u,2,"0");case"s":return String(e.$s);case"ss":return O.s(e.$s,2,"0");case"SSS":return O.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=O.p(d),m=w(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return O.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g;}return l?$:O.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=S(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return O.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),_=b.prototype;return w.prototype=_,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){_[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),w.extend=function(t,e){return t.$i||(t(e,b,w),t.$i=!0),w},w.locale=S,w.isDayjs=p,w.unix=function(t){return w(1e3*t)},w.en=D[g],w.Ls=D,w.p={},w}));
3084
+ !function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return "["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0;}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return b},m.isValid=function(){return !(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g;}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
253
3085
  } (dayjs_min, dayjs_min.exports));
254
3086
 
255
3087
  var dayjs_minExports = dayjs_min.exports;
@@ -287,12 +3119,12 @@ var buildColumnData = function buildColumnData(_ref) {
287
3119
  var _handleDelete = _ref.handleDelete,
288
3120
  _handleEdit = _ref.handleEdit;
289
3121
  return [{
290
- title: t("table.headers.label"),
3122
+ title: t$1("table.headers.label"),
291
3123
  key: "label",
292
3124
  dataIndex: "label",
293
3125
  width: "20%"
294
3126
  }, {
295
- title: t("table.headers.token"),
3127
+ title: t$1("table.headers.token"),
296
3128
  key: "token",
297
3129
  dataIndex: "token",
298
3130
  width: "30%",
@@ -306,49 +3138,49 @@ var buildColumnData = function buildColumnData(_ref) {
306
3138
  iconsSize: 28,
307
3139
  style: "text",
308
3140
  tooltipProps: {
309
- content: t("tooltips.copyToClipboard", {
3141
+ content: t$1("tooltips.copyToClipboard", {
310
3142
  token: token
311
3143
  }),
312
3144
  position: "top"
313
3145
  },
314
3146
  onClick: function onClick() {
315
3147
  return copyToClipboard(token, {
316
- message: t("notifications.copiedToClipboard")
3148
+ message: t$1("notifications.copiedToClipboard")
317
3149
  });
318
3150
  }
319
3151
  }));
320
3152
  }
321
3153
  }, {
322
- title: t("table.headers.status"),
3154
+ title: t$1("table.headers.status"),
323
3155
  key: "status",
324
3156
  width: "15%",
325
3157
  render: function render(_, _ref2) {
326
3158
  var expiresAt = _ref2.expiresAt;
327
3159
  return isPresent(expiresAt) && isInPast(expiresAt) ? /*#__PURE__*/React.createElement(Tag, {
328
3160
  style: "warning"
329
- }, t("tags.expired")) : /*#__PURE__*/React.createElement(Tag, {
3161
+ }, t$1("tags.expired")) : /*#__PURE__*/React.createElement(Tag, {
330
3162
  style: "success"
331
- }, t("tags.active"));
3163
+ }, t$1("tags.active"));
332
3164
  }
333
3165
  }, {
334
- title: t("table.headers.expiresAt"),
3166
+ title: t$1("table.headers.expiresAt"),
335
3167
  key: "expiresAt",
336
3168
  dataIndex: "expiresAt",
337
3169
  width: "15%",
338
3170
  render: function render(expiresAt) {
339
3171
  return isPresent(expiresAt) ? formatExpiry(expiresAt) : /*#__PURE__*/React.createElement(Typography, {
340
3172
  style: "body2"
341
- }, t("common.never"));
3173
+ }, t$1("common.never"));
342
3174
  }
343
3175
  }, {
344
- title: t("table.headers.createdAt"),
3176
+ title: t$1("table.headers.createdAt"),
345
3177
  key: "createdAt",
346
3178
  dataIndex: "createdAt",
347
3179
  width: "15%",
348
3180
  render: function render(createdAt) {
349
3181
  return isPresent(createdAt) ? dateFormat.dateTime(createdAt) : /*#__PURE__*/React.createElement(Typography, {
350
3182
  style: "body2"
351
- }, t("common.never"));
3183
+ }, t$1("common.never"));
352
3184
  }
353
3185
  }, {
354
3186
  key: "opitons",
@@ -412,14 +3244,14 @@ var INITIAL_VALUES = {
412
3244
  var NEXT_DAY = dayjs().add(1, "day").startOf("day");
413
3245
  var VALIDATION_SCHEMA = yup.object({
414
3246
  expiresAt: yup.date().when("hasNoExpiry", function (hasNoExpiry, field) {
415
- return hasNoExpiry ? field.nullable() : field.nullable().required(t("validations.required", {
416
- entity: t("fields.expiryDate")
417
- })).min(NEXT_DAY, t("validations.expiry", {
3247
+ return hasNoExpiry ? field.nullable() : field.nullable().required(t$1("validations.required", {
3248
+ entity: t$1("fields.expiryDate")
3249
+ })).min(NEXT_DAY, t$1("validations.expiry", {
418
3250
  date: dateFormat.date(NEXT_DAY)
419
3251
  }));
420
3252
  }),
421
- label: yup.string().required(t("validations.required", {
422
- entity: t("fields.label")
3253
+ label: yup.string().required(t$1("validations.required", {
3254
+ entity: t$1("fields.label")
423
3255
  }))
424
3256
  });
425
3257
  var DEFAULT_PAGE_SIZE = 15;
@@ -779,7 +3611,7 @@ var ApiKeys = function ApiKeys(_ref) {
779
3611
  }
780
3612
  }));
781
3613
  };
782
- var index = withTitle(ApiKeys, t("common.apiKey", PLURAL));
3614
+ var index = withTitle(ApiKeys, t$1("common.apiKey", PLURAL));
783
3615
 
784
3616
  export { index as ApiKeys };
785
3617
  //# sourceMappingURL=index.js.map