react-i18next 12.3.1 → 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 +5 -0
- package/TransWithoutContext.d.ts +26 -16
- package/dist/amd/react-i18next.js +827 -1130
- 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 +47 -82
- package/dist/commonjs/utils.js +29 -52
- 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 +47 -75
- package/dist/es/utils.js +25 -43
- package/dist/es/withSSR.js +9 -15
- package/dist/es/withTranslation.js +17 -35
- package/dist/umd/react-i18next.js +828 -1131
- 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 -1131
- package/react-i18next.min.js +1 -1
|
@@ -1,272 +1,242 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
var _excluded = ["format"],
|
|
5
|
-
_excluded2 = ["children", "count", "parent", "i18nKey", "context", "tOptions", "values", "defaults", "components", "ns", "i18n", "t", "shouldUnescape"];
|
|
6
|
-
|
|
7
|
-
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; }
|
|
8
|
-
|
|
9
|
-
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) { _defineProperty(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; }
|
|
10
|
-
|
|
11
1
|
import { isValidElement, cloneElement, createElement } from 'react';
|
|
12
2
|
import HTML from 'html-parse-stringify';
|
|
13
3
|
import { warn, warnOnce } from './utils.js';
|
|
14
4
|
import { getDefaults } from './defaults.js';
|
|
15
5
|
import { getI18n } from './i18nInstance.js';
|
|
16
|
-
|
|
17
6
|
function hasChildren(node, checkLength) {
|
|
18
7
|
if (!node) return false;
|
|
19
|
-
|
|
8
|
+
const base = node.props ? node.props.children : node.children;
|
|
20
9
|
if (checkLength) return base.length > 0;
|
|
21
10
|
return !!base;
|
|
22
11
|
}
|
|
23
|
-
|
|
24
12
|
function getChildren(node) {
|
|
25
13
|
if (!node) return [];
|
|
26
14
|
return node.props ? node.props.children : node.children;
|
|
27
15
|
}
|
|
28
|
-
|
|
29
16
|
function hasValidReactChildren(children) {
|
|
30
17
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
31
|
-
return children.every(
|
|
32
|
-
return isValidElement(child);
|
|
33
|
-
});
|
|
18
|
+
return children.every(child => isValidElement(child));
|
|
34
19
|
}
|
|
35
|
-
|
|
36
20
|
function getAsArray(data) {
|
|
37
21
|
return Array.isArray(data) ? data : [data];
|
|
38
22
|
}
|
|
39
|
-
|
|
40
23
|
function mergeProps(source, target) {
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
const newTarget = {
|
|
25
|
+
...target
|
|
26
|
+
};
|
|
43
27
|
newTarget.props = Object.assign(source.props, target.props);
|
|
44
28
|
return newTarget;
|
|
45
29
|
}
|
|
46
|
-
|
|
47
30
|
export function nodesToString(children, i18nOptions) {
|
|
48
31
|
if (!children) return '';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
childrenArray.forEach(
|
|
32
|
+
let stringNode = '';
|
|
33
|
+
const childrenArray = getAsArray(children);
|
|
34
|
+
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
35
|
+
childrenArray.forEach((child, childIndex) => {
|
|
53
36
|
if (typeof child === 'string') {
|
|
54
|
-
stringNode +=
|
|
37
|
+
stringNode += `${child}`;
|
|
55
38
|
} else if (isValidElement(child)) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
const childPropsCount = Object.keys(child.props).length;
|
|
40
|
+
const shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
41
|
+
const childChildren = child.props.children;
|
|
60
42
|
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
61
|
-
stringNode +=
|
|
43
|
+
stringNode += `<${child.type}/>`;
|
|
62
44
|
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
63
|
-
stringNode +=
|
|
45
|
+
stringNode += `<${childIndex}></${childIndex}>`;
|
|
64
46
|
} else if (child.props.i18nIsDynamicList) {
|
|
65
|
-
stringNode +=
|
|
47
|
+
stringNode += `<${childIndex}></${childIndex}>`;
|
|
66
48
|
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
67
|
-
stringNode +=
|
|
49
|
+
stringNode += `<${child.type}>${childChildren}</${child.type}>`;
|
|
68
50
|
} else {
|
|
69
|
-
|
|
70
|
-
stringNode +=
|
|
51
|
+
const content = nodesToString(childChildren, i18nOptions);
|
|
52
|
+
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
71
53
|
}
|
|
72
54
|
} else if (child === null) {
|
|
73
|
-
warn(
|
|
74
|
-
} else if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
55
|
+
warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
|
|
56
|
+
} else if (typeof child === 'object') {
|
|
57
|
+
const {
|
|
58
|
+
format,
|
|
59
|
+
...clone
|
|
60
|
+
} = child;
|
|
61
|
+
const keys = Object.keys(clone);
|
|
80
62
|
if (keys.length === 1) {
|
|
81
|
-
|
|
82
|
-
stringNode +=
|
|
63
|
+
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
64
|
+
stringNode += `{{${value}}}`;
|
|
83
65
|
} else {
|
|
84
|
-
warn(
|
|
66
|
+
warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
|
|
85
67
|
}
|
|
86
68
|
} else {
|
|
87
|
-
warn(
|
|
69
|
+
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);
|
|
88
70
|
}
|
|
89
71
|
});
|
|
90
72
|
return stringNode;
|
|
91
73
|
}
|
|
92
|
-
|
|
93
74
|
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
|
|
94
75
|
if (targetString === '') return [];
|
|
95
|
-
|
|
96
|
-
|
|
76
|
+
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
77
|
+
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
97
78
|
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
98
|
-
|
|
99
|
-
|
|
79
|
+
const data = {};
|
|
100
80
|
function getData(childs) {
|
|
101
|
-
|
|
102
|
-
childrenArray.forEach(
|
|
81
|
+
const childrenArray = getAsArray(childs);
|
|
82
|
+
childrenArray.forEach(child => {
|
|
103
83
|
if (typeof child === 'string') return;
|
|
104
|
-
if (hasChildren(child)) getData(getChildren(child));else if (
|
|
84
|
+
if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !isValidElement(child)) Object.assign(data, child);
|
|
105
85
|
});
|
|
106
86
|
}
|
|
107
|
-
|
|
108
87
|
getData(children);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
88
|
+
const ast = HTML.parse(`<0>${targetString}</0>`);
|
|
89
|
+
const opts = {
|
|
90
|
+
...data,
|
|
91
|
+
...combinedTOpts
|
|
92
|
+
};
|
|
113
93
|
function renderInner(child, node, rootReactNode) {
|
|
114
|
-
|
|
115
|
-
|
|
94
|
+
const childs = getChildren(child);
|
|
95
|
+
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
116
96
|
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
117
97
|
}
|
|
118
|
-
|
|
119
98
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
120
99
|
if (child.dummy) child.children = inner;
|
|
121
|
-
mem.push(cloneElement(child,
|
|
100
|
+
mem.push(cloneElement(child, {
|
|
101
|
+
...child.props,
|
|
122
102
|
key: i
|
|
123
|
-
}
|
|
103
|
+
}, isVoid ? undefined : inner));
|
|
124
104
|
}
|
|
125
|
-
|
|
126
105
|
function mapAST(reactNode, astNode, rootReactNode) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return astNodes.reduce(
|
|
130
|
-
|
|
131
|
-
|
|
106
|
+
const reactNodes = getAsArray(reactNode);
|
|
107
|
+
const astNodes = getAsArray(astNode);
|
|
108
|
+
return astNodes.reduce((mem, node, i) => {
|
|
109
|
+
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
132
110
|
if (node.type === 'tag') {
|
|
133
|
-
|
|
111
|
+
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
134
112
|
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
135
113
|
if (!tmp) tmp = {};
|
|
136
|
-
|
|
114
|
+
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
137
115
|
props: node.attrs
|
|
138
116
|
}, tmp) : tmp;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
117
|
+
const isElement = isValidElement(child);
|
|
118
|
+
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
119
|
+
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
|
|
120
|
+
const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
144
121
|
if (typeof child === 'string') {
|
|
145
|
-
|
|
122
|
+
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
146
123
|
mem.push(value);
|
|
147
124
|
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
125
|
+
const inner = renderInner(child, node, rootReactNode);
|
|
126
|
+
pushTranslatedJSX(child, inner, mem, i);
|
|
127
|
+
} else if (isEmptyTransWithHTML) {
|
|
128
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
129
|
+
mem.push(cloneElement(child, {
|
|
130
|
+
...child.props,
|
|
154
131
|
key: i
|
|
155
|
-
}
|
|
132
|
+
}, inner));
|
|
156
133
|
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
157
134
|
if (isKnownComponent) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
pushTranslatedJSX(child, _inner2, mem, i, node.voidElement);
|
|
135
|
+
const inner = renderInner(child, node, rootReactNode);
|
|
136
|
+
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
161
137
|
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
162
138
|
if (node.voidElement) {
|
|
163
139
|
mem.push(createElement(node.name, {
|
|
164
|
-
key:
|
|
140
|
+
key: `${node.name}-${i}`
|
|
165
141
|
}));
|
|
166
142
|
} else {
|
|
167
|
-
|
|
168
|
-
|
|
143
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
169
144
|
mem.push(createElement(node.name, {
|
|
170
|
-
key:
|
|
171
|
-
},
|
|
145
|
+
key: `${node.name}-${i}`
|
|
146
|
+
}, inner));
|
|
172
147
|
}
|
|
173
148
|
} else if (node.voidElement) {
|
|
174
|
-
mem.push(
|
|
149
|
+
mem.push(`<${node.name} />`);
|
|
175
150
|
} else {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
mem.push("<".concat(node.name, ">").concat(_inner4, "</").concat(node.name, ">"));
|
|
151
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
152
|
+
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
179
153
|
}
|
|
180
|
-
} else if (
|
|
181
|
-
|
|
154
|
+
} else if (typeof child === 'object' && !isElement) {
|
|
155
|
+
const content = node.children[0] ? translationContent : null;
|
|
182
156
|
if (content) mem.push(content);
|
|
183
157
|
} else if (node.children.length === 1 && translationContent) {
|
|
184
|
-
mem.push(cloneElement(child,
|
|
158
|
+
mem.push(cloneElement(child, {
|
|
159
|
+
...child.props,
|
|
185
160
|
key: i
|
|
186
|
-
}
|
|
161
|
+
}, translationContent));
|
|
187
162
|
} else {
|
|
188
|
-
mem.push(cloneElement(child,
|
|
163
|
+
mem.push(cloneElement(child, {
|
|
164
|
+
...child.props,
|
|
189
165
|
key: i
|
|
190
|
-
}))
|
|
166
|
+
}));
|
|
191
167
|
}
|
|
192
168
|
} else if (node.type === 'text') {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
var _content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
196
|
-
|
|
169
|
+
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
170
|
+
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
197
171
|
if (wrapTextNodes) {
|
|
198
172
|
mem.push(createElement(wrapTextNodes, {
|
|
199
|
-
key:
|
|
200
|
-
},
|
|
173
|
+
key: `${node.name}-${i}`
|
|
174
|
+
}, content));
|
|
201
175
|
} else {
|
|
202
|
-
mem.push(
|
|
176
|
+
mem.push(content);
|
|
203
177
|
}
|
|
204
178
|
}
|
|
205
|
-
|
|
206
179
|
return mem;
|
|
207
180
|
}, []);
|
|
208
181
|
}
|
|
209
|
-
|
|
210
|
-
var result = mapAST([{
|
|
182
|
+
const result = mapAST([{
|
|
211
183
|
dummy: true,
|
|
212
184
|
children: children || []
|
|
213
185
|
}], ast, getAsArray(children || []));
|
|
214
186
|
return getChildren(result[0]);
|
|
215
187
|
}
|
|
216
|
-
|
|
217
188
|
export function Trans(_ref) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
189
|
+
let {
|
|
190
|
+
children,
|
|
191
|
+
count,
|
|
192
|
+
parent,
|
|
193
|
+
i18nKey,
|
|
194
|
+
context,
|
|
195
|
+
tOptions = {},
|
|
196
|
+
values,
|
|
197
|
+
defaults,
|
|
198
|
+
components,
|
|
199
|
+
ns,
|
|
200
|
+
i18n: i18nFromProps,
|
|
201
|
+
t: tFromProps,
|
|
202
|
+
shouldUnescape,
|
|
203
|
+
...additionalProps
|
|
204
|
+
} = _ref;
|
|
205
|
+
const i18n = i18nFromProps || getI18n();
|
|
236
206
|
if (!i18n) {
|
|
237
207
|
warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
|
|
238
208
|
return children;
|
|
239
209
|
}
|
|
240
|
-
|
|
241
|
-
var t = tFromProps || i18n.t.bind(i18n) || function (k) {
|
|
242
|
-
return k;
|
|
243
|
-
};
|
|
244
|
-
|
|
210
|
+
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
|
|
245
211
|
if (context) tOptions.context = context;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
212
|
+
const reactI18nextOptions = {
|
|
213
|
+
...getDefaults(),
|
|
214
|
+
...(i18n.options && i18n.options.react)
|
|
215
|
+
};
|
|
216
|
+
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
|
|
250
217
|
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
218
|
+
const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
219
|
+
const {
|
|
220
|
+
hashTransKey
|
|
221
|
+
} = reactI18nextOptions;
|
|
222
|
+
const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
223
|
+
const interpolationOverride = values ? tOptions.interpolation : {
|
|
224
|
+
interpolation: {
|
|
225
|
+
...tOptions.interpolation,
|
|
256
226
|
prefix: '#$?',
|
|
257
227
|
suffix: '?$#'
|
|
258
|
-
}
|
|
228
|
+
}
|
|
259
229
|
};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
count
|
|
263
|
-
|
|
264
|
-
|
|
230
|
+
const combinedTOpts = {
|
|
231
|
+
...tOptions,
|
|
232
|
+
count,
|
|
233
|
+
...values,
|
|
234
|
+
...interpolationOverride,
|
|
235
|
+
defaultValue,
|
|
265
236
|
ns: namespaces
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
237
|
+
};
|
|
238
|
+
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
239
|
+
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
240
|
+
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
271
241
|
return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
|
|
272
242
|
}
|
package/dist/es/Translation.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["ns", "children"];
|
|
4
1
|
import { useTranslation } from './useTranslation.js';
|
|
5
2
|
export function Translation(props) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
t = _useTranslation2[0],
|
|
13
|
-
i18n = _useTranslation2[1],
|
|
14
|
-
ready = _useTranslation2[2];
|
|
15
|
-
|
|
3
|
+
const {
|
|
4
|
+
ns,
|
|
5
|
+
children,
|
|
6
|
+
...options
|
|
7
|
+
} = props;
|
|
8
|
+
const [t, i18n, ready] = useTranslation(ns, options);
|
|
16
9
|
return children(t, {
|
|
17
|
-
i18n
|
|
10
|
+
i18n,
|
|
18
11
|
lng: i18n.language
|
|
19
12
|
}, ready);
|
|
20
13
|
}
|
package/dist/es/context.js
CHANGED
|
@@ -1,65 +1,45 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
|
|
5
|
-
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; }
|
|
6
|
-
|
|
7
|
-
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) { _defineProperty(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; }
|
|
8
|
-
|
|
9
1
|
import { createContext } from 'react';
|
|
10
2
|
import { getDefaults, setDefaults } from './defaults.js';
|
|
11
3
|
import { getI18n, setI18n } from './i18nInstance.js';
|
|
12
4
|
import { initReactI18next } from './initReactI18next.js';
|
|
13
5
|
export { getDefaults, setDefaults, getI18n, setI18n, initReactI18next };
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
_classCallCheck(this, ReportNamespaces);
|
|
18
|
-
|
|
6
|
+
export const I18nContext = createContext();
|
|
7
|
+
export class ReportNamespaces {
|
|
8
|
+
constructor() {
|
|
19
9
|
this.usedNamespaces = {};
|
|
20
10
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}, {
|
|
32
|
-
key: "getUsedNamespaces",
|
|
33
|
-
value: function getUsedNamespaces() {
|
|
34
|
-
return Object.keys(this.usedNamespaces);
|
|
35
|
-
}
|
|
36
|
-
}]);
|
|
37
|
-
|
|
38
|
-
return ReportNamespaces;
|
|
39
|
-
}();
|
|
11
|
+
addUsedNamespaces(namespaces) {
|
|
12
|
+
namespaces.forEach(ns => {
|
|
13
|
+
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
getUsedNamespaces() {
|
|
17
|
+
return Object.keys(this.usedNamespaces);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
40
20
|
export function composeInitialProps(ForComponent) {
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
return ctx => new Promise(resolve => {
|
|
22
|
+
const i18nInitialProps = getInitialProps();
|
|
23
|
+
if (ForComponent.getInitialProps) {
|
|
24
|
+
ForComponent.getInitialProps(ctx).then(componentsInitialProps => {
|
|
25
|
+
resolve({
|
|
26
|
+
...componentsInitialProps,
|
|
27
|
+
...i18nInitialProps
|
|
48
28
|
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
};
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
resolve(i18nInitialProps);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
54
34
|
}
|
|
55
35
|
export function getInitialProps() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
i18n.languages.forEach(
|
|
36
|
+
const i18n = getI18n();
|
|
37
|
+
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
|
|
38
|
+
const ret = {};
|
|
39
|
+
const initialI18nStore = {};
|
|
40
|
+
i18n.languages.forEach(l => {
|
|
61
41
|
initialI18nStore[l] = {};
|
|
62
|
-
namespaces.forEach(
|
|
42
|
+
namespaces.forEach(ns => {
|
|
63
43
|
initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
|
|
64
44
|
});
|
|
65
45
|
});
|
package/dist/es/defaults.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
|
-
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; }
|
|
4
|
-
|
|
5
|
-
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) { _defineProperty(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; }
|
|
6
|
-
|
|
7
1
|
import { unescape } from './unescape.js';
|
|
8
|
-
|
|
2
|
+
let defaultOptions = {
|
|
9
3
|
bindI18n: 'languageChanged',
|
|
10
4
|
bindI18nStore: '',
|
|
11
5
|
transEmptyNodeValue: '',
|
|
@@ -13,11 +7,14 @@ var defaultOptions = {
|
|
|
13
7
|
transWrapTextNodes: '',
|
|
14
8
|
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
15
9
|
useSuspense: true,
|
|
16
|
-
unescape
|
|
10
|
+
unescape
|
|
17
11
|
};
|
|
18
12
|
export function setDefaults() {
|
|
19
|
-
|
|
20
|
-
defaultOptions =
|
|
13
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
14
|
+
defaultOptions = {
|
|
15
|
+
...defaultOptions,
|
|
16
|
+
...options
|
|
17
|
+
};
|
|
21
18
|
}
|
|
22
19
|
export function getDefaults() {
|
|
23
20
|
return defaultOptions;
|
package/dist/es/i18nInstance.js
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -10,21 +10,9 @@ export { initReactI18next } from './initReactI18next.js';
|
|
|
10
10
|
export { setDefaults, getDefaults } from './defaults.js';
|
|
11
11
|
export { setI18n, getI18n } from './i18nInstance.js';
|
|
12
12
|
export { I18nContext, composeInitialProps, getInitialProps } from './context.js';
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export var number = function number() {
|
|
20
|
-
return '';
|
|
21
|
-
};
|
|
22
|
-
export var select = function select() {
|
|
23
|
-
return '';
|
|
24
|
-
};
|
|
25
|
-
export var plural = function plural() {
|
|
26
|
-
return '';
|
|
27
|
-
};
|
|
28
|
-
export var selectOrdinal = function selectOrdinal() {
|
|
29
|
-
return '';
|
|
30
|
-
};
|
|
13
|
+
export const date = () => '';
|
|
14
|
+
export const time = () => '';
|
|
15
|
+
export const number = () => '';
|
|
16
|
+
export const select = () => '';
|
|
17
|
+
export const plural = () => '';
|
|
18
|
+
export const selectOrdinal = () => '';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { setDefaults } from './defaults.js';
|
|
2
2
|
import { setI18n } from './i18nInstance.js';
|
|
3
|
-
export
|
|
3
|
+
export const initReactI18next = {
|
|
4
4
|
type: '3rdParty',
|
|
5
|
-
init
|
|
5
|
+
init(instance) {
|
|
6
6
|
setDefaults(instance.options.react);
|
|
7
7
|
setI18n(instance);
|
|
8
8
|
}
|
package/dist/es/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"
|
|
1
|
+
{"type":"module","version":"13.0.0"}
|
package/dist/es/unescape.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
2
|
+
const htmlEntities = {
|
|
3
3
|
'&': '&',
|
|
4
4
|
'&': '&',
|
|
5
5
|
'<': '<',
|
|
@@ -21,11 +21,5 @@ var htmlEntities = {
|
|
|
21
21
|
'/': '/',
|
|
22
22
|
'/': '/'
|
|
23
23
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return htmlEntities[m];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export var unescape = function unescape(text) {
|
|
30
|
-
return text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
31
|
-
};
|
|
24
|
+
const unescapeHtmlEntity = m => htmlEntities[m];
|
|
25
|
+
export const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|