react-i18next 12.3.0 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +1 -1
- package/TransWithoutContext.d.ts +26 -16
- package/dist/amd/react-i18next.js +827 -1104
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/I18nextProvider.js +10 -13
- package/dist/commonjs/Trans.js +37 -52
- package/dist/commonjs/TransWithoutContext.js +130 -168
- package/dist/commonjs/Translation.js +8 -22
- package/dist/commonjs/context.js +45 -76
- package/dist/commonjs/defaults.js +7 -16
- package/dist/commonjs/i18nInstance.js +2 -4
- package/dist/commonjs/index.js +52 -86
- package/dist/commonjs/initReactI18next.js +2 -5
- package/dist/commonjs/unescape.js +4 -11
- package/dist/commonjs/useSSR.js +10 -14
- package/dist/commonjs/useTranslation.js +57 -79
- package/dist/commonjs/utils.js +38 -47
- package/dist/commonjs/withSSR.js +9 -23
- package/dist/commonjs/withTranslation.js +18 -45
- package/dist/es/I18nextProvider.js +10 -10
- package/dist/es/Trans.js +36 -43
- package/dist/es/TransWithoutContext.js +129 -159
- package/dist/es/Translation.js +7 -14
- package/dist/es/context.js +30 -50
- package/dist/es/defaults.js +7 -10
- package/dist/es/i18nInstance.js +1 -1
- package/dist/es/index.js +6 -18
- package/dist/es/initReactI18next.js +2 -2
- package/dist/es/package.json +1 -1
- package/dist/es/unescape.js +4 -10
- package/dist/es/useSSR.js +10 -11
- package/dist/es/useTranslation.js +58 -73
- package/dist/es/utils.js +34 -39
- package/dist/es/withSSR.js +9 -15
- package/dist/es/withTranslation.js +17 -35
- package/dist/umd/react-i18next.js +828 -1105
- package/dist/umd/react-i18next.min.js +1 -1
- package/helpers.d.ts +3 -0
- package/icu.macro.d.ts +37 -39
- package/index.d.ts +44 -37
- package/initReactI18next.d.ts +1 -1
- package/package.json +36 -36
- package/react-i18next.js +828 -1105
- package/react-i18next.min.js +1 -1
- package/src/useTranslation.js +17 -8
- package/src/utils.js +27 -15
|
@@ -1,288 +1,250 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.nodesToString = nodesToString;
|
|
9
7
|
exports.Trans = Trans;
|
|
10
|
-
|
|
11
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
12
|
-
|
|
13
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
14
|
-
|
|
15
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
-
|
|
8
|
+
exports.nodesToString = nodesToString;
|
|
17
9
|
var _react = require("react");
|
|
18
|
-
|
|
19
10
|
var _htmlParseStringify = _interopRequireDefault(require("html-parse-stringify"));
|
|
20
|
-
|
|
21
11
|
var _utils = require("./utils.js");
|
|
22
|
-
|
|
23
12
|
var _defaults = require("./defaults.js");
|
|
24
|
-
|
|
25
13
|
var _i18nInstance = require("./i18nInstance.js");
|
|
26
|
-
|
|
27
|
-
var _excluded = ["format"],
|
|
28
|
-
_excluded2 = ["children", "count", "parent", "i18nKey", "context", "tOptions", "values", "defaults", "components", "ns", "i18n", "t", "shouldUnescape"];
|
|
29
|
-
|
|
30
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
-
|
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
33
|
-
|
|
34
14
|
function hasChildren(node, checkLength) {
|
|
35
15
|
if (!node) return false;
|
|
36
|
-
|
|
16
|
+
const base = node.props ? node.props.children : node.children;
|
|
37
17
|
if (checkLength) return base.length > 0;
|
|
38
18
|
return !!base;
|
|
39
19
|
}
|
|
40
|
-
|
|
41
20
|
function getChildren(node) {
|
|
42
21
|
if (!node) return [];
|
|
43
22
|
return node.props ? node.props.children : node.children;
|
|
44
23
|
}
|
|
45
|
-
|
|
46
24
|
function hasValidReactChildren(children) {
|
|
47
25
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
48
|
-
return children.every(
|
|
49
|
-
return (0, _react.isValidElement)(child);
|
|
50
|
-
});
|
|
26
|
+
return children.every(child => (0, _react.isValidElement)(child));
|
|
51
27
|
}
|
|
52
|
-
|
|
53
28
|
function getAsArray(data) {
|
|
54
29
|
return Array.isArray(data) ? data : [data];
|
|
55
30
|
}
|
|
56
|
-
|
|
57
31
|
function mergeProps(source, target) {
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
const newTarget = {
|
|
33
|
+
...target
|
|
34
|
+
};
|
|
60
35
|
newTarget.props = Object.assign(source.props, target.props);
|
|
61
36
|
return newTarget;
|
|
62
37
|
}
|
|
63
|
-
|
|
64
38
|
function nodesToString(children, i18nOptions) {
|
|
65
39
|
if (!children) return '';
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
childrenArray.forEach(
|
|
40
|
+
let stringNode = '';
|
|
41
|
+
const childrenArray = getAsArray(children);
|
|
42
|
+
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
43
|
+
childrenArray.forEach((child, childIndex) => {
|
|
70
44
|
if (typeof child === 'string') {
|
|
71
|
-
stringNode +=
|
|
45
|
+
stringNode += `${child}`;
|
|
72
46
|
} else if ((0, _react.isValidElement)(child)) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
47
|
+
const childPropsCount = Object.keys(child.props).length;
|
|
48
|
+
const shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
49
|
+
const childChildren = child.props.children;
|
|
77
50
|
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
78
|
-
stringNode +=
|
|
51
|
+
stringNode += `<${child.type}/>`;
|
|
79
52
|
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
80
|
-
stringNode +=
|
|
53
|
+
stringNode += `<${childIndex}></${childIndex}>`;
|
|
81
54
|
} else if (child.props.i18nIsDynamicList) {
|
|
82
|
-
stringNode +=
|
|
55
|
+
stringNode += `<${childIndex}></${childIndex}>`;
|
|
83
56
|
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
84
|
-
stringNode +=
|
|
57
|
+
stringNode += `<${child.type}>${childChildren}</${child.type}>`;
|
|
85
58
|
} else {
|
|
86
|
-
|
|
87
|
-
stringNode +=
|
|
59
|
+
const content = nodesToString(childChildren, i18nOptions);
|
|
60
|
+
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
88
61
|
}
|
|
89
62
|
} else if (child === null) {
|
|
90
|
-
(0, _utils.warn)(
|
|
91
|
-
} else if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
63
|
+
(0, _utils.warn)(`Trans: the passed in value is invalid - seems you passed in a null child.`);
|
|
64
|
+
} else if (typeof child === 'object') {
|
|
65
|
+
const {
|
|
66
|
+
format,
|
|
67
|
+
...clone
|
|
68
|
+
} = child;
|
|
69
|
+
const keys = Object.keys(clone);
|
|
96
70
|
if (keys.length === 1) {
|
|
97
|
-
|
|
98
|
-
stringNode +=
|
|
71
|
+
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
72
|
+
stringNode += `{{${value}}}`;
|
|
99
73
|
} else {
|
|
100
|
-
(0, _utils.warn)(
|
|
74
|
+
(0, _utils.warn)(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
|
|
101
75
|
}
|
|
102
76
|
} else {
|
|
103
|
-
(0, _utils.warn)(
|
|
77
|
+
(0, _utils.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);
|
|
104
78
|
}
|
|
105
79
|
});
|
|
106
80
|
return stringNode;
|
|
107
81
|
}
|
|
108
|
-
|
|
109
82
|
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
|
|
110
83
|
if (targetString === '') return [];
|
|
111
|
-
|
|
112
|
-
|
|
84
|
+
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
85
|
+
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
113
86
|
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
114
|
-
|
|
115
|
-
|
|
87
|
+
const data = {};
|
|
116
88
|
function getData(childs) {
|
|
117
|
-
|
|
118
|
-
childrenArray.forEach(
|
|
89
|
+
const childrenArray = getAsArray(childs);
|
|
90
|
+
childrenArray.forEach(child => {
|
|
119
91
|
if (typeof child === 'string') return;
|
|
120
|
-
if (hasChildren(child)) getData(getChildren(child));else if (
|
|
92
|
+
if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !(0, _react.isValidElement)(child)) Object.assign(data, child);
|
|
121
93
|
});
|
|
122
94
|
}
|
|
123
|
-
|
|
124
95
|
getData(children);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
96
|
+
const ast = _htmlParseStringify.default.parse(`<0>${targetString}</0>`);
|
|
97
|
+
const opts = {
|
|
98
|
+
...data,
|
|
99
|
+
...combinedTOpts
|
|
100
|
+
};
|
|
130
101
|
function renderInner(child, node, rootReactNode) {
|
|
131
|
-
|
|
132
|
-
|
|
102
|
+
const childs = getChildren(child);
|
|
103
|
+
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
133
104
|
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
134
105
|
}
|
|
135
|
-
|
|
136
106
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
137
107
|
if (child.dummy) child.children = inner;
|
|
138
|
-
mem.push((0, _react.cloneElement)(child,
|
|
108
|
+
mem.push((0, _react.cloneElement)(child, {
|
|
109
|
+
...child.props,
|
|
139
110
|
key: i
|
|
140
|
-
}
|
|
111
|
+
}, isVoid ? undefined : inner));
|
|
141
112
|
}
|
|
142
|
-
|
|
143
113
|
function mapAST(reactNode, astNode, rootReactNode) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return astNodes.reduce(
|
|
147
|
-
|
|
148
|
-
|
|
114
|
+
const reactNodes = getAsArray(reactNode);
|
|
115
|
+
const astNodes = getAsArray(astNode);
|
|
116
|
+
return astNodes.reduce((mem, node, i) => {
|
|
117
|
+
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
149
118
|
if (node.type === 'tag') {
|
|
150
|
-
|
|
119
|
+
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
151
120
|
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
152
121
|
if (!tmp) tmp = {};
|
|
153
|
-
|
|
122
|
+
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
154
123
|
props: node.attrs
|
|
155
124
|
}, tmp) : tmp;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
125
|
+
const isElement = (0, _react.isValidElement)(child);
|
|
126
|
+
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
127
|
+
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
|
|
128
|
+
const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
161
129
|
if (typeof child === 'string') {
|
|
162
|
-
|
|
130
|
+
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
163
131
|
mem.push(value);
|
|
164
132
|
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
133
|
+
const inner = renderInner(child, node, rootReactNode);
|
|
134
|
+
pushTranslatedJSX(child, inner, mem, i);
|
|
135
|
+
} else if (isEmptyTransWithHTML) {
|
|
136
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
137
|
+
mem.push((0, _react.cloneElement)(child, {
|
|
138
|
+
...child.props,
|
|
171
139
|
key: i
|
|
172
|
-
}
|
|
140
|
+
}, inner));
|
|
173
141
|
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
174
142
|
if (isKnownComponent) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
pushTranslatedJSX(child, _inner2, mem, i, node.voidElement);
|
|
143
|
+
const inner = renderInner(child, node, rootReactNode);
|
|
144
|
+
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
178
145
|
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
179
146
|
if (node.voidElement) {
|
|
180
147
|
mem.push((0, _react.createElement)(node.name, {
|
|
181
|
-
key:
|
|
148
|
+
key: `${node.name}-${i}`
|
|
182
149
|
}));
|
|
183
150
|
} else {
|
|
184
|
-
|
|
185
|
-
|
|
151
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
186
152
|
mem.push((0, _react.createElement)(node.name, {
|
|
187
|
-
key:
|
|
188
|
-
},
|
|
153
|
+
key: `${node.name}-${i}`
|
|
154
|
+
}, inner));
|
|
189
155
|
}
|
|
190
156
|
} else if (node.voidElement) {
|
|
191
|
-
mem.push(
|
|
157
|
+
mem.push(`<${node.name} />`);
|
|
192
158
|
} else {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
mem.push("<".concat(node.name, ">").concat(_inner4, "</").concat(node.name, ">"));
|
|
159
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
160
|
+
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
196
161
|
}
|
|
197
|
-
} else if (
|
|
198
|
-
|
|
162
|
+
} else if (typeof child === 'object' && !isElement) {
|
|
163
|
+
const content = node.children[0] ? translationContent : null;
|
|
199
164
|
if (content) mem.push(content);
|
|
200
165
|
} else if (node.children.length === 1 && translationContent) {
|
|
201
|
-
mem.push((0, _react.cloneElement)(child,
|
|
166
|
+
mem.push((0, _react.cloneElement)(child, {
|
|
167
|
+
...child.props,
|
|
202
168
|
key: i
|
|
203
|
-
}
|
|
169
|
+
}, translationContent));
|
|
204
170
|
} else {
|
|
205
|
-
mem.push((0, _react.cloneElement)(child,
|
|
171
|
+
mem.push((0, _react.cloneElement)(child, {
|
|
172
|
+
...child.props,
|
|
206
173
|
key: i
|
|
207
|
-
}))
|
|
174
|
+
}));
|
|
208
175
|
}
|
|
209
176
|
} else if (node.type === 'text') {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
var _content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
213
|
-
|
|
177
|
+
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
178
|
+
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
214
179
|
if (wrapTextNodes) {
|
|
215
180
|
mem.push((0, _react.createElement)(wrapTextNodes, {
|
|
216
|
-
key:
|
|
217
|
-
},
|
|
181
|
+
key: `${node.name}-${i}`
|
|
182
|
+
}, content));
|
|
218
183
|
} else {
|
|
219
|
-
mem.push(
|
|
184
|
+
mem.push(content);
|
|
220
185
|
}
|
|
221
186
|
}
|
|
222
|
-
|
|
223
187
|
return mem;
|
|
224
188
|
}, []);
|
|
225
189
|
}
|
|
226
|
-
|
|
227
|
-
var result = mapAST([{
|
|
190
|
+
const result = mapAST([{
|
|
228
191
|
dummy: true,
|
|
229
192
|
children: children || []
|
|
230
193
|
}], ast, getAsArray(children || []));
|
|
231
194
|
return getChildren(result[0]);
|
|
232
195
|
}
|
|
233
|
-
|
|
234
196
|
function Trans(_ref) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
197
|
+
let {
|
|
198
|
+
children,
|
|
199
|
+
count,
|
|
200
|
+
parent,
|
|
201
|
+
i18nKey,
|
|
202
|
+
context,
|
|
203
|
+
tOptions = {},
|
|
204
|
+
values,
|
|
205
|
+
defaults,
|
|
206
|
+
components,
|
|
207
|
+
ns,
|
|
208
|
+
i18n: i18nFromProps,
|
|
209
|
+
t: tFromProps,
|
|
210
|
+
shouldUnescape,
|
|
211
|
+
...additionalProps
|
|
212
|
+
} = _ref;
|
|
213
|
+
const i18n = i18nFromProps || (0, _i18nInstance.getI18n)();
|
|
252
214
|
if (!i18n) {
|
|
253
215
|
(0, _utils.warnOnce)('You will need to pass in an i18next instance by using i18nextReactModule');
|
|
254
216
|
return children;
|
|
255
217
|
}
|
|
256
|
-
|
|
257
|
-
var t = tFromProps || i18n.t.bind(i18n) || function (k) {
|
|
258
|
-
return k;
|
|
259
|
-
};
|
|
260
|
-
|
|
218
|
+
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
|
|
261
219
|
if (context) tOptions.context = context;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
220
|
+
const reactI18nextOptions = {
|
|
221
|
+
...(0, _defaults.getDefaults)(),
|
|
222
|
+
...(i18n.options && i18n.options.react)
|
|
223
|
+
};
|
|
224
|
+
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
|
|
266
225
|
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
226
|
+
const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
227
|
+
const {
|
|
228
|
+
hashTransKey
|
|
229
|
+
} = reactI18nextOptions;
|
|
230
|
+
const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
231
|
+
const interpolationOverride = values ? tOptions.interpolation : {
|
|
232
|
+
interpolation: {
|
|
233
|
+
...tOptions.interpolation,
|
|
272
234
|
prefix: '#$?',
|
|
273
235
|
suffix: '?$#'
|
|
274
|
-
}
|
|
236
|
+
}
|
|
275
237
|
};
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
count
|
|
279
|
-
|
|
280
|
-
|
|
238
|
+
const combinedTOpts = {
|
|
239
|
+
...tOptions,
|
|
240
|
+
count,
|
|
241
|
+
...values,
|
|
242
|
+
...interpolationOverride,
|
|
243
|
+
defaultValue,
|
|
281
244
|
ns: namespaces
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
245
|
+
};
|
|
246
|
+
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
247
|
+
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
248
|
+
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
287
249
|
return useAsParent ? (0, _react.createElement)(useAsParent, additionalProps, content) : content;
|
|
288
250
|
}
|
|
@@ -1,33 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.Translation = Translation;
|
|
9
|
-
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
|
|
12
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
-
|
|
14
|
-
var _useTranslation3 = require("./useTranslation.js");
|
|
15
|
-
|
|
16
|
-
var _excluded = ["ns", "children"];
|
|
17
|
-
|
|
7
|
+
var _useTranslation = require("./useTranslation.js");
|
|
18
8
|
function Translation(props) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
t = _useTranslation2[0],
|
|
26
|
-
i18n = _useTranslation2[1],
|
|
27
|
-
ready = _useTranslation2[2];
|
|
28
|
-
|
|
9
|
+
const {
|
|
10
|
+
ns,
|
|
11
|
+
children,
|
|
12
|
+
...options
|
|
13
|
+
} = props;
|
|
14
|
+
const [t, i18n, ready] = (0, _useTranslation.useTranslation)(ns, options);
|
|
29
15
|
return children(t, {
|
|
30
|
-
i18n
|
|
16
|
+
i18n,
|
|
31
17
|
lng: i18n.language
|
|
32
18
|
}, ready);
|
|
33
19
|
}
|
package/dist/commonjs/context.js
CHANGED
|
@@ -1,115 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
6
|
+
exports.ReportNamespaces = exports.I18nContext = void 0;
|
|
8
7
|
exports.composeInitialProps = composeInitialProps;
|
|
9
|
-
exports.getInitialProps = getInitialProps;
|
|
10
8
|
Object.defineProperty(exports, "getDefaults", {
|
|
11
9
|
enumerable: true,
|
|
12
|
-
get: function
|
|
10
|
+
get: function () {
|
|
13
11
|
return _defaults.getDefaults;
|
|
14
12
|
}
|
|
15
13
|
});
|
|
16
|
-
Object.defineProperty(exports, "
|
|
14
|
+
Object.defineProperty(exports, "getI18n", {
|
|
17
15
|
enumerable: true,
|
|
18
|
-
get: function
|
|
19
|
-
return
|
|
16
|
+
get: function () {
|
|
17
|
+
return _i18nInstance.getI18n;
|
|
20
18
|
}
|
|
21
19
|
});
|
|
22
|
-
|
|
20
|
+
exports.getInitialProps = getInitialProps;
|
|
21
|
+
Object.defineProperty(exports, "initReactI18next", {
|
|
23
22
|
enumerable: true,
|
|
24
|
-
get: function
|
|
25
|
-
return
|
|
23
|
+
get: function () {
|
|
24
|
+
return _initReactI18next.initReactI18next;
|
|
26
25
|
}
|
|
27
26
|
});
|
|
28
|
-
Object.defineProperty(exports, "
|
|
27
|
+
Object.defineProperty(exports, "setDefaults", {
|
|
29
28
|
enumerable: true,
|
|
30
|
-
get: function
|
|
31
|
-
return
|
|
29
|
+
get: function () {
|
|
30
|
+
return _defaults.setDefaults;
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
|
-
Object.defineProperty(exports, "
|
|
33
|
+
Object.defineProperty(exports, "setI18n", {
|
|
35
34
|
enumerable: true,
|
|
36
|
-
get: function
|
|
37
|
-
return
|
|
35
|
+
get: function () {
|
|
36
|
+
return _i18nInstance.setI18n;
|
|
38
37
|
}
|
|
39
38
|
});
|
|
40
|
-
exports.ReportNamespaces = exports.I18nContext = void 0;
|
|
41
|
-
|
|
42
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
43
|
-
|
|
44
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
45
|
-
|
|
46
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
47
|
-
|
|
48
39
|
var _react = require("react");
|
|
49
|
-
|
|
50
40
|
var _defaults = require("./defaults.js");
|
|
51
|
-
|
|
52
41
|
var _i18nInstance = require("./i18nInstance.js");
|
|
53
|
-
|
|
54
42
|
var _initReactI18next = require("./initReactI18next.js");
|
|
55
|
-
|
|
56
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
57
|
-
|
|
58
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
59
|
-
|
|
60
|
-
var I18nContext = (0, _react.createContext)();
|
|
43
|
+
const I18nContext = (0, _react.createContext)();
|
|
61
44
|
exports.I18nContext = I18nContext;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
function ReportNamespaces() {
|
|
65
|
-
(0, _classCallCheck2["default"])(this, ReportNamespaces);
|
|
45
|
+
class ReportNamespaces {
|
|
46
|
+
constructor() {
|
|
66
47
|
this.usedNamespaces = {};
|
|
67
48
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
key: "getUsedNamespaces",
|
|
80
|
-
value: function getUsedNamespaces() {
|
|
81
|
-
return Object.keys(this.usedNamespaces);
|
|
82
|
-
}
|
|
83
|
-
}]);
|
|
84
|
-
return ReportNamespaces;
|
|
85
|
-
}();
|
|
86
|
-
|
|
49
|
+
addUsedNamespaces(namespaces) {
|
|
50
|
+
namespaces.forEach(ns => {
|
|
51
|
+
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
getUsedNamespaces() {
|
|
55
|
+
return Object.keys(this.usedNamespaces);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
87
58
|
exports.ReportNamespaces = ReportNamespaces;
|
|
88
|
-
|
|
89
59
|
function composeInitialProps(ForComponent) {
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
60
|
+
return ctx => new Promise(resolve => {
|
|
61
|
+
const i18nInitialProps = getInitialProps();
|
|
62
|
+
if (ForComponent.getInitialProps) {
|
|
63
|
+
ForComponent.getInitialProps(ctx).then(componentsInitialProps => {
|
|
64
|
+
resolve({
|
|
65
|
+
...componentsInitialProps,
|
|
66
|
+
...i18nInitialProps
|
|
97
67
|
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
};
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
resolve(i18nInitialProps);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
103
73
|
}
|
|
104
|
-
|
|
105
74
|
function getInitialProps() {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
i18n.languages.forEach(
|
|
75
|
+
const i18n = (0, _i18nInstance.getI18n)();
|
|
76
|
+
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
|
|
77
|
+
const ret = {};
|
|
78
|
+
const initialI18nStore = {};
|
|
79
|
+
i18n.languages.forEach(l => {
|
|
111
80
|
initialI18nStore[l] = {};
|
|
112
|
-
namespaces.forEach(
|
|
81
|
+
namespaces.forEach(ns => {
|
|
113
82
|
initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
|
|
114
83
|
});
|
|
115
84
|
});
|