react-i18next 12.3.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +1 -1
  3. package/TransWithoutContext.d.ts +26 -16
  4. package/dist/amd/react-i18next.js +827 -1104
  5. package/dist/amd/react-i18next.min.js +1 -1
  6. package/dist/commonjs/I18nextProvider.js +10 -13
  7. package/dist/commonjs/Trans.js +37 -52
  8. package/dist/commonjs/TransWithoutContext.js +130 -168
  9. package/dist/commonjs/Translation.js +8 -22
  10. package/dist/commonjs/context.js +45 -76
  11. package/dist/commonjs/defaults.js +7 -16
  12. package/dist/commonjs/i18nInstance.js +2 -4
  13. package/dist/commonjs/index.js +52 -86
  14. package/dist/commonjs/initReactI18next.js +2 -5
  15. package/dist/commonjs/unescape.js +4 -11
  16. package/dist/commonjs/useSSR.js +10 -14
  17. package/dist/commonjs/useTranslation.js +57 -79
  18. package/dist/commonjs/utils.js +38 -47
  19. package/dist/commonjs/withSSR.js +9 -23
  20. package/dist/commonjs/withTranslation.js +18 -45
  21. package/dist/es/I18nextProvider.js +10 -10
  22. package/dist/es/Trans.js +36 -43
  23. package/dist/es/TransWithoutContext.js +129 -159
  24. package/dist/es/Translation.js +7 -14
  25. package/dist/es/context.js +30 -50
  26. package/dist/es/defaults.js +7 -10
  27. package/dist/es/i18nInstance.js +1 -1
  28. package/dist/es/index.js +6 -18
  29. package/dist/es/initReactI18next.js +2 -2
  30. package/dist/es/package.json +1 -1
  31. package/dist/es/unescape.js +4 -10
  32. package/dist/es/useSSR.js +10 -11
  33. package/dist/es/useTranslation.js +58 -73
  34. package/dist/es/utils.js +34 -39
  35. package/dist/es/withSSR.js +9 -15
  36. package/dist/es/withTranslation.js +17 -35
  37. package/dist/umd/react-i18next.js +828 -1105
  38. package/dist/umd/react-i18next.min.js +1 -1
  39. package/helpers.d.ts +3 -0
  40. package/icu.macro.d.ts +37 -39
  41. package/index.d.ts +44 -37
  42. package/initReactI18next.d.ts +1 -1
  43. package/package.json +36 -36
  44. package/react-i18next.js +828 -1105
  45. package/react-i18next.min.js +1 -1
  46. package/src/useTranslation.js +17 -8
  47. package/src/utils.js +27 -15
@@ -1,1104 +1,827 @@
1
- define(['exports', 'react'], function (exports, react) { 'use strict';
2
-
3
- function ownKeys(object, enumerableOnly) {
4
- var keys = Object.keys(object);
5
-
6
- if (Object.getOwnPropertySymbols) {
7
- var symbols = Object.getOwnPropertySymbols(object);
8
-
9
- if (enumerableOnly) {
10
- symbols = symbols.filter(function (sym) {
11
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
12
- });
13
- }
14
-
15
- keys.push.apply(keys, symbols);
16
- }
17
-
18
- return keys;
19
- }
20
-
21
- function _objectSpread2(target) {
22
- for (var i = 1; i < arguments.length; i++) {
23
- var source = arguments[i] != null ? arguments[i] : {};
24
-
25
- if (i % 2) {
26
- ownKeys(Object(source), true).forEach(function (key) {
27
- _defineProperty(target, key, source[key]);
28
- });
29
- } else if (Object.getOwnPropertyDescriptors) {
30
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
31
- } else {
32
- ownKeys(Object(source)).forEach(function (key) {
33
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
34
- });
35
- }
36
- }
37
-
38
- return target;
39
- }
40
-
41
- function _typeof(obj) {
42
- "@babel/helpers - typeof";
43
-
44
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
45
- _typeof = function (obj) {
46
- return typeof obj;
47
- };
48
- } else {
49
- _typeof = function (obj) {
50
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
51
- };
52
- }
53
-
54
- return _typeof(obj);
55
- }
56
-
57
- function _classCallCheck(instance, Constructor) {
58
- if (!(instance instanceof Constructor)) {
59
- throw new TypeError("Cannot call a class as a function");
60
- }
61
- }
62
-
63
- function _defineProperties(target, props) {
64
- for (var i = 0; i < props.length; i++) {
65
- var descriptor = props[i];
66
- descriptor.enumerable = descriptor.enumerable || false;
67
- descriptor.configurable = true;
68
- if ("value" in descriptor) descriptor.writable = true;
69
- Object.defineProperty(target, descriptor.key, descriptor);
70
- }
71
- }
72
-
73
- function _createClass(Constructor, protoProps, staticProps) {
74
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
75
- if (staticProps) _defineProperties(Constructor, staticProps);
76
- return Constructor;
77
- }
78
-
79
- function _defineProperty(obj, key, value) {
80
- if (key in obj) {
81
- Object.defineProperty(obj, key, {
82
- value: value,
83
- enumerable: true,
84
- configurable: true,
85
- writable: true
86
- });
87
- } else {
88
- obj[key] = value;
89
- }
90
-
91
- return obj;
92
- }
93
-
94
- function _objectWithoutPropertiesLoose(source, excluded) {
95
- if (source == null) return {};
96
- var target = {};
97
- var sourceKeys = Object.keys(source);
98
- var key, i;
99
-
100
- for (i = 0; i < sourceKeys.length; i++) {
101
- key = sourceKeys[i];
102
- if (excluded.indexOf(key) >= 0) continue;
103
- target[key] = source[key];
104
- }
105
-
106
- return target;
107
- }
108
-
109
- function _objectWithoutProperties(source, excluded) {
110
- if (source == null) return {};
111
-
112
- var target = _objectWithoutPropertiesLoose(source, excluded);
113
-
114
- var key, i;
115
-
116
- if (Object.getOwnPropertySymbols) {
117
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
118
-
119
- for (i = 0; i < sourceSymbolKeys.length; i++) {
120
- key = sourceSymbolKeys[i];
121
- if (excluded.indexOf(key) >= 0) continue;
122
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
123
- target[key] = source[key];
124
- }
125
- }
126
-
127
- return target;
128
- }
129
-
130
- function _slicedToArray(arr, i) {
131
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
132
- }
133
-
134
- function _arrayWithHoles(arr) {
135
- if (Array.isArray(arr)) return arr;
136
- }
137
-
138
- function _iterableToArrayLimit(arr, i) {
139
- var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
140
-
141
- if (_i == null) return;
142
- var _arr = [];
143
- var _n = true;
144
- var _d = false;
145
-
146
- var _s, _e;
147
-
148
- try {
149
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
150
- _arr.push(_s.value);
151
-
152
- if (i && _arr.length === i) break;
153
- }
154
- } catch (err) {
155
- _d = true;
156
- _e = err;
157
- } finally {
158
- try {
159
- if (!_n && _i["return"] != null) _i["return"]();
160
- } finally {
161
- if (_d) throw _e;
162
- }
163
- }
164
-
165
- return _arr;
166
- }
167
-
168
- function _unsupportedIterableToArray(o, minLen) {
169
- if (!o) return;
170
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
171
- var n = Object.prototype.toString.call(o).slice(8, -1);
172
- if (n === "Object" && o.constructor) n = o.constructor.name;
173
- if (n === "Map" || n === "Set") return Array.from(o);
174
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
175
- }
176
-
177
- function _arrayLikeToArray(arr, len) {
178
- if (len == null || len > arr.length) len = arr.length;
179
-
180
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
181
-
182
- return arr2;
183
- }
184
-
185
- function _nonIterableRest() {
186
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
187
- }
188
-
189
- var voidElements = {
190
- "area": true,
191
- "base": true,
192
- "br": true,
193
- "col": true,
194
- "embed": true,
195
- "hr": true,
196
- "img": true,
197
- "input": true,
198
- "link": true,
199
- "meta": true,
200
- "param": true,
201
- "source": true,
202
- "track": true,
203
- "wbr": true
204
- };
205
-
206
- var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
207
-
208
- function n(n) {
209
- var r = {
210
- type: "tag",
211
- name: "",
212
- voidElement: !1,
213
- attrs: {},
214
- children: []
215
- },
216
- i = n.match(/<\/?([^\s]+?)[/\s>]/);
217
-
218
- if (i && (r.name = i[1], (voidElements[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) {
219
- var s = n.indexOf("--\x3e");
220
- return {
221
- type: "comment",
222
- comment: -1 !== s ? n.slice(4, s) : ""
223
- };
224
- }
225
-
226
- for (var a = new RegExp(t), c = null; null !== (c = a.exec(n));) {
227
- if (c[0].trim()) if (c[1]) {
228
- var o = c[1].trim(),
229
- l = [o, ""];
230
- o.indexOf("=") > -1 && (l = o.split("=")), r.attrs[l[0]] = l[1], a.lastIndex--;
231
- } else c[2] && (r.attrs[c[2]] = c[3].trim().substring(1, c[3].length - 1));
232
- }
233
-
234
- return r;
235
- }
236
-
237
- var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,
238
- i = /^\s*$/,
239
- s = Object.create(null);
240
-
241
- function a(e, t) {
242
- switch (t.type) {
243
- case "text":
244
- return e + t.content;
245
-
246
- case "tag":
247
- return e += "<" + t.name + (t.attrs ? function (e) {
248
- var t = [];
249
-
250
- for (var n in e) {
251
- t.push(n + '="' + e[n] + '"');
252
- }
253
-
254
- return t.length ? " " + t.join(" ") : "";
255
- }(t.attrs) : "") + (t.voidElement ? "/>" : ">"), t.voidElement ? e : e + t.children.reduce(a, "") + "</" + t.name + ">";
256
-
257
- case "comment":
258
- return e + "\x3c!--" + t.comment + "--\x3e";
259
- }
260
- }
261
-
262
- var c = {
263
- parse: function parse(e, t) {
264
- t || (t = {}), t.components || (t.components = s);
265
- var a,
266
- c = [],
267
- o = [],
268
- l = -1,
269
- m = !1;
270
-
271
- if (0 !== e.indexOf("<")) {
272
- var u = e.indexOf("<");
273
- c.push({
274
- type: "text",
275
- content: -1 === u ? e : e.substring(0, u)
276
- });
277
- }
278
-
279
- return e.replace(r, function (r, s) {
280
- if (m) {
281
- if (r !== "</" + a.name + ">") return;
282
- m = !1;
283
- }
284
-
285
- var u,
286
- f = "/" !== r.charAt(1),
287
- h = r.startsWith("\x3c!--"),
288
- p = s + r.length,
289
- d = e.charAt(p);
290
-
291
- if (h) {
292
- var v = n(r);
293
- return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
294
- }
295
-
296
- 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({
297
- type: "text",
298
- content: e.slice(p, e.indexOf("<", p))
299
- }), 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)) {
300
- u = -1 === l ? c : o[l].children;
301
- var x = e.indexOf("<", p),
302
- g = e.slice(p, -1 === x ? void 0 : x);
303
- i.test(g) && (g = " "), (x > -1 && l + u.length >= 0 || " " !== g) && u.push({
304
- type: "text",
305
- content: g
306
- });
307
- }
308
- }), c;
309
- },
310
- stringify: function stringify(e) {
311
- return e.reduce(function (e, t) {
312
- return e + a("", t);
313
- }, "");
314
- }
315
- };
316
-
317
- function warn() {
318
- if (console && console.warn) {
319
- var _console;
320
-
321
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
322
- args[_key] = arguments[_key];
323
- }
324
-
325
- if (typeof args[0] === 'string') args[0] = "react-i18next:: ".concat(args[0]);
326
-
327
- (_console = console).warn.apply(_console, args);
328
- }
329
- }
330
- var alreadyWarned = {};
331
- function warnOnce() {
332
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
333
- args[_key2] = arguments[_key2];
334
- }
335
-
336
- if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
337
- if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
338
- warn.apply(void 0, args);
339
- }
340
- function loadNamespaces(i18n, ns, cb) {
341
- i18n.loadNamespaces(ns, function () {
342
- if (i18n.isInitialized) {
343
- cb();
344
- } else {
345
- var initialized = function initialized() {
346
- setTimeout(function () {
347
- i18n.off('initialized', initialized);
348
- }, 0);
349
- cb();
350
- };
351
-
352
- i18n.on('initialized', initialized);
353
- }
354
- });
355
- }
356
-
357
- function oldI18nextHasLoadedNamespace(ns, i18n) {
358
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
359
- var lng = i18n.languages[0];
360
- var fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
361
- var lastLng = i18n.languages[i18n.languages.length - 1];
362
- if (lng.toLowerCase() === 'cimode') return true;
363
-
364
- var loadNotPending = function loadNotPending(l, n) {
365
- var loadState = i18n.services.backendConnector.state["".concat(l, "|").concat(n)];
366
- return loadState === -1 || loadState === 2;
367
- };
368
-
369
- if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
370
- if (i18n.hasResourceBundle(lng, ns)) return true;
371
- if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
372
- if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
373
- return false;
374
- }
375
-
376
- function hasLoadedNamespace(ns, i18n) {
377
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
378
-
379
- if (!i18n.languages || !i18n.languages.length) {
380
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
381
- return true;
382
- }
383
-
384
- var isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
385
-
386
- if (!isNewerI18next) {
387
- return oldI18nextHasLoadedNamespace(ns, i18n, options);
388
- }
389
-
390
- return i18n.hasLoadedNamespace(ns, {
391
- precheck: function precheck(i18nInstance, loadNotPending) {
392
- if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
393
- }
394
- });
395
- }
396
- function getDisplayName(Component) {
397
- return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown');
398
- }
399
-
400
- var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
401
- var htmlEntities = {
402
- '&amp;': '&',
403
- '&#38;': '&',
404
- '&lt;': '<',
405
- '&#60;': '<',
406
- '&gt;': '>',
407
- '&#62;': '>',
408
- '&apos;': "'",
409
- '&#39;': "'",
410
- '&quot;': '"',
411
- '&#34;': '"',
412
- '&nbsp;': ' ',
413
- '&#160;': ' ',
414
- '&copy;': '©',
415
- '&#169;': '©',
416
- '&reg;': '®',
417
- '&#174;': '®',
418
- '&hellip;': '…',
419
- '&#8230;': '…',
420
- '&#x2F;': '/',
421
- '&#47;': '/'
422
- };
423
-
424
- var unescapeHtmlEntity = function unescapeHtmlEntity(m) {
425
- return htmlEntities[m];
426
- };
427
-
428
- var unescape = function unescape(text) {
429
- return text.replace(matchHtmlEntity, unescapeHtmlEntity);
430
- };
431
-
432
- var defaultOptions = {
433
- bindI18n: 'languageChanged',
434
- bindI18nStore: '',
435
- transEmptyNodeValue: '',
436
- transSupportBasicHtmlNodes: true,
437
- transWrapTextNodes: '',
438
- transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
439
- useSuspense: true,
440
- unescape: unescape
441
- };
442
- function setDefaults() {
443
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
444
- defaultOptions = _objectSpread2(_objectSpread2({}, defaultOptions), options);
445
- }
446
- function getDefaults() {
447
- return defaultOptions;
448
- }
449
-
450
- var i18nInstance;
451
- function setI18n(instance) {
452
- i18nInstance = instance;
453
- }
454
- function getI18n() {
455
- return i18nInstance;
456
- }
457
-
458
- var _excluded = ["format"],
459
- _excluded2 = ["children", "count", "parent", "i18nKey", "context", "tOptions", "values", "defaults", "components", "ns", "i18n", "t", "shouldUnescape"];
460
-
461
- function hasChildren(node, checkLength) {
462
- if (!node) return false;
463
- var base = node.props ? node.props.children : node.children;
464
- if (checkLength) return base.length > 0;
465
- return !!base;
466
- }
467
-
468
- function getChildren(node) {
469
- if (!node) return [];
470
- return node.props ? node.props.children : node.children;
471
- }
472
-
473
- function hasValidReactChildren(children) {
474
- if (Object.prototype.toString.call(children) !== '[object Array]') return false;
475
- return children.every(function (child) {
476
- return react.isValidElement(child);
477
- });
478
- }
479
-
480
- function getAsArray(data) {
481
- return Array.isArray(data) ? data : [data];
482
- }
483
-
484
- function mergeProps(source, target) {
485
- var newTarget = _objectSpread2({}, target);
486
-
487
- newTarget.props = Object.assign(source.props, target.props);
488
- return newTarget;
489
- }
490
-
491
- function nodesToString(children, i18nOptions) {
492
- if (!children) return '';
493
- var stringNode = '';
494
- var childrenArray = getAsArray(children);
495
- var keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
496
- childrenArray.forEach(function (child, childIndex) {
497
- if (typeof child === 'string') {
498
- stringNode += "".concat(child);
499
- } else if (react.isValidElement(child)) {
500
- var childPropsCount = Object.keys(child.props).length;
501
- var shouldKeepChild = keepArray.indexOf(child.type) > -1;
502
- var childChildren = child.props.children;
503
-
504
- if (!childChildren && shouldKeepChild && childPropsCount === 0) {
505
- stringNode += "<".concat(child.type, "/>");
506
- } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
507
- stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
508
- } else if (child.props.i18nIsDynamicList) {
509
- stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
510
- } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
511
- stringNode += "<".concat(child.type, ">").concat(childChildren, "</").concat(child.type, ">");
512
- } else {
513
- var content = nodesToString(childChildren, i18nOptions);
514
- stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
515
- }
516
- } else if (child === null) {
517
- warn("Trans: the passed in value is invalid - seems you passed in a null child.");
518
- } else if (_typeof(child) === 'object') {
519
- var format = child.format,
520
- clone = _objectWithoutProperties(child, _excluded);
521
-
522
- var keys = Object.keys(clone);
523
-
524
- if (keys.length === 1) {
525
- var value = format ? "".concat(keys[0], ", ").concat(format) : keys[0];
526
- stringNode += "{{".concat(value, "}}");
527
- } else {
528
- warn("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.", child);
529
- }
530
- } else {
531
- 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);
532
- }
533
- });
534
- return stringNode;
535
- }
536
-
537
- function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
538
- if (targetString === '') return [];
539
- var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
540
- var emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
541
- if (!children && !emptyChildrenButNeedsHandling) return [targetString];
542
- var data = {};
543
-
544
- function getData(childs) {
545
- var childrenArray = getAsArray(childs);
546
- childrenArray.forEach(function (child) {
547
- if (typeof child === 'string') return;
548
- if (hasChildren(child)) getData(getChildren(child));else if (_typeof(child) === 'object' && !react.isValidElement(child)) Object.assign(data, child);
549
- });
550
- }
551
-
552
- getData(children);
553
- var ast = c.parse("<0>".concat(targetString, "</0>"));
554
-
555
- var opts = _objectSpread2(_objectSpread2({}, data), combinedTOpts);
556
-
557
- function renderInner(child, node, rootReactNode) {
558
- var childs = getChildren(child);
559
- var mappedChildren = mapAST(childs, node.children, rootReactNode);
560
- return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
561
- }
562
-
563
- function pushTranslatedJSX(child, inner, mem, i, isVoid) {
564
- if (child.dummy) child.children = inner;
565
- mem.push(react.cloneElement(child, _objectSpread2(_objectSpread2({}, child.props), {}, {
566
- key: i
567
- }), isVoid ? undefined : inner));
568
- }
569
-
570
- function mapAST(reactNode, astNode, rootReactNode) {
571
- var reactNodes = getAsArray(reactNode);
572
- var astNodes = getAsArray(astNode);
573
- return astNodes.reduce(function (mem, node, i) {
574
- var translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
575
-
576
- if (node.type === 'tag') {
577
- var tmp = reactNodes[parseInt(node.name, 10)];
578
- if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
579
- if (!tmp) tmp = {};
580
- var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
581
- props: node.attrs
582
- }, tmp) : tmp;
583
- var isElement = react.isValidElement(child);
584
- var isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
585
- var isEmptyTransWithHTML = emptyChildrenButNeedsHandling && _typeof(child) === 'object' && child.dummy && !isElement;
586
- var isKnownComponent = _typeof(children) === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
587
-
588
- if (typeof child === 'string') {
589
- var value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
590
- mem.push(value);
591
- } else if (hasChildren(child) || isValidTranslationWithChildren) {
592
- var inner = renderInner(child, node, rootReactNode);
593
- pushTranslatedJSX(child, inner, mem, i);
594
- } else if (isEmptyTransWithHTML) {
595
- var _inner = mapAST(reactNodes, node.children, rootReactNode);
596
-
597
- mem.push(react.cloneElement(child, _objectSpread2(_objectSpread2({}, child.props), {}, {
598
- key: i
599
- }), _inner));
600
- } else if (Number.isNaN(parseFloat(node.name))) {
601
- if (isKnownComponent) {
602
- var _inner2 = renderInner(child, node, rootReactNode);
603
-
604
- pushTranslatedJSX(child, _inner2, mem, i, node.voidElement);
605
- } else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
606
- if (node.voidElement) {
607
- mem.push(react.createElement(node.name, {
608
- key: "".concat(node.name, "-").concat(i)
609
- }));
610
- } else {
611
- var _inner3 = mapAST(reactNodes, node.children, rootReactNode);
612
-
613
- mem.push(react.createElement(node.name, {
614
- key: "".concat(node.name, "-").concat(i)
615
- }, _inner3));
616
- }
617
- } else if (node.voidElement) {
618
- mem.push("<".concat(node.name, " />"));
619
- } else {
620
- var _inner4 = mapAST(reactNodes, node.children, rootReactNode);
621
-
622
- mem.push("<".concat(node.name, ">").concat(_inner4, "</").concat(node.name, ">"));
623
- }
624
- } else if (_typeof(child) === 'object' && !isElement) {
625
- var content = node.children[0] ? translationContent : null;
626
- if (content) mem.push(content);
627
- } else if (node.children.length === 1 && translationContent) {
628
- mem.push(react.cloneElement(child, _objectSpread2(_objectSpread2({}, child.props), {}, {
629
- key: i
630
- }), translationContent));
631
- } else {
632
- mem.push(react.cloneElement(child, _objectSpread2(_objectSpread2({}, child.props), {}, {
633
- key: i
634
- })));
635
- }
636
- } else if (node.type === 'text') {
637
- var wrapTextNodes = i18nOptions.transWrapTextNodes;
638
-
639
- var _content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
640
-
641
- if (wrapTextNodes) {
642
- mem.push(react.createElement(wrapTextNodes, {
643
- key: "".concat(node.name, "-").concat(i)
644
- }, _content));
645
- } else {
646
- mem.push(_content);
647
- }
648
- }
649
-
650
- return mem;
651
- }, []);
652
- }
653
-
654
- var result = mapAST([{
655
- dummy: true,
656
- children: children || []
657
- }], ast, getAsArray(children || []));
658
- return getChildren(result[0]);
659
- }
660
-
661
- function Trans(_ref) {
662
- var children = _ref.children,
663
- count = _ref.count,
664
- parent = _ref.parent,
665
- i18nKey = _ref.i18nKey,
666
- context = _ref.context,
667
- _ref$tOptions = _ref.tOptions,
668
- tOptions = _ref$tOptions === void 0 ? {} : _ref$tOptions,
669
- values = _ref.values,
670
- defaults = _ref.defaults,
671
- components = _ref.components,
672
- ns = _ref.ns,
673
- i18nFromProps = _ref.i18n,
674
- tFromProps = _ref.t,
675
- shouldUnescape = _ref.shouldUnescape,
676
- additionalProps = _objectWithoutProperties(_ref, _excluded2);
677
-
678
- var i18n = i18nFromProps || getI18n();
679
-
680
- if (!i18n) {
681
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
682
- return children;
683
- }
684
-
685
- var t = tFromProps || i18n.t.bind(i18n) || function (k) {
686
- return k;
687
- };
688
-
689
- if (context) tOptions.context = context;
690
-
691
- var reactI18nextOptions = _objectSpread2(_objectSpread2({}, getDefaults()), i18n.options && i18n.options.react);
692
-
693
- var namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
694
- namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
695
- var defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
696
- var hashTransKey = reactI18nextOptions.hashTransKey;
697
- var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
698
- var interpolationOverride = values ? tOptions.interpolation : {
699
- interpolation: _objectSpread2(_objectSpread2({}, tOptions.interpolation), {}, {
700
- prefix: '#$?',
701
- suffix: '?$#'
702
- })
703
- };
704
-
705
- var combinedTOpts = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, tOptions), {}, {
706
- count: count
707
- }, values), interpolationOverride), {}, {
708
- defaultValue: defaultValue,
709
- ns: namespaces
710
- });
711
-
712
- var translation = key ? t(key, combinedTOpts) : defaultValue;
713
- var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
714
- var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
715
- return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
716
- }
717
-
718
- var initReactI18next = {
719
- type: '3rdParty',
720
- init: function init(instance) {
721
- setDefaults(instance.options.react);
722
- setI18n(instance);
723
- }
724
- };
725
-
726
- var I18nContext = react.createContext();
727
- var ReportNamespaces = function () {
728
- function ReportNamespaces() {
729
- _classCallCheck(this, ReportNamespaces);
730
-
731
- this.usedNamespaces = {};
732
- }
733
-
734
- _createClass(ReportNamespaces, [{
735
- key: "addUsedNamespaces",
736
- value: function addUsedNamespaces(namespaces) {
737
- var _this = this;
738
-
739
- namespaces.forEach(function (ns) {
740
- if (!_this.usedNamespaces[ns]) _this.usedNamespaces[ns] = true;
741
- });
742
- }
743
- }, {
744
- key: "getUsedNamespaces",
745
- value: function getUsedNamespaces() {
746
- return Object.keys(this.usedNamespaces);
747
- }
748
- }]);
749
-
750
- return ReportNamespaces;
751
- }();
752
- function composeInitialProps(ForComponent) {
753
- return function (ctx) {
754
- return new Promise(function (resolve) {
755
- var i18nInitialProps = getInitialProps();
756
-
757
- if (ForComponent.getInitialProps) {
758
- ForComponent.getInitialProps(ctx).then(function (componentsInitialProps) {
759
- resolve(_objectSpread2(_objectSpread2({}, componentsInitialProps), i18nInitialProps));
760
- });
761
- } else {
762
- resolve(i18nInitialProps);
763
- }
764
- });
765
- };
766
- }
767
- function getInitialProps() {
768
- var i18n = getI18n();
769
- var namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
770
- var ret = {};
771
- var initialI18nStore = {};
772
- i18n.languages.forEach(function (l) {
773
- initialI18nStore[l] = {};
774
- namespaces.forEach(function (ns) {
775
- initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
776
- });
777
- });
778
- ret.initialI18nStore = initialI18nStore;
779
- ret.initialLanguage = i18n.language;
780
- return ret;
781
- }
782
-
783
- var _excluded$1 = ["children", "count", "parent", "i18nKey", "context", "tOptions", "values", "defaults", "components", "ns", "i18n", "t", "shouldUnescape"];
784
- function Trans$1(_ref) {
785
- var children = _ref.children,
786
- count = _ref.count,
787
- parent = _ref.parent,
788
- i18nKey = _ref.i18nKey,
789
- context = _ref.context,
790
- _ref$tOptions = _ref.tOptions,
791
- tOptions = _ref$tOptions === void 0 ? {} : _ref$tOptions,
792
- values = _ref.values,
793
- defaults = _ref.defaults,
794
- components = _ref.components,
795
- ns = _ref.ns,
796
- i18nFromProps = _ref.i18n,
797
- tFromProps = _ref.t,
798
- shouldUnescape = _ref.shouldUnescape,
799
- additionalProps = _objectWithoutProperties(_ref, _excluded$1);
800
-
801
- var _ref2 = react.useContext(I18nContext) || {},
802
- i18nFromContext = _ref2.i18n,
803
- defaultNSFromContext = _ref2.defaultNS;
804
-
805
- var i18n = i18nFromProps || i18nFromContext || getI18n();
806
- var t = tFromProps || i18n && i18n.t.bind(i18n);
807
- return Trans(_objectSpread2({
808
- children: children,
809
- count: count,
810
- parent: parent,
811
- i18nKey: i18nKey,
812
- context: context,
813
- tOptions: tOptions,
814
- values: values,
815
- defaults: defaults,
816
- components: components,
817
- ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
818
- i18n: i18n,
819
- t: tFromProps,
820
- shouldUnescape: shouldUnescape
821
- }, additionalProps));
822
- }
823
-
824
- var usePrevious = function usePrevious(value, ignore) {
825
- var ref = react.useRef();
826
- react.useEffect(function () {
827
- ref.current = ignore ? ref.current : value;
828
- }, [value, ignore]);
829
- return ref.current;
830
- };
831
-
832
- function useTranslation(ns) {
833
- var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
834
- var i18nFromProps = props.i18n;
835
-
836
- var _ref = react.useContext(I18nContext) || {},
837
- i18nFromContext = _ref.i18n,
838
- defaultNSFromContext = _ref.defaultNS;
839
-
840
- var i18n = i18nFromProps || i18nFromContext || getI18n();
841
- if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
842
-
843
- if (!i18n) {
844
- warnOnce('You will need to pass in an i18next instance by using initReactI18next');
845
-
846
- var notReadyT = function notReadyT(k, optsOrDefaultValue) {
847
- if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
848
- if (optsOrDefaultValue && _typeof(optsOrDefaultValue) === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
849
- return Array.isArray(k) ? k[k.length - 1] : k;
850
- };
851
-
852
- var retNotReady = [notReadyT, {}, false];
853
- retNotReady.t = notReadyT;
854
- retNotReady.i18n = {};
855
- retNotReady.ready = false;
856
- return retNotReady;
857
- }
858
-
859
- 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.');
860
-
861
- var i18nOptions = _objectSpread2(_objectSpread2(_objectSpread2({}, getDefaults()), i18n.options.react), props);
862
-
863
- var useSuspense = i18nOptions.useSuspense,
864
- keyPrefix = i18nOptions.keyPrefix;
865
- var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
866
- namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
867
- if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
868
- var ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(function (n) {
869
- return hasLoadedNamespace(n, i18n, i18nOptions);
870
- });
871
-
872
- function getT() {
873
- return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
874
- }
875
-
876
- var _useState = react.useState(getT),
877
- _useState2 = _slicedToArray(_useState, 2),
878
- t = _useState2[0],
879
- setT = _useState2[1];
880
-
881
- var joinedNS = namespaces.join();
882
- var previousJoinedNS = usePrevious(joinedNS);
883
- var isMounted = react.useRef(true);
884
- react.useEffect(function () {
885
- var bindI18n = i18nOptions.bindI18n,
886
- bindI18nStore = i18nOptions.bindI18nStore;
887
- isMounted.current = true;
888
-
889
- if (!ready && !useSuspense) {
890
- loadNamespaces(i18n, namespaces, function () {
891
- if (isMounted.current) setT(getT);
892
- });
893
- }
894
-
895
- if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
896
- setT(getT);
897
- }
898
-
899
- function boundReset() {
900
- if (isMounted.current) setT(getT);
901
- }
902
-
903
- if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
904
- if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
905
- return function () {
906
- isMounted.current = false;
907
- if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
908
- return i18n.off(e, boundReset);
909
- });
910
- if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(function (e) {
911
- return i18n.store.off(e, boundReset);
912
- });
913
- };
914
- }, [i18n, joinedNS]);
915
- var isInitial = react.useRef(true);
916
- react.useEffect(function () {
917
- if (isMounted.current && !isInitial.current) {
918
- setT(getT);
919
- }
920
-
921
- isInitial.current = false;
922
- }, [i18n, keyPrefix]);
923
- var ret = [t, i18n, ready];
924
- ret.t = t;
925
- ret.i18n = i18n;
926
- ret.ready = ready;
927
- if (ready) return ret;
928
- if (!ready && !useSuspense) return ret;
929
- throw new Promise(function (resolve) {
930
- loadNamespaces(i18n, namespaces, function () {
931
- resolve();
932
- });
933
- });
934
- }
935
-
936
- var _excluded$2 = ["forwardedRef"];
937
- function withTranslation(ns) {
938
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
939
- return function Extend(WrappedComponent) {
940
- function I18nextWithTranslation(_ref) {
941
- var forwardedRef = _ref.forwardedRef,
942
- rest = _objectWithoutProperties(_ref, _excluded$2);
943
-
944
- var _useTranslation = useTranslation(ns, _objectSpread2(_objectSpread2({}, rest), {}, {
945
- keyPrefix: options.keyPrefix
946
- })),
947
- _useTranslation2 = _slicedToArray(_useTranslation, 3),
948
- t = _useTranslation2[0],
949
- i18n = _useTranslation2[1],
950
- ready = _useTranslation2[2];
951
-
952
- var passDownProps = _objectSpread2(_objectSpread2({}, rest), {}, {
953
- t: t,
954
- i18n: i18n,
955
- tReady: ready
956
- });
957
-
958
- if (options.withRef && forwardedRef) {
959
- passDownProps.ref = forwardedRef;
960
- } else if (!options.withRef && forwardedRef) {
961
- passDownProps.forwardedRef = forwardedRef;
962
- }
963
-
964
- return react.createElement(WrappedComponent, passDownProps);
965
- }
966
-
967
- I18nextWithTranslation.displayName = "withI18nextTranslation(".concat(getDisplayName(WrappedComponent), ")");
968
- I18nextWithTranslation.WrappedComponent = WrappedComponent;
969
-
970
- var forwardRef = function forwardRef(props, ref) {
971
- return react.createElement(I18nextWithTranslation, Object.assign({}, props, {
972
- forwardedRef: ref
973
- }));
974
- };
975
-
976
- return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
977
- };
978
- }
979
-
980
- var _excluded$3 = ["ns", "children"];
981
- function Translation(props) {
982
- var ns = props.ns,
983
- children = props.children,
984
- options = _objectWithoutProperties(props, _excluded$3);
985
-
986
- var _useTranslation = useTranslation(ns, options),
987
- _useTranslation2 = _slicedToArray(_useTranslation, 3),
988
- t = _useTranslation2[0],
989
- i18n = _useTranslation2[1],
990
- ready = _useTranslation2[2];
991
-
992
- return children(t, {
993
- i18n: i18n,
994
- lng: i18n.language
995
- }, ready);
996
- }
997
-
998
- function I18nextProvider(_ref) {
999
- var i18n = _ref.i18n,
1000
- defaultNS = _ref.defaultNS,
1001
- children = _ref.children;
1002
- var value = react.useMemo(function () {
1003
- return {
1004
- i18n: i18n,
1005
- defaultNS: defaultNS
1006
- };
1007
- }, [i18n, defaultNS]);
1008
- return react.createElement(I18nContext.Provider, {
1009
- value: value
1010
- }, children);
1011
- }
1012
-
1013
- function useSSR(initialI18nStore, initialLanguage) {
1014
- var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1015
- var i18nFromProps = props.i18n;
1016
-
1017
- var _ref = react.useContext(I18nContext) || {},
1018
- i18nFromContext = _ref.i18n;
1019
-
1020
- var i18n = i18nFromProps || i18nFromContext || getI18n();
1021
- if (i18n.options && i18n.options.isClone) return;
1022
-
1023
- if (initialI18nStore && !i18n.initializedStoreOnce) {
1024
- i18n.services.resourceStore.data = initialI18nStore;
1025
- i18n.options.ns = Object.values(initialI18nStore).reduce(function (mem, lngResources) {
1026
- Object.keys(lngResources).forEach(function (ns) {
1027
- if (mem.indexOf(ns) < 0) mem.push(ns);
1028
- });
1029
- return mem;
1030
- }, i18n.options.ns);
1031
- i18n.initializedStoreOnce = true;
1032
- i18n.isInitialized = true;
1033
- }
1034
-
1035
- if (initialLanguage && !i18n.initializedLanguageOnce) {
1036
- i18n.changeLanguage(initialLanguage);
1037
- i18n.initializedLanguageOnce = true;
1038
- }
1039
- }
1040
-
1041
- var _excluded$4 = ["initialI18nStore", "initialLanguage"];
1042
- function withSSR() {
1043
- return function Extend(WrappedComponent) {
1044
- function I18nextWithSSR(_ref) {
1045
- var initialI18nStore = _ref.initialI18nStore,
1046
- initialLanguage = _ref.initialLanguage,
1047
- rest = _objectWithoutProperties(_ref, _excluded$4);
1048
-
1049
- useSSR(initialI18nStore, initialLanguage);
1050
- return react.createElement(WrappedComponent, _objectSpread2({}, rest));
1051
- }
1052
-
1053
- I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
1054
- I18nextWithSSR.displayName = "withI18nextSSR(".concat(getDisplayName(WrappedComponent), ")");
1055
- I18nextWithSSR.WrappedComponent = WrappedComponent;
1056
- return I18nextWithSSR;
1057
- };
1058
- }
1059
-
1060
- var date = function date() {
1061
- return '';
1062
- };
1063
- var time = function time() {
1064
- return '';
1065
- };
1066
- var number = function number() {
1067
- return '';
1068
- };
1069
- var select = function select() {
1070
- return '';
1071
- };
1072
- var plural = function plural() {
1073
- return '';
1074
- };
1075
- var selectOrdinal = function selectOrdinal() {
1076
- return '';
1077
- };
1078
-
1079
- exports.I18nContext = I18nContext;
1080
- exports.I18nextProvider = I18nextProvider;
1081
- exports.Trans = Trans$1;
1082
- exports.TransWithoutContext = Trans;
1083
- exports.Translation = Translation;
1084
- exports.composeInitialProps = composeInitialProps;
1085
- exports.date = date;
1086
- exports.getDefaults = getDefaults;
1087
- exports.getI18n = getI18n;
1088
- exports.getInitialProps = getInitialProps;
1089
- exports.initReactI18next = initReactI18next;
1090
- exports.number = number;
1091
- exports.plural = plural;
1092
- exports.select = select;
1093
- exports.selectOrdinal = selectOrdinal;
1094
- exports.setDefaults = setDefaults;
1095
- exports.setI18n = setI18n;
1096
- exports.time = time;
1097
- exports.useSSR = useSSR;
1098
- exports.useTranslation = useTranslation;
1099
- exports.withSSR = withSSR;
1100
- exports.withTranslation = withTranslation;
1101
-
1102
- Object.defineProperty(exports, '__esModule', { value: true });
1103
-
1104
- });
1
+ define(['exports', 'react'], (function (exports, react) { 'use strict';
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ var voidElements = {
8
+ "area": true,
9
+ "base": true,
10
+ "br": true,
11
+ "col": true,
12
+ "embed": true,
13
+ "hr": true,
14
+ "img": true,
15
+ "input": true,
16
+ "link": true,
17
+ "meta": true,
18
+ "param": true,
19
+ "source": true,
20
+ "track": true,
21
+ "wbr": true
22
+ };
23
+
24
+ var e = /*@__PURE__*/getDefaultExportFromCjs(voidElements);
25
+
26
+ var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
27
+ function n(n) {
28
+ var r = {
29
+ type: "tag",
30
+ name: "",
31
+ voidElement: !1,
32
+ attrs: {},
33
+ children: []
34
+ },
35
+ i = n.match(/<\/?([^\s]+?)[/\s>]/);
36
+ if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) {
37
+ var s = n.indexOf("--\x3e");
38
+ return {
39
+ type: "comment",
40
+ comment: -1 !== s ? n.slice(4, s) : ""
41
+ };
42
+ }
43
+ for (var a = new RegExp(t), c = null; null !== (c = a.exec(n));) if (c[0].trim()) if (c[1]) {
44
+ var o = c[1].trim(),
45
+ l = [o, ""];
46
+ o.indexOf("=") > -1 && (l = o.split("=")), r.attrs[l[0]] = l[1], a.lastIndex--;
47
+ } else c[2] && (r.attrs[c[2]] = c[3].trim().substring(1, c[3].length - 1));
48
+ return r;
49
+ }
50
+ var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,
51
+ i = /^\s*$/,
52
+ s = Object.create(null);
53
+ function a(e, t) {
54
+ switch (t.type) {
55
+ case "text":
56
+ return e + t.content;
57
+ case "tag":
58
+ return e += "<" + t.name + (t.attrs ? function (e) {
59
+ var t = [];
60
+ for (var n in e) t.push(n + '="' + e[n] + '"');
61
+ return t.length ? " " + t.join(" ") : "";
62
+ }(t.attrs) : "") + (t.voidElement ? "/>" : ">"), t.voidElement ? e : e + t.children.reduce(a, "") + "</" + t.name + ">";
63
+ case "comment":
64
+ return e + "\x3c!--" + t.comment + "--\x3e";
65
+ }
66
+ }
67
+ var c = {
68
+ parse: function (e, t) {
69
+ t || (t = {}), t.components || (t.components = s);
70
+ var a,
71
+ c = [],
72
+ o = [],
73
+ l = -1,
74
+ m = !1;
75
+ if (0 !== e.indexOf("<")) {
76
+ var u = e.indexOf("<");
77
+ c.push({
78
+ type: "text",
79
+ content: -1 === u ? e : e.substring(0, u)
80
+ });
81
+ }
82
+ return e.replace(r, function (r, s) {
83
+ if (m) {
84
+ if (r !== "</" + a.name + ">") return;
85
+ m = !1;
86
+ }
87
+ var u,
88
+ f = "/" !== r.charAt(1),
89
+ h = r.startsWith("\x3c!--"),
90
+ p = s + r.length,
91
+ d = e.charAt(p);
92
+ if (h) {
93
+ var v = n(r);
94
+ return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
95
+ }
96
+ 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({
97
+ type: "text",
98
+ content: e.slice(p, e.indexOf("<", p))
99
+ }), 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)) {
100
+ u = -1 === l ? c : o[l].children;
101
+ var x = e.indexOf("<", p),
102
+ g = e.slice(p, -1 === x ? void 0 : x);
103
+ i.test(g) && (g = " "), (x > -1 && l + u.length >= 0 || " " !== g) && u.push({
104
+ type: "text",
105
+ content: g
106
+ });
107
+ }
108
+ }), c;
109
+ },
110
+ stringify: function (e) {
111
+ return e.reduce(function (e, t) {
112
+ return e + a("", t);
113
+ }, "");
114
+ }
115
+ };
116
+
117
+ function warn() {
118
+ if (console && console.warn) {
119
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
120
+ args[_key] = arguments[_key];
121
+ }
122
+ if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
123
+ console.warn(...args);
124
+ }
125
+ }
126
+ const alreadyWarned = {};
127
+ function warnOnce() {
128
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
129
+ args[_key2] = arguments[_key2];
130
+ }
131
+ if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
132
+ if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
133
+ warn(...args);
134
+ }
135
+ const loadedClb = (i18n, cb) => () => {
136
+ if (i18n.isInitialized) {
137
+ cb();
138
+ } else {
139
+ const initialized = () => {
140
+ setTimeout(() => {
141
+ i18n.off('initialized', initialized);
142
+ }, 0);
143
+ cb();
144
+ };
145
+ i18n.on('initialized', initialized);
146
+ }
147
+ };
148
+ function loadNamespaces(i18n, ns, cb) {
149
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
150
+ }
151
+ function loadLanguages(i18n, lng, ns, cb) {
152
+ if (typeof ns === 'string') ns = [ns];
153
+ ns.forEach(n => {
154
+ if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
155
+ });
156
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
157
+ }
158
+ function oldI18nextHasLoadedNamespace(ns, i18n) {
159
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
160
+ const lng = i18n.languages[0];
161
+ const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
162
+ const lastLng = i18n.languages[i18n.languages.length - 1];
163
+ if (lng.toLowerCase() === 'cimode') return true;
164
+ const loadNotPending = (l, n) => {
165
+ const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
166
+ return loadState === -1 || loadState === 2;
167
+ };
168
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
169
+ if (i18n.hasResourceBundle(lng, ns)) return true;
170
+ if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
171
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
172
+ return false;
173
+ }
174
+ function hasLoadedNamespace(ns, i18n) {
175
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
176
+ if (!i18n.languages || !i18n.languages.length) {
177
+ warnOnce('i18n.languages were undefined or empty', i18n.languages);
178
+ return true;
179
+ }
180
+ const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
181
+ if (!isNewerI18next) {
182
+ return oldI18nextHasLoadedNamespace(ns, i18n, options);
183
+ }
184
+ return i18n.hasLoadedNamespace(ns, {
185
+ lng: options.lng,
186
+ precheck: (i18nInstance, loadNotPending) => {
187
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
188
+ }
189
+ });
190
+ }
191
+ function getDisplayName(Component) {
192
+ return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown');
193
+ }
194
+
195
+ const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
196
+ const htmlEntities = {
197
+ '&amp;': '&',
198
+ '&#38;': '&',
199
+ '&lt;': '<',
200
+ '&#60;': '<',
201
+ '&gt;': '>',
202
+ '&#62;': '>',
203
+ '&apos;': "'",
204
+ '&#39;': "'",
205
+ '&quot;': '"',
206
+ '&#34;': '"',
207
+ '&nbsp;': ' ',
208
+ '&#160;': ' ',
209
+ '&copy;': '©',
210
+ '&#169;': '©',
211
+ '&reg;': '®',
212
+ '&#174;': '®',
213
+ '&hellip;': '…',
214
+ '&#8230;': '…',
215
+ '&#x2F;': '/',
216
+ '&#47;': '/'
217
+ };
218
+ const unescapeHtmlEntity = m => htmlEntities[m];
219
+ const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
220
+
221
+ let defaultOptions = {
222
+ bindI18n: 'languageChanged',
223
+ bindI18nStore: '',
224
+ transEmptyNodeValue: '',
225
+ transSupportBasicHtmlNodes: true,
226
+ transWrapTextNodes: '',
227
+ transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
228
+ useSuspense: true,
229
+ unescape
230
+ };
231
+ function setDefaults() {
232
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
233
+ defaultOptions = {
234
+ ...defaultOptions,
235
+ ...options
236
+ };
237
+ }
238
+ function getDefaults() {
239
+ return defaultOptions;
240
+ }
241
+
242
+ let i18nInstance;
243
+ function setI18n(instance) {
244
+ i18nInstance = instance;
245
+ }
246
+ function getI18n() {
247
+ return i18nInstance;
248
+ }
249
+
250
+ function hasChildren(node, checkLength) {
251
+ if (!node) return false;
252
+ const base = node.props ? node.props.children : node.children;
253
+ if (checkLength) return base.length > 0;
254
+ return !!base;
255
+ }
256
+ function getChildren(node) {
257
+ if (!node) return [];
258
+ return node.props ? node.props.children : node.children;
259
+ }
260
+ function hasValidReactChildren(children) {
261
+ if (Object.prototype.toString.call(children) !== '[object Array]') return false;
262
+ return children.every(child => react.isValidElement(child));
263
+ }
264
+ function getAsArray(data) {
265
+ return Array.isArray(data) ? data : [data];
266
+ }
267
+ function mergeProps(source, target) {
268
+ const newTarget = {
269
+ ...target
270
+ };
271
+ newTarget.props = Object.assign(source.props, target.props);
272
+ return newTarget;
273
+ }
274
+ function nodesToString(children, i18nOptions) {
275
+ if (!children) return '';
276
+ let stringNode = '';
277
+ const childrenArray = getAsArray(children);
278
+ const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
279
+ childrenArray.forEach((child, childIndex) => {
280
+ if (typeof child === 'string') {
281
+ stringNode += `${child}`;
282
+ } else if (react.isValidElement(child)) {
283
+ const childPropsCount = Object.keys(child.props).length;
284
+ const shouldKeepChild = keepArray.indexOf(child.type) > -1;
285
+ const childChildren = child.props.children;
286
+ if (!childChildren && shouldKeepChild && childPropsCount === 0) {
287
+ stringNode += `<${child.type}/>`;
288
+ } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
289
+ stringNode += `<${childIndex}></${childIndex}>`;
290
+ } else if (child.props.i18nIsDynamicList) {
291
+ stringNode += `<${childIndex}></${childIndex}>`;
292
+ } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
293
+ stringNode += `<${child.type}>${childChildren}</${child.type}>`;
294
+ } else {
295
+ const content = nodesToString(childChildren, i18nOptions);
296
+ stringNode += `<${childIndex}>${content}</${childIndex}>`;
297
+ }
298
+ } else if (child === null) {
299
+ warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
300
+ } else if (typeof child === 'object') {
301
+ const {
302
+ format,
303
+ ...clone
304
+ } = child;
305
+ const keys = Object.keys(clone);
306
+ if (keys.length === 1) {
307
+ const value = format ? `${keys[0]}, ${format}` : keys[0];
308
+ stringNode += `{{${value}}}`;
309
+ } else {
310
+ warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
311
+ }
312
+ } else {
313
+ 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);
314
+ }
315
+ });
316
+ return stringNode;
317
+ }
318
+ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
319
+ if (targetString === '') return [];
320
+ const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
321
+ const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
322
+ if (!children && !emptyChildrenButNeedsHandling) return [targetString];
323
+ const data = {};
324
+ function getData(childs) {
325
+ const childrenArray = getAsArray(childs);
326
+ childrenArray.forEach(child => {
327
+ if (typeof child === 'string') return;
328
+ if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !react.isValidElement(child)) Object.assign(data, child);
329
+ });
330
+ }
331
+ getData(children);
332
+ const ast = c.parse(`<0>${targetString}</0>`);
333
+ const opts = {
334
+ ...data,
335
+ ...combinedTOpts
336
+ };
337
+ function renderInner(child, node, rootReactNode) {
338
+ const childs = getChildren(child);
339
+ const mappedChildren = mapAST(childs, node.children, rootReactNode);
340
+ return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
341
+ }
342
+ function pushTranslatedJSX(child, inner, mem, i, isVoid) {
343
+ if (child.dummy) child.children = inner;
344
+ mem.push(react.cloneElement(child, {
345
+ ...child.props,
346
+ key: i
347
+ }, isVoid ? undefined : inner));
348
+ }
349
+ function mapAST(reactNode, astNode, rootReactNode) {
350
+ const reactNodes = getAsArray(reactNode);
351
+ const astNodes = getAsArray(astNode);
352
+ return astNodes.reduce((mem, node, i) => {
353
+ const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
354
+ if (node.type === 'tag') {
355
+ let tmp = reactNodes[parseInt(node.name, 10)];
356
+ if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
357
+ if (!tmp) tmp = {};
358
+ const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
359
+ props: node.attrs
360
+ }, tmp) : tmp;
361
+ const isElement = react.isValidElement(child);
362
+ const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
363
+ const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
364
+ const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
365
+ if (typeof child === 'string') {
366
+ const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
367
+ mem.push(value);
368
+ } else if (hasChildren(child) || isValidTranslationWithChildren) {
369
+ const inner = renderInner(child, node, rootReactNode);
370
+ pushTranslatedJSX(child, inner, mem, i);
371
+ } else if (isEmptyTransWithHTML) {
372
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
373
+ mem.push(react.cloneElement(child, {
374
+ ...child.props,
375
+ key: i
376
+ }, inner));
377
+ } else if (Number.isNaN(parseFloat(node.name))) {
378
+ if (isKnownComponent) {
379
+ const inner = renderInner(child, node, rootReactNode);
380
+ pushTranslatedJSX(child, inner, mem, i, node.voidElement);
381
+ } else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
382
+ if (node.voidElement) {
383
+ mem.push(react.createElement(node.name, {
384
+ key: `${node.name}-${i}`
385
+ }));
386
+ } else {
387
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
388
+ mem.push(react.createElement(node.name, {
389
+ key: `${node.name}-${i}`
390
+ }, inner));
391
+ }
392
+ } else if (node.voidElement) {
393
+ mem.push(`<${node.name} />`);
394
+ } else {
395
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
396
+ mem.push(`<${node.name}>${inner}</${node.name}>`);
397
+ }
398
+ } else if (typeof child === 'object' && !isElement) {
399
+ const content = node.children[0] ? translationContent : null;
400
+ if (content) mem.push(content);
401
+ } else if (node.children.length === 1 && translationContent) {
402
+ mem.push(react.cloneElement(child, {
403
+ ...child.props,
404
+ key: i
405
+ }, translationContent));
406
+ } else {
407
+ mem.push(react.cloneElement(child, {
408
+ ...child.props,
409
+ key: i
410
+ }));
411
+ }
412
+ } else if (node.type === 'text') {
413
+ const wrapTextNodes = i18nOptions.transWrapTextNodes;
414
+ const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
415
+ if (wrapTextNodes) {
416
+ mem.push(react.createElement(wrapTextNodes, {
417
+ key: `${node.name}-${i}`
418
+ }, content));
419
+ } else {
420
+ mem.push(content);
421
+ }
422
+ }
423
+ return mem;
424
+ }, []);
425
+ }
426
+ const result = mapAST([{
427
+ dummy: true,
428
+ children: children || []
429
+ }], ast, getAsArray(children || []));
430
+ return getChildren(result[0]);
431
+ }
432
+ function Trans$1(_ref) {
433
+ let {
434
+ children,
435
+ count,
436
+ parent,
437
+ i18nKey,
438
+ context,
439
+ tOptions = {},
440
+ values,
441
+ defaults,
442
+ components,
443
+ ns,
444
+ i18n: i18nFromProps,
445
+ t: tFromProps,
446
+ shouldUnescape,
447
+ ...additionalProps
448
+ } = _ref;
449
+ const i18n = i18nFromProps || getI18n();
450
+ if (!i18n) {
451
+ warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
452
+ return children;
453
+ }
454
+ const t = tFromProps || i18n.t.bind(i18n) || (k => k);
455
+ if (context) tOptions.context = context;
456
+ const reactI18nextOptions = {
457
+ ...getDefaults(),
458
+ ...(i18n.options && i18n.options.react)
459
+ };
460
+ let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
461
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
462
+ const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
463
+ const {
464
+ hashTransKey
465
+ } = reactI18nextOptions;
466
+ const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
467
+ const interpolationOverride = values ? tOptions.interpolation : {
468
+ interpolation: {
469
+ ...tOptions.interpolation,
470
+ prefix: '#$?',
471
+ suffix: '?$#'
472
+ }
473
+ };
474
+ const combinedTOpts = {
475
+ ...tOptions,
476
+ count,
477
+ ...values,
478
+ ...interpolationOverride,
479
+ defaultValue,
480
+ ns: namespaces
481
+ };
482
+ const translation = key ? t(key, combinedTOpts) : defaultValue;
483
+ const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
484
+ const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
485
+ return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
486
+ }
487
+
488
+ const initReactI18next = {
489
+ type: '3rdParty',
490
+ init(instance) {
491
+ setDefaults(instance.options.react);
492
+ setI18n(instance);
493
+ }
494
+ };
495
+
496
+ const I18nContext = react.createContext();
497
+ class ReportNamespaces {
498
+ constructor() {
499
+ this.usedNamespaces = {};
500
+ }
501
+ addUsedNamespaces(namespaces) {
502
+ namespaces.forEach(ns => {
503
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
504
+ });
505
+ }
506
+ getUsedNamespaces() {
507
+ return Object.keys(this.usedNamespaces);
508
+ }
509
+ }
510
+ function composeInitialProps(ForComponent) {
511
+ return ctx => new Promise(resolve => {
512
+ const i18nInitialProps = getInitialProps();
513
+ if (ForComponent.getInitialProps) {
514
+ ForComponent.getInitialProps(ctx).then(componentsInitialProps => {
515
+ resolve({
516
+ ...componentsInitialProps,
517
+ ...i18nInitialProps
518
+ });
519
+ });
520
+ } else {
521
+ resolve(i18nInitialProps);
522
+ }
523
+ });
524
+ }
525
+ function getInitialProps() {
526
+ const i18n = getI18n();
527
+ const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
528
+ const ret = {};
529
+ const initialI18nStore = {};
530
+ i18n.languages.forEach(l => {
531
+ initialI18nStore[l] = {};
532
+ namespaces.forEach(ns => {
533
+ initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
534
+ });
535
+ });
536
+ ret.initialI18nStore = initialI18nStore;
537
+ ret.initialLanguage = i18n.language;
538
+ return ret;
539
+ }
540
+
541
+ function Trans(_ref) {
542
+ let {
543
+ children,
544
+ count,
545
+ parent,
546
+ i18nKey,
547
+ context,
548
+ tOptions = {},
549
+ values,
550
+ defaults,
551
+ components,
552
+ ns,
553
+ i18n: i18nFromProps,
554
+ t: tFromProps,
555
+ shouldUnescape,
556
+ ...additionalProps
557
+ } = _ref;
558
+ const {
559
+ i18n: i18nFromContext,
560
+ defaultNS: defaultNSFromContext
561
+ } = react.useContext(I18nContext) || {};
562
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
563
+ const t = tFromProps || i18n && i18n.t.bind(i18n);
564
+ return Trans$1({
565
+ children,
566
+ count,
567
+ parent,
568
+ i18nKey,
569
+ context,
570
+ tOptions,
571
+ values,
572
+ defaults,
573
+ components,
574
+ ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
575
+ i18n,
576
+ t: tFromProps,
577
+ shouldUnescape,
578
+ ...additionalProps
579
+ });
580
+ }
581
+
582
+ const usePrevious = (value, ignore) => {
583
+ const ref = react.useRef();
584
+ react.useEffect(() => {
585
+ ref.current = ignore ? ref.current : value;
586
+ }, [value, ignore]);
587
+ return ref.current;
588
+ };
589
+ function useTranslation(ns) {
590
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
591
+ const {
592
+ i18n: i18nFromProps
593
+ } = props;
594
+ const {
595
+ i18n: i18nFromContext,
596
+ defaultNS: defaultNSFromContext
597
+ } = react.useContext(I18nContext) || {};
598
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
599
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
600
+ if (!i18n) {
601
+ warnOnce('You will need to pass in an i18next instance by using initReactI18next');
602
+ const notReadyT = (k, optsOrDefaultValue) => {
603
+ if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
604
+ if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
605
+ return Array.isArray(k) ? k[k.length - 1] : k;
606
+ };
607
+ const retNotReady = [notReadyT, {}, false];
608
+ retNotReady.t = notReadyT;
609
+ retNotReady.i18n = {};
610
+ retNotReady.ready = false;
611
+ return retNotReady;
612
+ }
613
+ 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.');
614
+ const i18nOptions = {
615
+ ...getDefaults(),
616
+ ...i18n.options.react,
617
+ ...props
618
+ };
619
+ const {
620
+ useSuspense,
621
+ keyPrefix
622
+ } = i18nOptions;
623
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
624
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
625
+ if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
626
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
627
+ function getT() {
628
+ return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
629
+ }
630
+ const [t, setT] = react.useState(getT);
631
+ let joinedNS = namespaces.join();
632
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
633
+ const previousJoinedNS = usePrevious(joinedNS);
634
+ const isMounted = react.useRef(true);
635
+ react.useEffect(() => {
636
+ const {
637
+ bindI18n,
638
+ bindI18nStore
639
+ } = i18nOptions;
640
+ isMounted.current = true;
641
+ if (!ready && !useSuspense) {
642
+ if (props.lng) {
643
+ loadLanguages(i18n, props.lng, namespaces, () => {
644
+ if (isMounted.current) setT(getT);
645
+ });
646
+ } else {
647
+ loadNamespaces(i18n, namespaces, () => {
648
+ if (isMounted.current) setT(getT);
649
+ });
650
+ }
651
+ }
652
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
653
+ setT(getT);
654
+ }
655
+ function boundReset() {
656
+ if (isMounted.current) setT(getT);
657
+ }
658
+ if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
659
+ if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
660
+ return () => {
661
+ isMounted.current = false;
662
+ if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
663
+ if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
664
+ };
665
+ }, [i18n, joinedNS]);
666
+ const isInitial = react.useRef(true);
667
+ react.useEffect(() => {
668
+ if (isMounted.current && !isInitial.current) {
669
+ setT(getT);
670
+ }
671
+ isInitial.current = false;
672
+ }, [i18n, keyPrefix]);
673
+ const ret = [t, i18n, ready];
674
+ ret.t = t;
675
+ ret.i18n = i18n;
676
+ ret.ready = ready;
677
+ if (ready) return ret;
678
+ if (!ready && !useSuspense) return ret;
679
+ throw new Promise(resolve => {
680
+ if (props.lng) {
681
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
682
+ } else {
683
+ loadNamespaces(i18n, namespaces, () => resolve());
684
+ }
685
+ });
686
+ }
687
+
688
+ function withTranslation(ns) {
689
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
690
+ return function Extend(WrappedComponent) {
691
+ function I18nextWithTranslation(_ref) {
692
+ let {
693
+ forwardedRef,
694
+ ...rest
695
+ } = _ref;
696
+ const [t, i18n, ready] = useTranslation(ns, {
697
+ ...rest,
698
+ keyPrefix: options.keyPrefix
699
+ });
700
+ const passDownProps = {
701
+ ...rest,
702
+ t,
703
+ i18n,
704
+ tReady: ready
705
+ };
706
+ if (options.withRef && forwardedRef) {
707
+ passDownProps.ref = forwardedRef;
708
+ } else if (!options.withRef && forwardedRef) {
709
+ passDownProps.forwardedRef = forwardedRef;
710
+ }
711
+ return react.createElement(WrappedComponent, passDownProps);
712
+ }
713
+ I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`;
714
+ I18nextWithTranslation.WrappedComponent = WrappedComponent;
715
+ const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, {
716
+ forwardedRef: ref
717
+ }));
718
+ return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
719
+ };
720
+ }
721
+
722
+ function Translation(props) {
723
+ const {
724
+ ns,
725
+ children,
726
+ ...options
727
+ } = props;
728
+ const [t, i18n, ready] = useTranslation(ns, options);
729
+ return children(t, {
730
+ i18n,
731
+ lng: i18n.language
732
+ }, ready);
733
+ }
734
+
735
+ function I18nextProvider(_ref) {
736
+ let {
737
+ i18n,
738
+ defaultNS,
739
+ children
740
+ } = _ref;
741
+ const value = react.useMemo(() => ({
742
+ i18n,
743
+ defaultNS
744
+ }), [i18n, defaultNS]);
745
+ return react.createElement(I18nContext.Provider, {
746
+ value
747
+ }, children);
748
+ }
749
+
750
+ function useSSR(initialI18nStore, initialLanguage) {
751
+ let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
752
+ const {
753
+ i18n: i18nFromProps
754
+ } = props;
755
+ const {
756
+ i18n: i18nFromContext
757
+ } = react.useContext(I18nContext) || {};
758
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
759
+ if (i18n.options && i18n.options.isClone) return;
760
+ if (initialI18nStore && !i18n.initializedStoreOnce) {
761
+ i18n.services.resourceStore.data = initialI18nStore;
762
+ i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
763
+ Object.keys(lngResources).forEach(ns => {
764
+ if (mem.indexOf(ns) < 0) mem.push(ns);
765
+ });
766
+ return mem;
767
+ }, i18n.options.ns);
768
+ i18n.initializedStoreOnce = true;
769
+ i18n.isInitialized = true;
770
+ }
771
+ if (initialLanguage && !i18n.initializedLanguageOnce) {
772
+ i18n.changeLanguage(initialLanguage);
773
+ i18n.initializedLanguageOnce = true;
774
+ }
775
+ }
776
+
777
+ function withSSR() {
778
+ return function Extend(WrappedComponent) {
779
+ function I18nextWithSSR(_ref) {
780
+ let {
781
+ initialI18nStore,
782
+ initialLanguage,
783
+ ...rest
784
+ } = _ref;
785
+ useSSR(initialI18nStore, initialLanguage);
786
+ return react.createElement(WrappedComponent, {
787
+ ...rest
788
+ });
789
+ }
790
+ I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
791
+ I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`;
792
+ I18nextWithSSR.WrappedComponent = WrappedComponent;
793
+ return I18nextWithSSR;
794
+ };
795
+ }
796
+
797
+ const date = () => '';
798
+ const time = () => '';
799
+ const number = () => '';
800
+ const select = () => '';
801
+ const plural = () => '';
802
+ const selectOrdinal = () => '';
803
+
804
+ exports.I18nContext = I18nContext;
805
+ exports.I18nextProvider = I18nextProvider;
806
+ exports.Trans = Trans;
807
+ exports.TransWithoutContext = Trans$1;
808
+ exports.Translation = Translation;
809
+ exports.composeInitialProps = composeInitialProps;
810
+ exports.date = date;
811
+ exports.getDefaults = getDefaults;
812
+ exports.getI18n = getI18n;
813
+ exports.getInitialProps = getInitialProps;
814
+ exports.initReactI18next = initReactI18next;
815
+ exports.number = number;
816
+ exports.plural = plural;
817
+ exports.select = select;
818
+ exports.selectOrdinal = selectOrdinal;
819
+ exports.setDefaults = setDefaults;
820
+ exports.setI18n = setI18n;
821
+ exports.time = time;
822
+ exports.useSSR = useSSR;
823
+ exports.useTranslation = useTranslation;
824
+ exports.withSSR = withSSR;
825
+ exports.withTranslation = withTranslation;
826
+
827
+ }));