react-i18next 14.0.0 → 14.0.2

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