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.
Files changed (44) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/TransWithoutContext.d.ts +26 -16
  3. package/dist/amd/react-i18next.js +827 -1130
  4. package/dist/amd/react-i18next.min.js +1 -1
  5. package/dist/commonjs/I18nextProvider.js +10 -13
  6. package/dist/commonjs/Trans.js +37 -52
  7. package/dist/commonjs/TransWithoutContext.js +130 -168
  8. package/dist/commonjs/Translation.js +8 -22
  9. package/dist/commonjs/context.js +45 -76
  10. package/dist/commonjs/defaults.js +7 -16
  11. package/dist/commonjs/i18nInstance.js +2 -4
  12. package/dist/commonjs/index.js +52 -86
  13. package/dist/commonjs/initReactI18next.js +2 -5
  14. package/dist/commonjs/unescape.js +4 -11
  15. package/dist/commonjs/useSSR.js +10 -14
  16. package/dist/commonjs/useTranslation.js +47 -82
  17. package/dist/commonjs/utils.js +29 -52
  18. package/dist/commonjs/withSSR.js +9 -23
  19. package/dist/commonjs/withTranslation.js +18 -45
  20. package/dist/es/I18nextProvider.js +10 -10
  21. package/dist/es/Trans.js +36 -43
  22. package/dist/es/TransWithoutContext.js +129 -159
  23. package/dist/es/Translation.js +7 -14
  24. package/dist/es/context.js +30 -50
  25. package/dist/es/defaults.js +7 -10
  26. package/dist/es/i18nInstance.js +1 -1
  27. package/dist/es/index.js +6 -18
  28. package/dist/es/initReactI18next.js +2 -2
  29. package/dist/es/package.json +1 -1
  30. package/dist/es/unescape.js +4 -10
  31. package/dist/es/useSSR.js +10 -11
  32. package/dist/es/useTranslation.js +47 -75
  33. package/dist/es/utils.js +25 -43
  34. package/dist/es/withSSR.js +9 -15
  35. package/dist/es/withTranslation.js +17 -35
  36. package/dist/umd/react-i18next.js +828 -1131
  37. package/dist/umd/react-i18next.min.js +1 -1
  38. package/helpers.d.ts +3 -0
  39. package/icu.macro.d.ts +37 -39
  40. package/index.d.ts +44 -37
  41. package/initReactI18next.d.ts +1 -1
  42. package/package.json +36 -36
  43. package/react-i18next.js +828 -1131
  44. 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
- var base = node.props ? node.props.children : node.children;
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(function (child) {
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
- var newTarget = _objectSpread({}, target);
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
- var stringNode = '';
50
- var childrenArray = getAsArray(children);
51
- var keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
52
- childrenArray.forEach(function (child, childIndex) {
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 += "".concat(child);
37
+ stringNode += `${child}`;
55
38
  } else if (isValidElement(child)) {
56
- var childPropsCount = Object.keys(child.props).length;
57
- var shouldKeepChild = keepArray.indexOf(child.type) > -1;
58
- var childChildren = child.props.children;
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 += "<".concat(child.type, "/>");
43
+ stringNode += `<${child.type}/>`;
62
44
  } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
63
- stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
45
+ stringNode += `<${childIndex}></${childIndex}>`;
64
46
  } else if (child.props.i18nIsDynamicList) {
65
- stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
47
+ stringNode += `<${childIndex}></${childIndex}>`;
66
48
  } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
67
- stringNode += "<".concat(child.type, ">").concat(childChildren, "</").concat(child.type, ">");
49
+ stringNode += `<${child.type}>${childChildren}</${child.type}>`;
68
50
  } else {
69
- var content = nodesToString(childChildren, i18nOptions);
70
- stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
51
+ const content = nodesToString(childChildren, i18nOptions);
52
+ stringNode += `<${childIndex}>${content}</${childIndex}>`;
71
53
  }
72
54
  } else if (child === null) {
73
- warn("Trans: the passed in value is invalid - seems you passed in a null child.");
74
- } else if (_typeof(child) === 'object') {
75
- var format = child.format,
76
- clone = _objectWithoutProperties(child, _excluded);
77
-
78
- var keys = Object.keys(clone);
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
- var value = format ? "".concat(keys[0], ", ").concat(format) : keys[0];
82
- stringNode += "{{".concat(value, "}}");
63
+ const value = format ? `${keys[0]}, ${format}` : keys[0];
64
+ stringNode += `{{${value}}}`;
83
65
  } else {
84
- warn("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.", child);
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("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);
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
- var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
96
- var emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
76
+ const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
77
+ const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
97
78
  if (!children && !emptyChildrenButNeedsHandling) return [targetString];
98
- var data = {};
99
-
79
+ const data = {};
100
80
  function getData(childs) {
101
- var childrenArray = getAsArray(childs);
102
- childrenArray.forEach(function (child) {
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 (_typeof(child) === 'object' && !isValidElement(child)) Object.assign(data, child);
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
- var ast = HTML.parse("<0>".concat(targetString, "</0>"));
110
-
111
- var opts = _objectSpread(_objectSpread({}, data), combinedTOpts);
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
- var childs = getChildren(child);
115
- var mappedChildren = mapAST(childs, node.children, rootReactNode);
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, _objectSpread(_objectSpread({}, child.props), {}, {
100
+ mem.push(cloneElement(child, {
101
+ ...child.props,
122
102
  key: i
123
- }), isVoid ? undefined : inner));
103
+ }, isVoid ? undefined : inner));
124
104
  }
125
-
126
105
  function mapAST(reactNode, astNode, rootReactNode) {
127
- var reactNodes = getAsArray(reactNode);
128
- var astNodes = getAsArray(astNode);
129
- return astNodes.reduce(function (mem, node, i) {
130
- var translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
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
- var tmp = reactNodes[parseInt(node.name, 10)];
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
- var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
114
+ const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
137
115
  props: node.attrs
138
116
  }, tmp) : tmp;
139
- var isElement = isValidElement(child);
140
- var isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
141
- var isEmptyTransWithHTML = emptyChildrenButNeedsHandling && _typeof(child) === 'object' && child.dummy && !isElement;
142
- var isKnownComponent = _typeof(children) === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
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
- var value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
122
+ const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
146
123
  mem.push(value);
147
124
  } else if (hasChildren(child) || isValidTranslationWithChildren) {
148
- var inner = renderInner(child, node, rootReactNode);
149
- pushTranslatedJSX(child, inner, mem, i);
150
- } else if (isEmptyTransWithHTML) {
151
- var _inner = mapAST(reactNodes, node.children, rootReactNode);
152
-
153
- mem.push(cloneElement(child, _objectSpread(_objectSpread({}, child.props), {}, {
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
- }), _inner));
132
+ }, inner));
156
133
  } else if (Number.isNaN(parseFloat(node.name))) {
157
134
  if (isKnownComponent) {
158
- var _inner2 = renderInner(child, node, rootReactNode);
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: "".concat(node.name, "-").concat(i)
140
+ key: `${node.name}-${i}`
165
141
  }));
166
142
  } else {
167
- var _inner3 = mapAST(reactNodes, node.children, rootReactNode);
168
-
143
+ const inner = mapAST(reactNodes, node.children, rootReactNode);
169
144
  mem.push(createElement(node.name, {
170
- key: "".concat(node.name, "-").concat(i)
171
- }, _inner3));
145
+ key: `${node.name}-${i}`
146
+ }, inner));
172
147
  }
173
148
  } else if (node.voidElement) {
174
- mem.push("<".concat(node.name, " />"));
149
+ mem.push(`<${node.name} />`);
175
150
  } else {
176
- var _inner4 = mapAST(reactNodes, node.children, rootReactNode);
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 (_typeof(child) === 'object' && !isElement) {
181
- var content = node.children[0] ? translationContent : null;
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, _objectSpread(_objectSpread({}, child.props), {}, {
158
+ mem.push(cloneElement(child, {
159
+ ...child.props,
185
160
  key: i
186
- }), translationContent));
161
+ }, translationContent));
187
162
  } else {
188
- mem.push(cloneElement(child, _objectSpread(_objectSpread({}, child.props), {}, {
163
+ mem.push(cloneElement(child, {
164
+ ...child.props,
189
165
  key: i
190
- })));
166
+ }));
191
167
  }
192
168
  } else if (node.type === 'text') {
193
- var wrapTextNodes = i18nOptions.transWrapTextNodes;
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: "".concat(node.name, "-").concat(i)
200
- }, _content));
173
+ key: `${node.name}-${i}`
174
+ }, content));
201
175
  } else {
202
- mem.push(_content);
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
- var children = _ref.children,
219
- count = _ref.count,
220
- parent = _ref.parent,
221
- i18nKey = _ref.i18nKey,
222
- context = _ref.context,
223
- _ref$tOptions = _ref.tOptions,
224
- tOptions = _ref$tOptions === void 0 ? {} : _ref$tOptions,
225
- values = _ref.values,
226
- defaults = _ref.defaults,
227
- components = _ref.components,
228
- ns = _ref.ns,
229
- i18nFromProps = _ref.i18n,
230
- tFromProps = _ref.t,
231
- shouldUnescape = _ref.shouldUnescape,
232
- additionalProps = _objectWithoutProperties(_ref, _excluded2);
233
-
234
- var i18n = i18nFromProps || getI18n();
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
- var reactI18nextOptions = _objectSpread(_objectSpread({}, getDefaults()), i18n.options && i18n.options.react);
248
-
249
- var namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
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
- var defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
252
- var hashTransKey = reactI18nextOptions.hashTransKey;
253
- var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
254
- var interpolationOverride = values ? tOptions.interpolation : {
255
- interpolation: _objectSpread(_objectSpread({}, tOptions.interpolation), {}, {
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
- var combinedTOpts = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, tOptions), {}, {
262
- count: count
263
- }, values), interpolationOverride), {}, {
264
- defaultValue: defaultValue,
230
+ const combinedTOpts = {
231
+ ...tOptions,
232
+ count,
233
+ ...values,
234
+ ...interpolationOverride,
235
+ defaultValue,
265
236
  ns: namespaces
266
- });
267
-
268
- var translation = key ? t(key, combinedTOpts) : defaultValue;
269
- var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
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
  }
@@ -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
- var ns = props.ns,
7
- children = props.children,
8
- options = _objectWithoutProperties(props, _excluded);
9
-
10
- var _useTranslation = useTranslation(ns, options),
11
- _useTranslation2 = _slicedToArray(_useTranslation, 3),
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: i18n,
10
+ i18n,
18
11
  lng: i18n.language
19
12
  }, ready);
20
13
  }
@@ -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 var I18nContext = createContext();
15
- export var ReportNamespaces = function () {
16
- function ReportNamespaces() {
17
- _classCallCheck(this, ReportNamespaces);
18
-
6
+ export const I18nContext = createContext();
7
+ export class ReportNamespaces {
8
+ constructor() {
19
9
  this.usedNamespaces = {};
20
10
  }
21
-
22
- _createClass(ReportNamespaces, [{
23
- key: "addUsedNamespaces",
24
- value: function addUsedNamespaces(namespaces) {
25
- var _this = this;
26
-
27
- namespaces.forEach(function (ns) {
28
- if (!_this.usedNamespaces[ns]) _this.usedNamespaces[ns] = true;
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 function (ctx) {
42
- return new Promise(function (resolve) {
43
- var i18nInitialProps = getInitialProps();
44
-
45
- if (ForComponent.getInitialProps) {
46
- ForComponent.getInitialProps(ctx).then(function (componentsInitialProps) {
47
- resolve(_objectSpread(_objectSpread({}, componentsInitialProps), i18nInitialProps));
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
- } else {
50
- resolve(i18nInitialProps);
51
- }
52
- });
53
- };
29
+ });
30
+ } else {
31
+ resolve(i18nInitialProps);
32
+ }
33
+ });
54
34
  }
55
35
  export function getInitialProps() {
56
- var i18n = getI18n();
57
- var namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
58
- var ret = {};
59
- var initialI18nStore = {};
60
- i18n.languages.forEach(function (l) {
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(function (ns) {
42
+ namespaces.forEach(ns => {
63
43
  initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
64
44
  });
65
45
  });
@@ -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
- var defaultOptions = {
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: unescape
10
+ unescape
17
11
  };
18
12
  export function setDefaults() {
19
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20
- defaultOptions = _objectSpread(_objectSpread({}, defaultOptions), options);
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;
@@ -1,4 +1,4 @@
1
- var i18nInstance;
1
+ let i18nInstance;
2
2
  export function setI18n(instance) {
3
3
  i18nInstance = instance;
4
4
  }
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 var date = function date() {
14
- return '';
15
- };
16
- export var time = function time() {
17
- return '';
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 var initReactI18next = {
3
+ export const initReactI18next = {
4
4
  type: '3rdParty',
5
- init: function init(instance) {
5
+ init(instance) {
6
6
  setDefaults(instance.options.react);
7
7
  setI18n(instance);
8
8
  }
@@ -1 +1 @@
1
- {"type":"module","version":"12.3.1"}
1
+ {"type":"module","version":"13.0.0"}
@@ -1,5 +1,5 @@
1
- var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
2
- var htmlEntities = {
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
  '&amp;': '&',
4
4
  '&#38;': '&',
5
5
  '&lt;': '<',
@@ -21,11 +21,5 @@ var htmlEntities = {
21
21
  '&#x2F;': '/',
22
22
  '&#47;': '/'
23
23
  };
24
-
25
- var unescapeHtmlEntity = function unescapeHtmlEntity(m) {
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);