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.
Files changed (47) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +1 -1
  3. package/TransWithoutContext.d.ts +26 -16
  4. package/dist/amd/react-i18next.js +827 -1104
  5. package/dist/amd/react-i18next.min.js +1 -1
  6. package/dist/commonjs/I18nextProvider.js +10 -13
  7. package/dist/commonjs/Trans.js +37 -52
  8. package/dist/commonjs/TransWithoutContext.js +130 -168
  9. package/dist/commonjs/Translation.js +8 -22
  10. package/dist/commonjs/context.js +45 -76
  11. package/dist/commonjs/defaults.js +7 -16
  12. package/dist/commonjs/i18nInstance.js +2 -4
  13. package/dist/commonjs/index.js +52 -86
  14. package/dist/commonjs/initReactI18next.js +2 -5
  15. package/dist/commonjs/unescape.js +4 -11
  16. package/dist/commonjs/useSSR.js +10 -14
  17. package/dist/commonjs/useTranslation.js +57 -79
  18. package/dist/commonjs/utils.js +38 -47
  19. package/dist/commonjs/withSSR.js +9 -23
  20. package/dist/commonjs/withTranslation.js +18 -45
  21. package/dist/es/I18nextProvider.js +10 -10
  22. package/dist/es/Trans.js +36 -43
  23. package/dist/es/TransWithoutContext.js +129 -159
  24. package/dist/es/Translation.js +7 -14
  25. package/dist/es/context.js +30 -50
  26. package/dist/es/defaults.js +7 -10
  27. package/dist/es/i18nInstance.js +1 -1
  28. package/dist/es/index.js +6 -18
  29. package/dist/es/initReactI18next.js +2 -2
  30. package/dist/es/package.json +1 -1
  31. package/dist/es/unescape.js +4 -10
  32. package/dist/es/useSSR.js +10 -11
  33. package/dist/es/useTranslation.js +58 -73
  34. package/dist/es/utils.js +34 -39
  35. package/dist/es/withSSR.js +9 -15
  36. package/dist/es/withTranslation.js +17 -35
  37. package/dist/umd/react-i18next.js +828 -1105
  38. package/dist/umd/react-i18next.min.js +1 -1
  39. package/helpers.d.ts +3 -0
  40. package/icu.macro.d.ts +37 -39
  41. package/index.d.ts +44 -37
  42. package/initReactI18next.d.ts +1 -1
  43. package/package.json +36 -36
  44. package/react-i18next.js +828 -1105
  45. package/react-i18next.min.js +1 -1
  46. package/src/useTranslation.js +17 -8
  47. 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
- var base = node.props ? node.props.children : node.children;
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(function (child) {
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
- var newTarget = _objectSpread({}, target);
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
- var stringNode = '';
67
- var childrenArray = getAsArray(children);
68
- var keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
69
- childrenArray.forEach(function (child, childIndex) {
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 += "".concat(child);
45
+ stringNode += `${child}`;
72
46
  } else if ((0, _react.isValidElement)(child)) {
73
- var childPropsCount = Object.keys(child.props).length;
74
- var shouldKeepChild = keepArray.indexOf(child.type) > -1;
75
- var childChildren = child.props.children;
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 += "<".concat(child.type, "/>");
51
+ stringNode += `<${child.type}/>`;
79
52
  } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
80
- stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
53
+ stringNode += `<${childIndex}></${childIndex}>`;
81
54
  } else if (child.props.i18nIsDynamicList) {
82
- stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
55
+ stringNode += `<${childIndex}></${childIndex}>`;
83
56
  } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
84
- stringNode += "<".concat(child.type, ">").concat(childChildren, "</").concat(child.type, ">");
57
+ stringNode += `<${child.type}>${childChildren}</${child.type}>`;
85
58
  } else {
86
- var content = nodesToString(childChildren, i18nOptions);
87
- stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
59
+ const content = nodesToString(childChildren, i18nOptions);
60
+ stringNode += `<${childIndex}>${content}</${childIndex}>`;
88
61
  }
89
62
  } else if (child === null) {
90
- (0, _utils.warn)("Trans: the passed in value is invalid - seems you passed in a null child.");
91
- } else if ((0, _typeof2["default"])(child) === 'object') {
92
- var format = child.format,
93
- clone = (0, _objectWithoutProperties2["default"])(child, _excluded);
94
- var keys = Object.keys(clone);
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
- var value = format ? "".concat(keys[0], ", ").concat(format) : keys[0];
98
- stringNode += "{{".concat(value, "}}");
71
+ const value = format ? `${keys[0]}, ${format}` : keys[0];
72
+ stringNode += `{{${value}}}`;
99
73
  } else {
100
- (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);
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)("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);
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
- var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
112
- var emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
84
+ const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
85
+ const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
113
86
  if (!children && !emptyChildrenButNeedsHandling) return [targetString];
114
- var data = {};
115
-
87
+ const data = {};
116
88
  function getData(childs) {
117
- var childrenArray = getAsArray(childs);
118
- childrenArray.forEach(function (child) {
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 ((0, _typeof2["default"])(child) === 'object' && !(0, _react.isValidElement)(child)) Object.assign(data, child);
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
- var ast = _htmlParseStringify["default"].parse("<0>".concat(targetString, "</0>"));
127
-
128
- var opts = _objectSpread(_objectSpread({}, data), combinedTOpts);
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
- var childs = getChildren(child);
132
- var mappedChildren = mapAST(childs, node.children, rootReactNode);
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, _objectSpread(_objectSpread({}, child.props), {}, {
108
+ mem.push((0, _react.cloneElement)(child, {
109
+ ...child.props,
139
110
  key: i
140
- }), isVoid ? undefined : inner));
111
+ }, isVoid ? undefined : inner));
141
112
  }
142
-
143
113
  function mapAST(reactNode, astNode, rootReactNode) {
144
- var reactNodes = getAsArray(reactNode);
145
- var astNodes = getAsArray(astNode);
146
- return astNodes.reduce(function (mem, node, i) {
147
- var translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
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
- var tmp = reactNodes[parseInt(node.name, 10)];
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
- var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
122
+ const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
154
123
  props: node.attrs
155
124
  }, tmp) : tmp;
156
- var isElement = (0, _react.isValidElement)(child);
157
- var isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
158
- var isEmptyTransWithHTML = emptyChildrenButNeedsHandling && (0, _typeof2["default"])(child) === 'object' && child.dummy && !isElement;
159
- var isKnownComponent = (0, _typeof2["default"])(children) === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
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
- var value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
130
+ const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
163
131
  mem.push(value);
164
132
  } else if (hasChildren(child) || isValidTranslationWithChildren) {
165
- var inner = renderInner(child, node, rootReactNode);
166
- pushTranslatedJSX(child, inner, mem, i);
167
- } else if (isEmptyTransWithHTML) {
168
- var _inner = mapAST(reactNodes, node.children, rootReactNode);
169
-
170
- mem.push((0, _react.cloneElement)(child, _objectSpread(_objectSpread({}, child.props), {}, {
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
- }), _inner));
140
+ }, inner));
173
141
  } else if (Number.isNaN(parseFloat(node.name))) {
174
142
  if (isKnownComponent) {
175
- var _inner2 = renderInner(child, node, rootReactNode);
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: "".concat(node.name, "-").concat(i)
148
+ key: `${node.name}-${i}`
182
149
  }));
183
150
  } else {
184
- var _inner3 = mapAST(reactNodes, node.children, rootReactNode);
185
-
151
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
186
152
  mem.push((0, _react.createElement)(node.name, {
187
- key: "".concat(node.name, "-").concat(i)
188
- }, _inner3));
153
+ key: `${node.name}-${i}`
154
+ }, inner));
189
155
  }
190
156
  } else if (node.voidElement) {
191
- mem.push("<".concat(node.name, " />"));
157
+ mem.push(`<${node.name} />`);
192
158
  } else {
193
- var _inner4 = mapAST(reactNodes, node.children, rootReactNode);
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 ((0, _typeof2["default"])(child) === 'object' && !isElement) {
198
- var content = node.children[0] ? translationContent : null;
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, _objectSpread(_objectSpread({}, child.props), {}, {
166
+ mem.push((0, _react.cloneElement)(child, {
167
+ ...child.props,
202
168
  key: i
203
- }), translationContent));
169
+ }, translationContent));
204
170
  } else {
205
- mem.push((0, _react.cloneElement)(child, _objectSpread(_objectSpread({}, child.props), {}, {
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
- var wrapTextNodes = i18nOptions.transWrapTextNodes;
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: "".concat(node.name, "-").concat(i)
217
- }, _content));
181
+ key: `${node.name}-${i}`
182
+ }, content));
218
183
  } else {
219
- mem.push(_content);
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
- var children = _ref.children,
236
- count = _ref.count,
237
- parent = _ref.parent,
238
- i18nKey = _ref.i18nKey,
239
- context = _ref.context,
240
- _ref$tOptions = _ref.tOptions,
241
- tOptions = _ref$tOptions === void 0 ? {} : _ref$tOptions,
242
- values = _ref.values,
243
- defaults = _ref.defaults,
244
- components = _ref.components,
245
- ns = _ref.ns,
246
- i18nFromProps = _ref.i18n,
247
- tFromProps = _ref.t,
248
- shouldUnescape = _ref.shouldUnescape,
249
- additionalProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded2);
250
- var i18n = i18nFromProps || (0, _i18nInstance.getI18n)();
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
- var reactI18nextOptions = _objectSpread(_objectSpread({}, (0, _defaults.getDefaults)()), i18n.options && i18n.options.react);
264
-
265
- var namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
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
- var defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
268
- var hashTransKey = reactI18nextOptions.hashTransKey;
269
- var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
270
- var interpolationOverride = values ? tOptions.interpolation : {
271
- interpolation: _objectSpread(_objectSpread({}, tOptions.interpolation), {}, {
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
- var combinedTOpts = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, tOptions), {}, {
278
- count: count
279
- }, values), interpolationOverride), {}, {
280
- defaultValue: defaultValue,
238
+ const combinedTOpts = {
239
+ ...tOptions,
240
+ count,
241
+ ...values,
242
+ ...interpolationOverride,
243
+ defaultValue,
281
244
  ns: namespaces
282
- });
283
-
284
- var translation = key ? t(key, combinedTOpts) : defaultValue;
285
- var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
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
- var ns = props.ns,
20
- children = props.children,
21
- options = (0, _objectWithoutProperties2["default"])(props, _excluded);
22
-
23
- var _useTranslation = (0, _useTranslation3.useTranslation)(ns, options),
24
- _useTranslation2 = (0, _slicedToArray2["default"])(_useTranslation, 3),
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: i18n,
16
+ i18n,
31
17
  lng: i18n.language
32
18
  }, ready);
33
19
  }
@@ -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 get() {
10
+ get: function () {
13
11
  return _defaults.getDefaults;
14
12
  }
15
13
  });
16
- Object.defineProperty(exports, "setDefaults", {
14
+ Object.defineProperty(exports, "getI18n", {
17
15
  enumerable: true,
18
- get: function get() {
19
- return _defaults.setDefaults;
16
+ get: function () {
17
+ return _i18nInstance.getI18n;
20
18
  }
21
19
  });
22
- Object.defineProperty(exports, "getI18n", {
20
+ exports.getInitialProps = getInitialProps;
21
+ Object.defineProperty(exports, "initReactI18next", {
23
22
  enumerable: true,
24
- get: function get() {
25
- return _i18nInstance.getI18n;
23
+ get: function () {
24
+ return _initReactI18next.initReactI18next;
26
25
  }
27
26
  });
28
- Object.defineProperty(exports, "setI18n", {
27
+ Object.defineProperty(exports, "setDefaults", {
29
28
  enumerable: true,
30
- get: function get() {
31
- return _i18nInstance.setI18n;
29
+ get: function () {
30
+ return _defaults.setDefaults;
32
31
  }
33
32
  });
34
- Object.defineProperty(exports, "initReactI18next", {
33
+ Object.defineProperty(exports, "setI18n", {
35
34
  enumerable: true,
36
- get: function get() {
37
- return _initReactI18next.initReactI18next;
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
- var ReportNamespaces = function () {
64
- function ReportNamespaces() {
65
- (0, _classCallCheck2["default"])(this, ReportNamespaces);
45
+ class ReportNamespaces {
46
+ constructor() {
66
47
  this.usedNamespaces = {};
67
48
  }
68
-
69
- (0, _createClass2["default"])(ReportNamespaces, [{
70
- key: "addUsedNamespaces",
71
- value: function addUsedNamespaces(namespaces) {
72
- var _this = this;
73
-
74
- namespaces.forEach(function (ns) {
75
- if (!_this.usedNamespaces[ns]) _this.usedNamespaces[ns] = true;
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 function (ctx) {
91
- return new Promise(function (resolve) {
92
- var i18nInitialProps = getInitialProps();
93
-
94
- if (ForComponent.getInitialProps) {
95
- ForComponent.getInitialProps(ctx).then(function (componentsInitialProps) {
96
- resolve(_objectSpread(_objectSpread({}, componentsInitialProps), i18nInitialProps));
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
- } else {
99
- resolve(i18nInitialProps);
100
- }
101
- });
102
- };
68
+ });
69
+ } else {
70
+ resolve(i18nInitialProps);
71
+ }
72
+ });
103
73
  }
104
-
105
74
  function getInitialProps() {
106
- var i18n = (0, _i18nInstance.getI18n)();
107
- var namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
108
- var ret = {};
109
- var initialI18nStore = {};
110
- i18n.languages.forEach(function (l) {
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(function (ns) {
81
+ namespaces.forEach(ns => {
113
82
  initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
114
83
  });
115
84
  });