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