react-i18next 13.0.2 → 13.1.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.
@@ -1,831 +1,850 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactI18next = {}, global.React));
5
- })(this, (function (exports, react) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactI18next = {}, global.React));
5
+ })(this, (function (exports, React) { 'use strict';
6
6
 
7
- function getDefaultExportFromCjs (x) {
8
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
9
- }
7
+ function _extends() {
8
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
9
+ for (var i = 1; i < arguments.length; i++) {
10
+ var source = arguments[i];
11
+ for (var key in source) {
12
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
13
+ target[key] = source[key];
14
+ }
15
+ }
16
+ }
17
+ return target;
18
+ };
19
+ return _extends.apply(this, arguments);
20
+ }
10
21
 
11
- var voidElements = {
12
- "area": true,
13
- "base": true,
14
- "br": true,
15
- "col": true,
16
- "embed": true,
17
- "hr": true,
18
- "img": true,
19
- "input": true,
20
- "link": true,
21
- "meta": true,
22
- "param": true,
23
- "source": true,
24
- "track": true,
25
- "wbr": true
26
- };
22
+ function getDefaultExportFromCjs (x) {
23
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
24
+ }
27
25
 
28
- var e = /*@__PURE__*/getDefaultExportFromCjs(voidElements);
26
+ var voidElements = {
27
+ "area": true,
28
+ "base": true,
29
+ "br": true,
30
+ "col": true,
31
+ "embed": true,
32
+ "hr": true,
33
+ "img": true,
34
+ "input": true,
35
+ "link": true,
36
+ "meta": true,
37
+ "param": true,
38
+ "source": true,
39
+ "track": true,
40
+ "wbr": true
41
+ };
29
42
 
30
- var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
31
- function n(n) {
32
- var r = {
33
- type: "tag",
34
- name: "",
35
- voidElement: !1,
36
- attrs: {},
37
- children: []
38
- },
39
- i = n.match(/<\/?([^\s]+?)[/\s>]/);
40
- if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) {
41
- var s = n.indexOf("--\x3e");
42
- return {
43
- type: "comment",
44
- comment: -1 !== s ? n.slice(4, s) : ""
45
- };
46
- }
47
- for (var a = new RegExp(t), c = null; null !== (c = a.exec(n));) if (c[0].trim()) if (c[1]) {
48
- var o = c[1].trim(),
49
- l = [o, ""];
50
- o.indexOf("=") > -1 && (l = o.split("=")), r.attrs[l[0]] = l[1], a.lastIndex--;
51
- } else c[2] && (r.attrs[c[2]] = c[3].trim().substring(1, c[3].length - 1));
52
- return r;
53
- }
54
- var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,
55
- i = /^\s*$/,
56
- s = Object.create(null);
57
- function a(e, t) {
58
- switch (t.type) {
59
- case "text":
60
- return e + t.content;
61
- case "tag":
62
- return e += "<" + t.name + (t.attrs ? function (e) {
63
- var t = [];
64
- for (var n in e) t.push(n + '="' + e[n] + '"');
65
- return t.length ? " " + t.join(" ") : "";
66
- }(t.attrs) : "") + (t.voidElement ? "/>" : ">"), t.voidElement ? e : e + t.children.reduce(a, "") + "</" + t.name + ">";
67
- case "comment":
68
- return e + "\x3c!--" + t.comment + "--\x3e";
69
- }
70
- }
71
- var c = {
72
- parse: function (e, t) {
73
- t || (t = {}), t.components || (t.components = s);
74
- var a,
75
- c = [],
76
- o = [],
77
- l = -1,
78
- m = !1;
79
- if (0 !== e.indexOf("<")) {
80
- var u = e.indexOf("<");
81
- c.push({
82
- type: "text",
83
- content: -1 === u ? e : e.substring(0, u)
84
- });
85
- }
86
- return e.replace(r, function (r, s) {
87
- if (m) {
88
- if (r !== "</" + a.name + ">") return;
89
- m = !1;
90
- }
91
- var u,
92
- f = "/" !== r.charAt(1),
93
- h = r.startsWith("\x3c!--"),
94
- p = s + r.length,
95
- d = e.charAt(p);
96
- if (h) {
97
- var v = n(r);
98
- return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
99
- }
100
- 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({
101
- type: "text",
102
- content: e.slice(p, e.indexOf("<", p))
103
- }), 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)) {
104
- u = -1 === l ? c : o[l].children;
105
- var x = e.indexOf("<", p),
106
- g = e.slice(p, -1 === x ? void 0 : x);
107
- i.test(g) && (g = " "), (x > -1 && l + u.length >= 0 || " " !== g) && u.push({
108
- type: "text",
109
- content: g
110
- });
111
- }
112
- }), c;
113
- },
114
- stringify: function (e) {
115
- return e.reduce(function (e, t) {
116
- return e + a("", t);
117
- }, "");
118
- }
119
- };
43
+ var e = /*@__PURE__*/getDefaultExportFromCjs(voidElements);
120
44
 
121
- function warn() {
122
- if (console && console.warn) {
123
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
124
- args[_key] = arguments[_key];
125
- }
126
- if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
127
- console.warn(...args);
128
- }
129
- }
130
- const alreadyWarned = {};
131
- function warnOnce() {
132
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
133
- args[_key2] = arguments[_key2];
134
- }
135
- if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
136
- if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
137
- warn(...args);
138
- }
139
- const loadedClb = (i18n, cb) => () => {
140
- if (i18n.isInitialized) {
141
- cb();
142
- } else {
143
- const initialized = () => {
144
- setTimeout(() => {
145
- i18n.off('initialized', initialized);
146
- }, 0);
147
- cb();
148
- };
149
- i18n.on('initialized', initialized);
150
- }
151
- };
152
- function loadNamespaces(i18n, ns, cb) {
153
- i18n.loadNamespaces(ns, loadedClb(i18n, cb));
154
- }
155
- function loadLanguages(i18n, lng, ns, cb) {
156
- if (typeof ns === 'string') ns = [ns];
157
- ns.forEach(n => {
158
- if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
159
- });
160
- i18n.loadLanguages(lng, loadedClb(i18n, cb));
161
- }
162
- function oldI18nextHasLoadedNamespace(ns, i18n) {
163
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
164
- const lng = i18n.languages[0];
165
- const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
166
- const lastLng = i18n.languages[i18n.languages.length - 1];
167
- if (lng.toLowerCase() === 'cimode') return true;
168
- const loadNotPending = (l, n) => {
169
- const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
170
- return loadState === -1 || loadState === 2;
171
- };
172
- if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
173
- if (i18n.hasResourceBundle(lng, ns)) return true;
174
- if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
175
- if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
176
- return false;
177
- }
178
- function hasLoadedNamespace(ns, i18n) {
179
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
180
- if (!i18n.languages || !i18n.languages.length) {
181
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
182
- return true;
183
- }
184
- const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
185
- if (!isNewerI18next) {
186
- return oldI18nextHasLoadedNamespace(ns, i18n, options);
187
- }
188
- return i18n.hasLoadedNamespace(ns, {
189
- lng: options.lng,
190
- precheck: (i18nInstance, loadNotPending) => {
191
- if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
192
- }
193
- });
194
- }
195
- function getDisplayName(Component) {
196
- return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown');
197
- }
45
+ var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
46
+ function n(n) {
47
+ var r = {
48
+ type: "tag",
49
+ name: "",
50
+ voidElement: !1,
51
+ attrs: {},
52
+ children: []
53
+ },
54
+ i = n.match(/<\/?([^\s]+?)[/\s>]/);
55
+ if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) {
56
+ var s = n.indexOf("--\x3e");
57
+ return {
58
+ type: "comment",
59
+ comment: -1 !== s ? n.slice(4, s) : ""
60
+ };
61
+ }
62
+ for (var a = new RegExp(t), c = null; null !== (c = a.exec(n));) if (c[0].trim()) if (c[1]) {
63
+ var o = c[1].trim(),
64
+ l = [o, ""];
65
+ o.indexOf("=") > -1 && (l = o.split("=")), r.attrs[l[0]] = l[1], a.lastIndex--;
66
+ } else c[2] && (r.attrs[c[2]] = c[3].trim().substring(1, c[3].length - 1));
67
+ return r;
68
+ }
69
+ var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,
70
+ i = /^\s*$/,
71
+ s = Object.create(null);
72
+ function a(e, t) {
73
+ switch (t.type) {
74
+ case "text":
75
+ return e + t.content;
76
+ case "tag":
77
+ return e += "<" + t.name + (t.attrs ? function (e) {
78
+ var t = [];
79
+ for (var n in e) t.push(n + '="' + e[n] + '"');
80
+ return t.length ? " " + t.join(" ") : "";
81
+ }(t.attrs) : "") + (t.voidElement ? "/>" : ">"), t.voidElement ? e : e + t.children.reduce(a, "") + "</" + t.name + ">";
82
+ case "comment":
83
+ return e + "\x3c!--" + t.comment + "--\x3e";
84
+ }
85
+ }
86
+ var c = {
87
+ parse: function (e, t) {
88
+ t || (t = {}), t.components || (t.components = s);
89
+ var a,
90
+ c = [],
91
+ o = [],
92
+ l = -1,
93
+ m = !1;
94
+ if (0 !== e.indexOf("<")) {
95
+ var u = e.indexOf("<");
96
+ c.push({
97
+ type: "text",
98
+ content: -1 === u ? e : e.substring(0, u)
99
+ });
100
+ }
101
+ return e.replace(r, function (r, s) {
102
+ if (m) {
103
+ if (r !== "</" + a.name + ">") return;
104
+ m = !1;
105
+ }
106
+ var u,
107
+ f = "/" !== r.charAt(1),
108
+ h = r.startsWith("\x3c!--"),
109
+ p = s + r.length,
110
+ d = e.charAt(p);
111
+ if (h) {
112
+ var v = n(r);
113
+ return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
114
+ }
115
+ 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({
116
+ type: "text",
117
+ content: e.slice(p, e.indexOf("<", p))
118
+ }), 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)) {
119
+ u = -1 === l ? c : o[l].children;
120
+ var x = e.indexOf("<", p),
121
+ g = e.slice(p, -1 === x ? void 0 : x);
122
+ i.test(g) && (g = " "), (x > -1 && l + u.length >= 0 || " " !== g) && u.push({
123
+ type: "text",
124
+ content: g
125
+ });
126
+ }
127
+ }), c;
128
+ },
129
+ stringify: function (e) {
130
+ return e.reduce(function (e, t) {
131
+ return e + a("", t);
132
+ }, "");
133
+ }
134
+ };
198
135
 
199
- const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
200
- const htmlEntities = {
201
- '&amp;': '&',
202
- '&#38;': '&',
203
- '&lt;': '<',
204
- '&#60;': '<',
205
- '&gt;': '>',
206
- '&#62;': '>',
207
- '&apos;': "'",
208
- '&#39;': "'",
209
- '&quot;': '"',
210
- '&#34;': '"',
211
- '&nbsp;': ' ',
212
- '&#160;': ' ',
213
- '&copy;': '©',
214
- '&#169;': '©',
215
- '&reg;': '®',
216
- '&#174;': '®',
217
- '&hellip;': '…',
218
- '&#8230;': '…',
219
- '&#x2F;': '/',
220
- '&#47;': '/'
221
- };
222
- const unescapeHtmlEntity = m => htmlEntities[m];
223
- const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
136
+ function warn() {
137
+ if (console && console.warn) {
138
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
139
+ args[_key] = arguments[_key];
140
+ }
141
+ if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
142
+ console.warn(...args);
143
+ }
144
+ }
145
+ const alreadyWarned = {};
146
+ function warnOnce() {
147
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
148
+ args[_key2] = arguments[_key2];
149
+ }
150
+ if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
151
+ if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
152
+ warn(...args);
153
+ }
154
+ const loadedClb = (i18n, cb) => () => {
155
+ if (i18n.isInitialized) {
156
+ cb();
157
+ } else {
158
+ const initialized = () => {
159
+ setTimeout(() => {
160
+ i18n.off('initialized', initialized);
161
+ }, 0);
162
+ cb();
163
+ };
164
+ i18n.on('initialized', initialized);
165
+ }
166
+ };
167
+ function loadNamespaces(i18n, ns, cb) {
168
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
169
+ }
170
+ function loadLanguages(i18n, lng, ns, cb) {
171
+ if (typeof ns === 'string') ns = [ns];
172
+ ns.forEach(n => {
173
+ if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
174
+ });
175
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
176
+ }
177
+ function oldI18nextHasLoadedNamespace(ns, i18n) {
178
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
179
+ const lng = i18n.languages[0];
180
+ const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
181
+ const lastLng = i18n.languages[i18n.languages.length - 1];
182
+ if (lng.toLowerCase() === 'cimode') return true;
183
+ const loadNotPending = (l, n) => {
184
+ const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
185
+ return loadState === -1 || loadState === 2;
186
+ };
187
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
188
+ if (i18n.hasResourceBundle(lng, ns)) return true;
189
+ if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
190
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
191
+ return false;
192
+ }
193
+ function hasLoadedNamespace(ns, i18n) {
194
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
195
+ if (!i18n.languages || !i18n.languages.length) {
196
+ warnOnce('i18n.languages were undefined or empty', i18n.languages);
197
+ return true;
198
+ }
199
+ const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
200
+ if (!isNewerI18next) {
201
+ return oldI18nextHasLoadedNamespace(ns, i18n, options);
202
+ }
203
+ return i18n.hasLoadedNamespace(ns, {
204
+ lng: options.lng,
205
+ precheck: (i18nInstance, loadNotPending) => {
206
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
207
+ }
208
+ });
209
+ }
210
+ function getDisplayName(Component) {
211
+ return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown');
212
+ }
224
213
 
225
- let defaultOptions = {
226
- bindI18n: 'languageChanged',
227
- bindI18nStore: '',
228
- transEmptyNodeValue: '',
229
- transSupportBasicHtmlNodes: true,
230
- transWrapTextNodes: '',
231
- transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
232
- useSuspense: true,
233
- unescape
234
- };
235
- function setDefaults() {
236
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
237
- defaultOptions = {
238
- ...defaultOptions,
239
- ...options
240
- };
241
- }
242
- function getDefaults() {
243
- return defaultOptions;
244
- }
214
+ const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
215
+ const htmlEntities = {
216
+ '&amp;': '&',
217
+ '&#38;': '&',
218
+ '&lt;': '<',
219
+ '&#60;': '<',
220
+ '&gt;': '>',
221
+ '&#62;': '>',
222
+ '&apos;': "'",
223
+ '&#39;': "'",
224
+ '&quot;': '"',
225
+ '&#34;': '"',
226
+ '&nbsp;': ' ',
227
+ '&#160;': ' ',
228
+ '&copy;': '©',
229
+ '&#169;': '©',
230
+ '&reg;': '®',
231
+ '&#174;': '®',
232
+ '&hellip;': '…',
233
+ '&#8230;': '…',
234
+ '&#x2F;': '/',
235
+ '&#47;': '/'
236
+ };
237
+ const unescapeHtmlEntity = m => htmlEntities[m];
238
+ const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
245
239
 
246
- let i18nInstance;
247
- function setI18n(instance) {
248
- i18nInstance = instance;
249
- }
250
- function getI18n() {
251
- return i18nInstance;
252
- }
240
+ let defaultOptions = {
241
+ bindI18n: 'languageChanged',
242
+ bindI18nStore: '',
243
+ transEmptyNodeValue: '',
244
+ transSupportBasicHtmlNodes: true,
245
+ transWrapTextNodes: '',
246
+ transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
247
+ useSuspense: true,
248
+ unescape
249
+ };
250
+ function setDefaults() {
251
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
252
+ defaultOptions = {
253
+ ...defaultOptions,
254
+ ...options
255
+ };
256
+ }
257
+ function getDefaults() {
258
+ return defaultOptions;
259
+ }
253
260
 
254
- function hasChildren(node, checkLength) {
255
- if (!node) return false;
256
- const base = node.props ? node.props.children : node.children;
257
- if (checkLength) return base.length > 0;
258
- return !!base;
259
- }
260
- function getChildren(node) {
261
- if (!node) return [];
262
- return node.props ? node.props.children : node.children;
263
- }
264
- function hasValidReactChildren(children) {
265
- if (Object.prototype.toString.call(children) !== '[object Array]') return false;
266
- return children.every(child => react.isValidElement(child));
267
- }
268
- function getAsArray(data) {
269
- return Array.isArray(data) ? data : [data];
270
- }
271
- function mergeProps(source, target) {
272
- const newTarget = {
273
- ...target
274
- };
275
- newTarget.props = Object.assign(source.props, target.props);
276
- return newTarget;
277
- }
278
- function nodesToString(children, i18nOptions) {
279
- if (!children) return '';
280
- let stringNode = '';
281
- const childrenArray = getAsArray(children);
282
- const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
283
- childrenArray.forEach((child, childIndex) => {
284
- if (typeof child === 'string') {
285
- stringNode += `${child}`;
286
- } else if (react.isValidElement(child)) {
287
- const childPropsCount = Object.keys(child.props).length;
288
- const shouldKeepChild = keepArray.indexOf(child.type) > -1;
289
- const childChildren = child.props.children;
290
- if (!childChildren && shouldKeepChild && childPropsCount === 0) {
291
- stringNode += `<${child.type}/>`;
292
- } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
293
- stringNode += `<${childIndex}></${childIndex}>`;
294
- } else if (child.props.i18nIsDynamicList) {
295
- stringNode += `<${childIndex}></${childIndex}>`;
296
- } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
297
- stringNode += `<${child.type}>${childChildren}</${child.type}>`;
298
- } else {
299
- const content = nodesToString(childChildren, i18nOptions);
300
- stringNode += `<${childIndex}>${content}</${childIndex}>`;
301
- }
302
- } else if (child === null) {
303
- warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
304
- } else if (typeof child === 'object') {
305
- const {
306
- format,
307
- ...clone
308
- } = child;
309
- const keys = Object.keys(clone);
310
- if (keys.length === 1) {
311
- const value = format ? `${keys[0]}, ${format}` : keys[0];
312
- stringNode += `{{${value}}}`;
313
- } else {
314
- warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
315
- }
316
- } else {
317
- 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);
318
- }
319
- });
320
- return stringNode;
321
- }
322
- function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
323
- if (targetString === '') return [];
324
- const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
325
- const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
326
- if (!children && !emptyChildrenButNeedsHandling) return [targetString];
327
- const data = {};
328
- function getData(childs) {
329
- const childrenArray = getAsArray(childs);
330
- childrenArray.forEach(child => {
331
- if (typeof child === 'string') return;
332
- if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !react.isValidElement(child)) Object.assign(data, child);
333
- });
334
- }
335
- getData(children);
336
- const ast = c.parse(`<0>${targetString}</0>`);
337
- const opts = {
338
- ...data,
339
- ...combinedTOpts
340
- };
341
- function renderInner(child, node, rootReactNode) {
342
- const childs = getChildren(child);
343
- const mappedChildren = mapAST(childs, node.children, rootReactNode);
344
- return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
345
- }
346
- function pushTranslatedJSX(child, inner, mem, i, isVoid) {
347
- if (child.dummy) child.children = inner;
348
- mem.push(react.cloneElement(child, {
349
- ...child.props,
350
- key: i
351
- }, isVoid ? undefined : inner));
352
- }
353
- function mapAST(reactNode, astNode, rootReactNode) {
354
- const reactNodes = getAsArray(reactNode);
355
- const astNodes = getAsArray(astNode);
356
- return astNodes.reduce((mem, node, i) => {
357
- const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
358
- if (node.type === 'tag') {
359
- let tmp = reactNodes[parseInt(node.name, 10)];
360
- if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
361
- if (!tmp) tmp = {};
362
- const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
363
- props: node.attrs
364
- }, tmp) : tmp;
365
- const isElement = react.isValidElement(child);
366
- const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
367
- const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
368
- const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
369
- if (typeof child === 'string') {
370
- const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
371
- mem.push(value);
372
- } else if (hasChildren(child) || isValidTranslationWithChildren) {
373
- const inner = renderInner(child, node, rootReactNode);
374
- pushTranslatedJSX(child, inner, mem, i);
375
- } else if (isEmptyTransWithHTML) {
376
- const inner = mapAST(reactNodes, node.children, rootReactNode);
377
- mem.push(react.cloneElement(child, {
378
- ...child.props,
379
- key: i
380
- }, inner));
381
- } else if (Number.isNaN(parseFloat(node.name))) {
382
- if (isKnownComponent) {
383
- const inner = renderInner(child, node, rootReactNode);
384
- pushTranslatedJSX(child, inner, mem, i, node.voidElement);
385
- } else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
386
- if (node.voidElement) {
387
- mem.push(react.createElement(node.name, {
388
- key: `${node.name}-${i}`
389
- }));
390
- } else {
391
- const inner = mapAST(reactNodes, node.children, rootReactNode);
392
- mem.push(react.createElement(node.name, {
393
- key: `${node.name}-${i}`
394
- }, inner));
395
- }
396
- } else if (node.voidElement) {
397
- mem.push(`<${node.name} />`);
398
- } else {
399
- const inner = mapAST(reactNodes, node.children, rootReactNode);
400
- mem.push(`<${node.name}>${inner}</${node.name}>`);
401
- }
402
- } else if (typeof child === 'object' && !isElement) {
403
- const content = node.children[0] ? translationContent : null;
404
- if (content) mem.push(content);
405
- } else if (node.children.length === 1 && translationContent) {
406
- mem.push(react.cloneElement(child, {
407
- ...child.props,
408
- key: i
409
- }, translationContent));
410
- } else {
411
- mem.push(react.cloneElement(child, {
412
- ...child.props,
413
- key: i
414
- }));
415
- }
416
- } else if (node.type === 'text') {
417
- const wrapTextNodes = i18nOptions.transWrapTextNodes;
418
- const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
419
- if (wrapTextNodes) {
420
- mem.push(react.createElement(wrapTextNodes, {
421
- key: `${node.name}-${i}`
422
- }, content));
423
- } else {
424
- mem.push(content);
425
- }
426
- }
427
- return mem;
428
- }, []);
429
- }
430
- const result = mapAST([{
431
- dummy: true,
432
- children: children || []
433
- }], ast, getAsArray(children || []));
434
- return getChildren(result[0]);
435
- }
436
- function Trans$1(_ref) {
437
- let {
438
- children,
439
- count,
440
- parent,
441
- i18nKey,
442
- context,
443
- tOptions = {},
444
- values,
445
- defaults,
446
- components,
447
- ns,
448
- i18n: i18nFromProps,
449
- t: tFromProps,
450
- shouldUnescape,
451
- ...additionalProps
452
- } = _ref;
453
- const i18n = i18nFromProps || getI18n();
454
- if (!i18n) {
455
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
456
- return children;
457
- }
458
- const t = tFromProps || i18n.t.bind(i18n) || (k => k);
459
- if (context) tOptions.context = context;
460
- const reactI18nextOptions = {
461
- ...getDefaults(),
462
- ...(i18n.options && i18n.options.react)
463
- };
464
- let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
465
- namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
466
- const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
467
- const {
468
- hashTransKey
469
- } = reactI18nextOptions;
470
- const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
471
- const interpolationOverride = values ? tOptions.interpolation : {
472
- interpolation: {
473
- ...tOptions.interpolation,
474
- prefix: '#$?',
475
- suffix: '?$#'
476
- }
477
- };
478
- const combinedTOpts = {
479
- ...tOptions,
480
- count,
481
- ...values,
482
- ...interpolationOverride,
483
- defaultValue,
484
- ns: namespaces
485
- };
486
- const translation = key ? t(key, combinedTOpts) : defaultValue;
487
- const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
488
- const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
489
- return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
490
- }
261
+ let i18nInstance;
262
+ function setI18n(instance) {
263
+ i18nInstance = instance;
264
+ }
265
+ function getI18n() {
266
+ return i18nInstance;
267
+ }
491
268
 
492
- const initReactI18next = {
493
- type: '3rdParty',
494
- init(instance) {
495
- setDefaults(instance.options.react);
496
- setI18n(instance);
497
- }
498
- };
269
+ function hasChildren(node, checkLength) {
270
+ if (!node) return false;
271
+ const base = node.props ? node.props.children : node.children;
272
+ if (checkLength) return base.length > 0;
273
+ return !!base;
274
+ }
275
+ function getChildren(node) {
276
+ if (!node) return [];
277
+ const children = node.props ? node.props.children : node.children;
278
+ return node.props?.i18nIsDynamicList ? getAsArray(children) : children;
279
+ }
280
+ function hasValidReactChildren(children) {
281
+ if (Object.prototype.toString.call(children) !== '[object Array]') return false;
282
+ return children.every(child => React.isValidElement(child));
283
+ }
284
+ function getAsArray(data) {
285
+ return Array.isArray(data) ? data : [data];
286
+ }
287
+ function mergeProps(source, target) {
288
+ const newTarget = {
289
+ ...target
290
+ };
291
+ newTarget.props = Object.assign(source.props, target.props);
292
+ return newTarget;
293
+ }
294
+ function nodesToString(children, i18nOptions) {
295
+ if (!children) return '';
296
+ let stringNode = '';
297
+ const childrenArray = getAsArray(children);
298
+ const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
299
+ childrenArray.forEach((child, childIndex) => {
300
+ if (typeof child === 'string') {
301
+ stringNode += `${child}`;
302
+ } else if (React.isValidElement(child)) {
303
+ const childPropsCount = Object.keys(child.props).length;
304
+ const shouldKeepChild = keepArray.indexOf(child.type) > -1;
305
+ const childChildren = child.props.children;
306
+ if (!childChildren && shouldKeepChild && childPropsCount === 0) {
307
+ stringNode += `<${child.type}/>`;
308
+ } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
309
+ stringNode += `<${childIndex}></${childIndex}>`;
310
+ } else if (child.props.i18nIsDynamicList) {
311
+ stringNode += `<${childIndex}></${childIndex}>`;
312
+ } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
313
+ stringNode += `<${child.type}>${childChildren}</${child.type}>`;
314
+ } else {
315
+ const content = nodesToString(childChildren, i18nOptions);
316
+ stringNode += `<${childIndex}>${content}</${childIndex}>`;
317
+ }
318
+ } else if (child === null) {
319
+ warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
320
+ } else if (typeof child === 'object') {
321
+ const {
322
+ format,
323
+ ...clone
324
+ } = child;
325
+ const keys = Object.keys(clone);
326
+ if (keys.length === 1) {
327
+ const value = format ? `${keys[0]}, ${format}` : keys[0];
328
+ stringNode += `{{${value}}}`;
329
+ } else {
330
+ warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
331
+ }
332
+ } else {
333
+ 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);
334
+ }
335
+ });
336
+ return stringNode;
337
+ }
338
+ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
339
+ if (targetString === '') return [];
340
+ const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
341
+ const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
342
+ if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
343
+ const data = {};
344
+ function getData(childs) {
345
+ const childrenArray = getAsArray(childs);
346
+ childrenArray.forEach(child => {
347
+ if (typeof child === 'string') return;
348
+ if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !React.isValidElement(child)) Object.assign(data, child);
349
+ });
350
+ }
351
+ getData(children);
352
+ const ast = c.parse(`<0>${targetString}</0>`);
353
+ const opts = {
354
+ ...data,
355
+ ...combinedTOpts
356
+ };
357
+ function renderInner(child, node, rootReactNode) {
358
+ const childs = getChildren(child);
359
+ const mappedChildren = mapAST(childs, node.children, rootReactNode);
360
+ return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
361
+ }
362
+ function pushTranslatedJSX(child, inner, mem, i, isVoid) {
363
+ if (child.dummy) {
364
+ child.children = inner;
365
+ mem.push(React.cloneElement(child, {
366
+ key: i
367
+ }, isVoid ? undefined : inner));
368
+ } else {
369
+ mem.push(...React.Children.map([child], c => {
370
+ const props = {
371
+ ...c.props
372
+ };
373
+ delete props.i18nIsDynamicList;
374
+ return React.createElement(c.type, _extends({}, props, {
375
+ key: i,
376
+ ref: c.ref
377
+ }, isVoid ? {} : {
378
+ children: inner
379
+ }));
380
+ }));
381
+ }
382
+ }
383
+ function mapAST(reactNode, astNode, rootReactNode) {
384
+ const reactNodes = getAsArray(reactNode);
385
+ const astNodes = getAsArray(astNode);
386
+ return astNodes.reduce((mem, node, i) => {
387
+ const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
388
+ if (node.type === 'tag') {
389
+ let tmp = reactNodes[parseInt(node.name, 10)];
390
+ if (rootReactNode.length === 1) tmp ||= rootReactNode[0][node.name];
391
+ tmp ||= {};
392
+ const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
393
+ props: node.attrs
394
+ }, tmp) : tmp;
395
+ const isElement = React.isValidElement(child);
396
+ const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
397
+ const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
398
+ const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
399
+ if (typeof child === 'string') {
400
+ const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
401
+ mem.push(value);
402
+ } else if (hasChildren(child) || isValidTranslationWithChildren) {
403
+ const inner = renderInner(child, node, rootReactNode);
404
+ pushTranslatedJSX(child, inner, mem, i);
405
+ } else if (isEmptyTransWithHTML) {
406
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
407
+ pushTranslatedJSX(child, inner, mem, i);
408
+ } else if (Number.isNaN(parseFloat(node.name))) {
409
+ if (isKnownComponent) {
410
+ const inner = renderInner(child, node, rootReactNode);
411
+ pushTranslatedJSX(child, inner, mem, i, node.voidElement);
412
+ } else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
413
+ if (node.voidElement) {
414
+ mem.push(React.createElement(node.name, {
415
+ key: `${node.name}-${i}`
416
+ }));
417
+ } else {
418
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
419
+ mem.push(React.createElement(node.name, {
420
+ key: `${node.name}-${i}`
421
+ }, inner));
422
+ }
423
+ } else if (node.voidElement) {
424
+ mem.push(`<${node.name} />`);
425
+ } else {
426
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
427
+ mem.push(`<${node.name}>${inner}</${node.name}>`);
428
+ }
429
+ } else if (typeof child === 'object' && !isElement) {
430
+ const content = node.children[0] ? translationContent : null;
431
+ if (content) mem.push(content);
432
+ } else {
433
+ pushTranslatedJSX(child, translationContent, mem, i, node.children.length !== 1 || !translationContent);
434
+ }
435
+ } else if (node.type === 'text') {
436
+ const wrapTextNodes = i18nOptions.transWrapTextNodes;
437
+ const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
438
+ if (wrapTextNodes) {
439
+ mem.push(React.createElement(wrapTextNodes, {
440
+ key: `${node.name}-${i}`
441
+ }, content));
442
+ } else {
443
+ mem.push(content);
444
+ }
445
+ }
446
+ return mem;
447
+ }, []);
448
+ }
449
+ const result = mapAST([{
450
+ dummy: true,
451
+ children: children || []
452
+ }], ast, getAsArray(children || []));
453
+ return getChildren(result[0]);
454
+ }
455
+ function Trans$1(_ref) {
456
+ let {
457
+ children,
458
+ count,
459
+ parent,
460
+ i18nKey,
461
+ context,
462
+ tOptions = {},
463
+ values,
464
+ defaults,
465
+ components,
466
+ ns,
467
+ i18n: i18nFromProps,
468
+ t: tFromProps,
469
+ shouldUnescape,
470
+ ...additionalProps
471
+ } = _ref;
472
+ const i18n = i18nFromProps || getI18n();
473
+ if (!i18n) {
474
+ warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
475
+ return children;
476
+ }
477
+ const t = tFromProps || i18n.t.bind(i18n) || (k => k);
478
+ if (context) tOptions.context = context;
479
+ const reactI18nextOptions = {
480
+ ...getDefaults(),
481
+ ...(i18n.options && i18n.options.react)
482
+ };
483
+ let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
484
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
485
+ const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
486
+ const {
487
+ hashTransKey
488
+ } = reactI18nextOptions;
489
+ const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
490
+ const interpolationOverride = values ? tOptions.interpolation : {
491
+ interpolation: {
492
+ ...tOptions.interpolation,
493
+ prefix: '#$?',
494
+ suffix: '?$#'
495
+ }
496
+ };
497
+ const combinedTOpts = {
498
+ ...tOptions,
499
+ count,
500
+ ...values,
501
+ ...interpolationOverride,
502
+ defaultValue,
503
+ ns: namespaces
504
+ };
505
+ const translation = key ? t(key, combinedTOpts) : defaultValue;
506
+ const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
507
+ const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
508
+ return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content;
509
+ }
499
510
 
500
- const I18nContext = react.createContext();
501
- class ReportNamespaces {
502
- constructor() {
503
- this.usedNamespaces = {};
504
- }
505
- addUsedNamespaces(namespaces) {
506
- namespaces.forEach(ns => {
507
- if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
508
- });
509
- }
510
- getUsedNamespaces() {
511
- return Object.keys(this.usedNamespaces);
512
- }
513
- }
514
- function composeInitialProps(ForComponent) {
515
- return ctx => new Promise(resolve => {
516
- const i18nInitialProps = getInitialProps();
517
- if (ForComponent.getInitialProps) {
518
- ForComponent.getInitialProps(ctx).then(componentsInitialProps => {
519
- resolve({
520
- ...componentsInitialProps,
521
- ...i18nInitialProps
522
- });
523
- });
524
- } else {
525
- resolve(i18nInitialProps);
526
- }
527
- });
528
- }
529
- function getInitialProps() {
530
- const i18n = getI18n();
531
- const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
532
- const ret = {};
533
- const initialI18nStore = {};
534
- i18n.languages.forEach(l => {
535
- initialI18nStore[l] = {};
536
- namespaces.forEach(ns => {
537
- initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
538
- });
539
- });
540
- ret.initialI18nStore = initialI18nStore;
541
- ret.initialLanguage = i18n.language;
542
- return ret;
543
- }
511
+ const initReactI18next = {
512
+ type: '3rdParty',
513
+ init(instance) {
514
+ setDefaults(instance.options.react);
515
+ setI18n(instance);
516
+ }
517
+ };
544
518
 
545
- function Trans(_ref) {
546
- let {
547
- children,
548
- count,
549
- parent,
550
- i18nKey,
551
- context,
552
- tOptions = {},
553
- values,
554
- defaults,
555
- components,
556
- ns,
557
- i18n: i18nFromProps,
558
- t: tFromProps,
559
- shouldUnescape,
560
- ...additionalProps
561
- } = _ref;
562
- const {
563
- i18n: i18nFromContext,
564
- defaultNS: defaultNSFromContext
565
- } = react.useContext(I18nContext) || {};
566
- const i18n = i18nFromProps || i18nFromContext || getI18n();
567
- const t = tFromProps || i18n && i18n.t.bind(i18n);
568
- return Trans$1({
569
- children,
570
- count,
571
- parent,
572
- i18nKey,
573
- context,
574
- tOptions,
575
- values,
576
- defaults,
577
- components,
578
- ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
579
- i18n,
580
- t: tFromProps,
581
- shouldUnescape,
582
- ...additionalProps
583
- });
584
- }
519
+ const I18nContext = React.createContext();
520
+ class ReportNamespaces {
521
+ constructor() {
522
+ this.usedNamespaces = {};
523
+ }
524
+ addUsedNamespaces(namespaces) {
525
+ namespaces.forEach(ns => {
526
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
527
+ });
528
+ }
529
+ getUsedNamespaces() {
530
+ return Object.keys(this.usedNamespaces);
531
+ }
532
+ }
533
+ function composeInitialProps(ForComponent) {
534
+ return ctx => new Promise(resolve => {
535
+ const i18nInitialProps = getInitialProps();
536
+ if (ForComponent.getInitialProps) {
537
+ ForComponent.getInitialProps(ctx).then(componentsInitialProps => {
538
+ resolve({
539
+ ...componentsInitialProps,
540
+ ...i18nInitialProps
541
+ });
542
+ });
543
+ } else {
544
+ resolve(i18nInitialProps);
545
+ }
546
+ });
547
+ }
548
+ function getInitialProps() {
549
+ const i18n = getI18n();
550
+ const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
551
+ const ret = {};
552
+ const initialI18nStore = {};
553
+ i18n.languages.forEach(l => {
554
+ initialI18nStore[l] = {};
555
+ namespaces.forEach(ns => {
556
+ initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
557
+ });
558
+ });
559
+ ret.initialI18nStore = initialI18nStore;
560
+ ret.initialLanguage = i18n.language;
561
+ return ret;
562
+ }
585
563
 
586
- const usePrevious = (value, ignore) => {
587
- const ref = react.useRef();
588
- react.useEffect(() => {
589
- ref.current = ignore ? ref.current : value;
590
- }, [value, ignore]);
591
- return ref.current;
592
- };
593
- function useTranslation(ns) {
594
- let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
595
- const {
596
- i18n: i18nFromProps
597
- } = props;
598
- const {
599
- i18n: i18nFromContext,
600
- defaultNS: defaultNSFromContext
601
- } = react.useContext(I18nContext) || {};
602
- const i18n = i18nFromProps || i18nFromContext || getI18n();
603
- if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
604
- if (!i18n) {
605
- warnOnce('You will need to pass in an i18next instance by using initReactI18next');
606
- const notReadyT = (k, optsOrDefaultValue) => {
607
- if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
608
- if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
609
- return Array.isArray(k) ? k[k.length - 1] : k;
610
- };
611
- const retNotReady = [notReadyT, {}, false];
612
- retNotReady.t = notReadyT;
613
- retNotReady.i18n = {};
614
- retNotReady.ready = false;
615
- return retNotReady;
616
- }
617
- 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.');
618
- const i18nOptions = {
619
- ...getDefaults(),
620
- ...i18n.options.react,
621
- ...props
622
- };
623
- const {
624
- useSuspense,
625
- keyPrefix
626
- } = i18nOptions;
627
- let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
628
- namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
629
- if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
630
- const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
631
- function getT() {
632
- return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
633
- }
634
- const [t, setT] = react.useState(getT);
635
- let joinedNS = namespaces.join();
636
- if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
637
- const previousJoinedNS = usePrevious(joinedNS);
638
- const isMounted = react.useRef(true);
639
- react.useEffect(() => {
640
- const {
641
- bindI18n,
642
- bindI18nStore
643
- } = i18nOptions;
644
- isMounted.current = true;
645
- if (!ready && !useSuspense) {
646
- if (props.lng) {
647
- loadLanguages(i18n, props.lng, namespaces, () => {
648
- if (isMounted.current) setT(getT);
649
- });
650
- } else {
651
- loadNamespaces(i18n, namespaces, () => {
652
- if (isMounted.current) setT(getT);
653
- });
654
- }
655
- }
656
- if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
657
- setT(getT);
658
- }
659
- function boundReset() {
660
- if (isMounted.current) setT(getT);
661
- }
662
- if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
663
- if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
664
- return () => {
665
- isMounted.current = false;
666
- if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
667
- if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
668
- };
669
- }, [i18n, joinedNS]);
670
- const isInitial = react.useRef(true);
671
- react.useEffect(() => {
672
- if (isMounted.current && !isInitial.current) {
673
- setT(getT);
674
- }
675
- isInitial.current = false;
676
- }, [i18n, keyPrefix]);
677
- const ret = [t, i18n, ready];
678
- ret.t = t;
679
- ret.i18n = i18n;
680
- ret.ready = ready;
681
- if (ready) return ret;
682
- if (!ready && !useSuspense) return ret;
683
- throw new Promise(resolve => {
684
- if (props.lng) {
685
- loadLanguages(i18n, props.lng, namespaces, () => resolve());
686
- } else {
687
- loadNamespaces(i18n, namespaces, () => resolve());
688
- }
689
- });
690
- }
564
+ function Trans(_ref) {
565
+ let {
566
+ children,
567
+ count,
568
+ parent,
569
+ i18nKey,
570
+ context,
571
+ tOptions = {},
572
+ values,
573
+ defaults,
574
+ components,
575
+ ns,
576
+ i18n: i18nFromProps,
577
+ t: tFromProps,
578
+ shouldUnescape,
579
+ ...additionalProps
580
+ } = _ref;
581
+ const {
582
+ i18n: i18nFromContext,
583
+ defaultNS: defaultNSFromContext
584
+ } = React.useContext(I18nContext) || {};
585
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
586
+ const t = tFromProps || i18n && i18n.t.bind(i18n);
587
+ return Trans$1({
588
+ children,
589
+ count,
590
+ parent,
591
+ i18nKey,
592
+ context,
593
+ tOptions,
594
+ values,
595
+ defaults,
596
+ components,
597
+ ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
598
+ i18n,
599
+ t: tFromProps,
600
+ shouldUnescape,
601
+ ...additionalProps
602
+ });
603
+ }
691
604
 
692
- function withTranslation(ns) {
693
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
694
- return function Extend(WrappedComponent) {
695
- function I18nextWithTranslation(_ref) {
696
- let {
697
- forwardedRef,
698
- ...rest
699
- } = _ref;
700
- const [t, i18n, ready] = useTranslation(ns, {
701
- ...rest,
702
- keyPrefix: options.keyPrefix
703
- });
704
- const passDownProps = {
705
- ...rest,
706
- t,
707
- i18n,
708
- tReady: ready
709
- };
710
- if (options.withRef && forwardedRef) {
711
- passDownProps.ref = forwardedRef;
712
- } else if (!options.withRef && forwardedRef) {
713
- passDownProps.forwardedRef = forwardedRef;
714
- }
715
- return react.createElement(WrappedComponent, passDownProps);
716
- }
717
- I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`;
718
- I18nextWithTranslation.WrappedComponent = WrappedComponent;
719
- const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, {
720
- forwardedRef: ref
721
- }));
722
- return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
723
- };
724
- }
605
+ const usePrevious = (value, ignore) => {
606
+ const ref = React.useRef();
607
+ React.useEffect(() => {
608
+ ref.current = ignore ? ref.current : value;
609
+ }, [value, ignore]);
610
+ return ref.current;
611
+ };
612
+ function useTranslation(ns) {
613
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
614
+ const {
615
+ i18n: i18nFromProps
616
+ } = props;
617
+ const {
618
+ i18n: i18nFromContext,
619
+ defaultNS: defaultNSFromContext
620
+ } = React.useContext(I18nContext) || {};
621
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
622
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
623
+ if (!i18n) {
624
+ warnOnce('You will need to pass in an i18next instance by using initReactI18next');
625
+ const notReadyT = (k, optsOrDefaultValue) => {
626
+ if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
627
+ if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
628
+ return Array.isArray(k) ? k[k.length - 1] : k;
629
+ };
630
+ const retNotReady = [notReadyT, {}, false];
631
+ retNotReady.t = notReadyT;
632
+ retNotReady.i18n = {};
633
+ retNotReady.ready = false;
634
+ return retNotReady;
635
+ }
636
+ 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.');
637
+ const i18nOptions = {
638
+ ...getDefaults(),
639
+ ...i18n.options.react,
640
+ ...props
641
+ };
642
+ const {
643
+ useSuspense,
644
+ keyPrefix
645
+ } = i18nOptions;
646
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
647
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
648
+ if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
649
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
650
+ function getT() {
651
+ return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
652
+ }
653
+ const [t, setT] = React.useState(getT);
654
+ let joinedNS = namespaces.join();
655
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
656
+ const previousJoinedNS = usePrevious(joinedNS);
657
+ const isMounted = React.useRef(true);
658
+ React.useEffect(() => {
659
+ const {
660
+ bindI18n,
661
+ bindI18nStore
662
+ } = i18nOptions;
663
+ isMounted.current = true;
664
+ if (!ready && !useSuspense) {
665
+ if (props.lng) {
666
+ loadLanguages(i18n, props.lng, namespaces, () => {
667
+ if (isMounted.current) setT(getT);
668
+ });
669
+ } else {
670
+ loadNamespaces(i18n, namespaces, () => {
671
+ if (isMounted.current) setT(getT);
672
+ });
673
+ }
674
+ }
675
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
676
+ setT(getT);
677
+ }
678
+ function boundReset() {
679
+ if (isMounted.current) setT(getT);
680
+ }
681
+ if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
682
+ if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
683
+ return () => {
684
+ isMounted.current = false;
685
+ if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
686
+ if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
687
+ };
688
+ }, [i18n, joinedNS]);
689
+ const isInitial = React.useRef(true);
690
+ React.useEffect(() => {
691
+ if (isMounted.current && !isInitial.current) {
692
+ setT(getT);
693
+ }
694
+ isInitial.current = false;
695
+ }, [i18n, keyPrefix]);
696
+ const ret = [t, i18n, ready];
697
+ ret.t = t;
698
+ ret.i18n = i18n;
699
+ ret.ready = ready;
700
+ if (ready) return ret;
701
+ if (!ready && !useSuspense) return ret;
702
+ throw new Promise(resolve => {
703
+ if (props.lng) {
704
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
705
+ } else {
706
+ loadNamespaces(i18n, namespaces, () => resolve());
707
+ }
708
+ });
709
+ }
725
710
 
726
- function Translation(props) {
727
- const {
728
- ns,
729
- children,
730
- ...options
731
- } = props;
732
- const [t, i18n, ready] = useTranslation(ns, options);
733
- return children(t, {
734
- i18n,
735
- lng: i18n.language
736
- }, ready);
737
- }
711
+ function withTranslation(ns) {
712
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
713
+ return function Extend(WrappedComponent) {
714
+ function I18nextWithTranslation(_ref) {
715
+ let {
716
+ forwardedRef,
717
+ ...rest
718
+ } = _ref;
719
+ const [t, i18n, ready] = useTranslation(ns, {
720
+ ...rest,
721
+ keyPrefix: options.keyPrefix
722
+ });
723
+ const passDownProps = {
724
+ ...rest,
725
+ t,
726
+ i18n,
727
+ tReady: ready
728
+ };
729
+ if (options.withRef && forwardedRef) {
730
+ passDownProps.ref = forwardedRef;
731
+ } else if (!options.withRef && forwardedRef) {
732
+ passDownProps.forwardedRef = forwardedRef;
733
+ }
734
+ return React.createElement(WrappedComponent, passDownProps);
735
+ }
736
+ I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`;
737
+ I18nextWithTranslation.WrappedComponent = WrappedComponent;
738
+ const forwardRef = (props, ref) => React.createElement(I18nextWithTranslation, Object.assign({}, props, {
739
+ forwardedRef: ref
740
+ }));
741
+ return options.withRef ? React.forwardRef(forwardRef) : I18nextWithTranslation;
742
+ };
743
+ }
738
744
 
739
- function I18nextProvider(_ref) {
740
- let {
741
- i18n,
742
- defaultNS,
743
- children
744
- } = _ref;
745
- const value = react.useMemo(() => ({
746
- i18n,
747
- defaultNS
748
- }), [i18n, defaultNS]);
749
- return react.createElement(I18nContext.Provider, {
750
- value
751
- }, children);
752
- }
745
+ function Translation(props) {
746
+ const {
747
+ ns,
748
+ children,
749
+ ...options
750
+ } = props;
751
+ const [t, i18n, ready] = useTranslation(ns, options);
752
+ return children(t, {
753
+ i18n,
754
+ lng: i18n.language
755
+ }, ready);
756
+ }
753
757
 
754
- function useSSR(initialI18nStore, initialLanguage) {
755
- let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
756
- const {
757
- i18n: i18nFromProps
758
- } = props;
759
- const {
760
- i18n: i18nFromContext
761
- } = react.useContext(I18nContext) || {};
762
- const i18n = i18nFromProps || i18nFromContext || getI18n();
763
- if (i18n.options && i18n.options.isClone) return;
764
- if (initialI18nStore && !i18n.initializedStoreOnce) {
765
- i18n.services.resourceStore.data = initialI18nStore;
766
- i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
767
- Object.keys(lngResources).forEach(ns => {
768
- if (mem.indexOf(ns) < 0) mem.push(ns);
769
- });
770
- return mem;
771
- }, i18n.options.ns);
772
- i18n.initializedStoreOnce = true;
773
- i18n.isInitialized = true;
774
- }
775
- if (initialLanguage && !i18n.initializedLanguageOnce) {
776
- i18n.changeLanguage(initialLanguage);
777
- i18n.initializedLanguageOnce = true;
778
- }
779
- }
758
+ function I18nextProvider(_ref) {
759
+ let {
760
+ i18n,
761
+ defaultNS,
762
+ children
763
+ } = _ref;
764
+ const value = React.useMemo(() => ({
765
+ i18n,
766
+ defaultNS
767
+ }), [i18n, defaultNS]);
768
+ return React.createElement(I18nContext.Provider, {
769
+ value
770
+ }, children);
771
+ }
780
772
 
781
- function withSSR() {
782
- return function Extend(WrappedComponent) {
783
- function I18nextWithSSR(_ref) {
784
- let {
785
- initialI18nStore,
786
- initialLanguage,
787
- ...rest
788
- } = _ref;
789
- useSSR(initialI18nStore, initialLanguage);
790
- return react.createElement(WrappedComponent, {
791
- ...rest
792
- });
793
- }
794
- I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
795
- I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`;
796
- I18nextWithSSR.WrappedComponent = WrappedComponent;
797
- return I18nextWithSSR;
798
- };
799
- }
773
+ function useSSR(initialI18nStore, initialLanguage) {
774
+ let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
775
+ const {
776
+ i18n: i18nFromProps
777
+ } = props;
778
+ const {
779
+ i18n: i18nFromContext
780
+ } = React.useContext(I18nContext) || {};
781
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
782
+ if (i18n.options && i18n.options.isClone) return;
783
+ if (initialI18nStore && !i18n.initializedStoreOnce) {
784
+ i18n.services.resourceStore.data = initialI18nStore;
785
+ i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
786
+ Object.keys(lngResources).forEach(ns => {
787
+ if (mem.indexOf(ns) < 0) mem.push(ns);
788
+ });
789
+ return mem;
790
+ }, i18n.options.ns);
791
+ i18n.initializedStoreOnce = true;
792
+ i18n.isInitialized = true;
793
+ }
794
+ if (initialLanguage && !i18n.initializedLanguageOnce) {
795
+ i18n.changeLanguage(initialLanguage);
796
+ i18n.initializedLanguageOnce = true;
797
+ }
798
+ }
800
799
 
801
- const date = () => '';
802
- const time = () => '';
803
- const number = () => '';
804
- const select = () => '';
805
- const plural = () => '';
806
- const selectOrdinal = () => '';
800
+ function withSSR() {
801
+ return function Extend(WrappedComponent) {
802
+ function I18nextWithSSR(_ref) {
803
+ let {
804
+ initialI18nStore,
805
+ initialLanguage,
806
+ ...rest
807
+ } = _ref;
808
+ useSSR(initialI18nStore, initialLanguage);
809
+ return React.createElement(WrappedComponent, {
810
+ ...rest
811
+ });
812
+ }
813
+ I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
814
+ I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`;
815
+ I18nextWithSSR.WrappedComponent = WrappedComponent;
816
+ return I18nextWithSSR;
817
+ };
818
+ }
807
819
 
808
- exports.I18nContext = I18nContext;
809
- exports.I18nextProvider = I18nextProvider;
810
- exports.Trans = Trans;
811
- exports.TransWithoutContext = Trans$1;
812
- exports.Translation = Translation;
813
- exports.composeInitialProps = composeInitialProps;
814
- exports.date = date;
815
- exports.getDefaults = getDefaults;
816
- exports.getI18n = getI18n;
817
- exports.getInitialProps = getInitialProps;
818
- exports.initReactI18next = initReactI18next;
819
- exports.number = number;
820
- exports.plural = plural;
821
- exports.select = select;
822
- exports.selectOrdinal = selectOrdinal;
823
- exports.setDefaults = setDefaults;
824
- exports.setI18n = setI18n;
825
- exports.time = time;
826
- exports.useSSR = useSSR;
827
- exports.useTranslation = useTranslation;
828
- exports.withSSR = withSSR;
829
- exports.withTranslation = withTranslation;
820
+ const date = () => '';
821
+ const time = () => '';
822
+ const number = () => '';
823
+ const select = () => '';
824
+ const plural = () => '';
825
+ const selectOrdinal = () => '';
826
+
827
+ exports.I18nContext = I18nContext;
828
+ exports.I18nextProvider = I18nextProvider;
829
+ exports.Trans = Trans;
830
+ exports.TransWithoutContext = Trans$1;
831
+ exports.Translation = Translation;
832
+ exports.composeInitialProps = composeInitialProps;
833
+ exports.date = date;
834
+ exports.getDefaults = getDefaults;
835
+ exports.getI18n = getI18n;
836
+ exports.getInitialProps = getInitialProps;
837
+ exports.initReactI18next = initReactI18next;
838
+ exports.number = number;
839
+ exports.plural = plural;
840
+ exports.select = select;
841
+ exports.selectOrdinal = selectOrdinal;
842
+ exports.setDefaults = setDefaults;
843
+ exports.setI18n = setI18n;
844
+ exports.time = time;
845
+ exports.useSSR = useSSR;
846
+ exports.useTranslation = useTranslation;
847
+ exports.withSSR = withSSR;
848
+ exports.withTranslation = withTranslation;
830
849
 
831
850
  }));