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

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