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