react-i18next 11.4.0 → 11.7.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 +16 -0
- package/README.md +1 -1
- package/dist/amd/react-i18next.js +116 -190
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/I18nextProvider.js +2 -5
- package/dist/commonjs/Trans.js +87 -87
- package/dist/commonjs/context.js +2 -27
- package/dist/commonjs/useSSR.js +4 -8
- package/dist/commonjs/useTranslation.js +13 -26
- package/dist/commonjs/utils.js +6 -23
- package/dist/es/I18nextProvider.js +3 -4
- package/dist/es/Trans.js +86 -88
- package/dist/es/context.js +2 -23
- package/dist/es/useSSR.js +5 -9
- package/dist/es/useTranslation.js +14 -27
- package/dist/es/utils.js +6 -23
- package/dist/umd/react-i18next.js +116 -190
- package/dist/umd/react-i18next.min.js +1 -1
- package/icu.macro.js +3 -1
- package/package.json +1 -2
- package/react-i18next.js +116 -190
- package/react-i18next.min.js +1 -1
- package/rollup.config.js +2 -1
- package/src/I18nextProvider.js +3 -5
- package/src/Trans.js +127 -79
- package/src/context.js +0 -9
- package/src/index.d.ts +1 -1
- package/src/useSSR.js +2 -3
- package/src/useTranslation.js +3 -12
- package/src/utils.js +22 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -16
- package/.github/ISSUE_TEMPLATE/question.md +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
### 11.7.0
|
|
2
|
+
|
|
3
|
+
- Trans interpolating self-closing tags in components prop(object) [1140](https://github.com/i18next/react-i18next/pull/1140)
|
|
4
|
+
|
|
5
|
+
### 11.6.0
|
|
6
|
+
|
|
7
|
+
- Trans allow components props to be an object containing named interpolation elements
|
|
8
|
+
|
|
9
|
+
### 11.5.1
|
|
10
|
+
|
|
11
|
+
- providing filename when running babel.parse in icu.macro [1133](https://github.com/i18next/react-i18next/pull/1133)
|
|
12
|
+
|
|
13
|
+
### 11.5.0
|
|
14
|
+
|
|
15
|
+
- Trans: merge option in mapAST [1120](https://github.com/i18next/react-i18next/pull/1120)
|
|
16
|
+
|
|
1
17
|
### 11.4.0
|
|
2
18
|
|
|
3
19
|
- Add sideEffects false to package json to allow tree shaking [1097](https://github.com/i18next/react-i18next/pull/1097)
|
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ Head over to the **interactive playground** at [codesandbox](https://codesandbox
|
|
|
81
81
|
- **Production ready** we know there are more needs for production than just doing i18n on the clientside, so we offer wider support on [serverside](https://www.i18next.com/supported-frameworks.html) too (nodejs, php, ruby, .net, ...). **Learn once - translate everywhere**.
|
|
82
82
|
- **Beyond i18n** comes with [locize](https://locize.com) bridging the gap between developement and translations - covering the whole translation process.
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+

|
|
85
85
|
|
|
86
86
|
### Localization workflow
|
|
87
87
|
|
|
@@ -165,10 +165,6 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
165
165
|
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
/**
|
|
169
|
-
* This file automatically generated from `pre-publish.js`.
|
|
170
|
-
* Do not manually edit.
|
|
171
|
-
*/
|
|
172
168
|
var voidElements = {
|
|
173
169
|
"area": true,
|
|
174
170
|
"base": true,
|
|
@@ -212,7 +208,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
212
208
|
|
|
213
209
|
if (!expectingValueAfterEquals) {
|
|
214
210
|
if (key) {
|
|
215
|
-
res.attrs[key] = key;
|
|
211
|
+
res.attrs[key] = key;
|
|
216
212
|
}
|
|
217
213
|
|
|
218
214
|
key = match;
|
|
@@ -235,28 +231,19 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
235
231
|
return res;
|
|
236
232
|
};
|
|
237
233
|
|
|
238
|
-
/*jshint -W030 */
|
|
239
234
|
var tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
|
|
240
235
|
|
|
241
|
-
// re-used obj for quick lookups of components
|
|
242
236
|
|
|
243
237
|
|
|
244
|
-
var empty = Object.create ? Object.create(null) : {};
|
|
238
|
+
var empty = Object.create ? Object.create(null) : {};
|
|
245
239
|
|
|
246
240
|
function pushTextNode(list, html, level, start, ignoreWhitespace) {
|
|
247
|
-
// calculate correct end of the content slice in case there's
|
|
248
|
-
// no tag after the text node.
|
|
249
241
|
var end = html.indexOf('<', start);
|
|
250
|
-
var content = html.slice(start, end === -1 ? undefined : end);
|
|
251
|
-
// https://www.w3.org/TR/html4/struct/text.html#h-9.1
|
|
242
|
+
var content = html.slice(start, end === -1 ? undefined : end);
|
|
252
243
|
|
|
253
244
|
if (/^\s*$/.test(content)) {
|
|
254
245
|
content = ' ';
|
|
255
|
-
}
|
|
256
|
-
// or if they would be leading whitespace-only text nodes:
|
|
257
|
-
// * end > -1 indicates this is not a trailing text node
|
|
258
|
-
// * leading node is when level is -1 and list has length 0
|
|
259
|
-
|
|
246
|
+
}
|
|
260
247
|
|
|
261
248
|
if (!ignoreWhitespace && end > -1 && level + list.length >= 0 || content !== ' ') {
|
|
262
249
|
list.push({
|
|
@@ -303,7 +290,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
303
290
|
pushTextNode(current.children, html, level, start, options.ignoreWhitespace);
|
|
304
291
|
}
|
|
305
292
|
|
|
306
|
-
byTag[current.tagName] = current;
|
|
293
|
+
byTag[current.tagName] = current;
|
|
307
294
|
|
|
308
295
|
if (level === 0) {
|
|
309
296
|
result.push(current);
|
|
@@ -324,14 +311,11 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
324
311
|
}
|
|
325
312
|
|
|
326
313
|
if (!inComponent && nextChar !== '<' && nextChar) {
|
|
327
|
-
// trailing text node
|
|
328
|
-
// if we're at the root, push a base text node. otherwise add as
|
|
329
|
-
// a child to the current node.
|
|
330
314
|
parent = level === -1 ? result : arr[level].children;
|
|
331
315
|
pushTextNode(parent, html, level, start, options.ignoreWhitespace);
|
|
332
316
|
}
|
|
333
317
|
}
|
|
334
|
-
});
|
|
318
|
+
});
|
|
335
319
|
|
|
336
320
|
if (!result.length && html.length) {
|
|
337
321
|
pushTextNode(result, html, 0, 0, options.ignoreWhitespace);
|
|
@@ -384,22 +368,13 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
384
368
|
var defaultOptions = {
|
|
385
369
|
bindI18n: 'languageChanged',
|
|
386
370
|
bindI18nStore: '',
|
|
387
|
-
// nsMode: 'fallback' // loop through all namespaces given to hook, HOC, render prop for key lookup
|
|
388
371
|
transEmptyNodeValue: '',
|
|
389
372
|
transSupportBasicHtmlNodes: true,
|
|
390
373
|
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
391
|
-
// hashTransKey: key => key // calculate a key for Trans component based on defaultValue
|
|
392
374
|
useSuspense: true
|
|
393
375
|
};
|
|
394
376
|
var i18nInstance;
|
|
395
|
-
var hasUsedI18nextProvider;
|
|
396
377
|
var I18nContext = React__default.createContext();
|
|
397
|
-
function usedI18nextProvider(used) {
|
|
398
|
-
hasUsedI18nextProvider = used;
|
|
399
|
-
}
|
|
400
|
-
function getHasUsedI18nextProvider() {
|
|
401
|
-
return hasUsedI18nextProvider;
|
|
402
|
-
}
|
|
403
378
|
function setDefaults() {
|
|
404
379
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
405
380
|
defaultOptions = _objectSpread2({}, defaultOptions, {}, options);
|
|
@@ -407,9 +382,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
407
382
|
function getDefaults() {
|
|
408
383
|
return defaultOptions;
|
|
409
384
|
}
|
|
410
|
-
var ReportNamespaces =
|
|
411
|
-
/*#__PURE__*/
|
|
412
|
-
function () {
|
|
385
|
+
var ReportNamespaces = function () {
|
|
413
386
|
function ReportNamespaces() {
|
|
414
387
|
_classCallCheck(this, ReportNamespaces);
|
|
415
388
|
|
|
@@ -460,17 +433,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
460
433
|
resolve(i18nInitialProps);
|
|
461
434
|
}
|
|
462
435
|
});
|
|
463
|
-
};
|
|
464
|
-
// return async ctx => {
|
|
465
|
-
// const componentsInitialProps = ForComponent.getInitialProps
|
|
466
|
-
// ? await ForComponent.getInitialProps(ctx)
|
|
467
|
-
// : {};
|
|
468
|
-
// const i18nInitialProps = getInitialProps();
|
|
469
|
-
// return {
|
|
470
|
-
// ...componentsInitialProps,
|
|
471
|
-
// ...i18nInitialProps,
|
|
472
|
-
// };
|
|
473
|
-
// };
|
|
436
|
+
};
|
|
474
437
|
}
|
|
475
438
|
function getInitialProps() {
|
|
476
439
|
var i18n = getI18n();
|
|
@@ -510,23 +473,13 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
510
473
|
if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
|
|
511
474
|
if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
|
|
512
475
|
warn.apply(void 0, args);
|
|
513
|
-
}
|
|
514
|
-
//
|
|
515
|
-
// export function deprecated(...args) {
|
|
516
|
-
// if (process && process.env && (!"development" || "development" === 'development')) {
|
|
517
|
-
// if (typeof args[0] === 'string') args[0] = `deprecation warning -> ${args[0]}`;
|
|
518
|
-
// warnOnce(...args);
|
|
519
|
-
// }
|
|
520
|
-
// }
|
|
521
|
-
|
|
476
|
+
}
|
|
522
477
|
function loadNamespaces(i18n, ns, cb) {
|
|
523
478
|
i18n.loadNamespaces(ns, function () {
|
|
524
|
-
// delay ready if not yet initialized i18n instance
|
|
525
479
|
if (i18n.isInitialized) {
|
|
526
480
|
cb();
|
|
527
481
|
} else {
|
|
528
482
|
var initialized = function initialized() {
|
|
529
|
-
// due to emitter removing issue in i18next we need to delay remove
|
|
530
483
|
setTimeout(function () {
|
|
531
484
|
i18n.off('initialized', initialized);
|
|
532
485
|
}, 0);
|
|
@@ -547,24 +500,17 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
547
500
|
|
|
548
501
|
var lng = i18n.languages[0];
|
|
549
502
|
var fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
550
|
-
var lastLng = i18n.languages[i18n.languages.length - 1];
|
|
551
|
-
|
|
503
|
+
var lastLng = i18n.languages[i18n.languages.length - 1];
|
|
552
504
|
if (lng.toLowerCase() === 'cimode') return true;
|
|
553
505
|
|
|
554
506
|
var loadNotPending = function loadNotPending(l, n) {
|
|
555
507
|
var loadState = i18n.services.backendConnector.state["".concat(l, "|").concat(n)];
|
|
556
508
|
return loadState === -1 || loadState === 2;
|
|
557
|
-
};
|
|
558
|
-
// so set ready to false while we are changing the language
|
|
559
|
-
// and namespace pending (depends on having a backend)
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false; // loaded -> SUCCESS
|
|
563
|
-
|
|
564
|
-
if (i18n.hasResourceBundle(lng, ns)) return true; // were not loading at all -> SEMI SUCCESS
|
|
565
|
-
|
|
566
|
-
if (!i18n.services.backendConnector.backend) return true; // failed loading ns - but at least fallback is not pending -> SEMI SUCCESS
|
|
509
|
+
};
|
|
567
510
|
|
|
511
|
+
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
|
|
512
|
+
if (i18n.hasResourceBundle(lng, ns)) return true;
|
|
513
|
+
if (!i18n.services.backendConnector.backend) return true;
|
|
568
514
|
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
569
515
|
return false;
|
|
570
516
|
}
|
|
@@ -572,8 +518,11 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
572
518
|
return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown');
|
|
573
519
|
}
|
|
574
520
|
|
|
575
|
-
function hasChildren(node) {
|
|
576
|
-
|
|
521
|
+
function hasChildren(node, checkLength) {
|
|
522
|
+
if (!node) return false;
|
|
523
|
+
var base = node.props ? node.props.children : node.children;
|
|
524
|
+
if (checkLength) return base.length > 0;
|
|
525
|
+
return !!base;
|
|
577
526
|
}
|
|
578
527
|
|
|
579
528
|
function getChildren(node) {
|
|
@@ -592,46 +541,48 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
592
541
|
return Array.isArray(data) ? data : [data];
|
|
593
542
|
}
|
|
594
543
|
|
|
595
|
-
function
|
|
544
|
+
function mergeProps(source, target) {
|
|
545
|
+
var newTarget = _objectSpread2({}, target);
|
|
546
|
+
|
|
547
|
+
newTarget.props = Object.assign(source.props, target.props);
|
|
548
|
+
return newTarget;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function nodesToString(children, i18nOptions) {
|
|
596
552
|
if (!children) return '';
|
|
597
|
-
var stringNode =
|
|
553
|
+
var stringNode = '';
|
|
598
554
|
var childrenArray = getAsArray(children);
|
|
599
555
|
var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
600
|
-
childrenArray.forEach(function (child,
|
|
601
|
-
var elementKey = "".concat(i);
|
|
602
|
-
|
|
556
|
+
childrenArray.forEach(function (child, childIndex) {
|
|
603
557
|
if (typeof child === 'string') {
|
|
604
|
-
stringNode
|
|
605
|
-
} else if (hasChildren(child)) {
|
|
606
|
-
var elementTag = keepArray.indexOf(child.type) > -1 && Object.keys(child.props).length === 1 && typeof hasChildren(child) === 'string' ? child.type : elementKey;
|
|
607
|
-
|
|
608
|
-
if (child.props && child.props.i18nIsDynamicList) {
|
|
609
|
-
// we got a dynamic list like "<ul>{['a', 'b'].map(item => ( <li key={item}>{item}</li> ))}</ul>""
|
|
610
|
-
// the result should be "<0></0>" and not "<0><0>a</0><1>b</1></0>"
|
|
611
|
-
stringNode = "".concat(stringNode, "<").concat(elementTag, "></").concat(elementTag, ">");
|
|
612
|
-
} else {
|
|
613
|
-
// regular case mapping the inner children
|
|
614
|
-
stringNode = "".concat(stringNode, "<").concat(elementTag, ">").concat(nodesToString('', getChildren(child), i + 1, i18nOptions), "</").concat(elementTag, ">");
|
|
615
|
-
}
|
|
558
|
+
stringNode += "".concat(child);
|
|
616
559
|
} else if (React__default.isValidElement(child)) {
|
|
617
|
-
|
|
618
|
-
|
|
560
|
+
var childPropsCount = Object.keys(child.props).length;
|
|
561
|
+
var shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
562
|
+
var childChildren = child.props.children;
|
|
563
|
+
|
|
564
|
+
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
565
|
+
stringNode += "<".concat(child.type, "/>");
|
|
566
|
+
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
567
|
+
stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
|
|
568
|
+
} else if (child.props.i18nIsDynamicList) {
|
|
569
|
+
stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
|
|
570
|
+
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
571
|
+
stringNode += "<".concat(child.type, ">").concat(childChildren, "</").concat(child.type, ">");
|
|
619
572
|
} else {
|
|
620
|
-
|
|
573
|
+
var content = nodesToString(childChildren, i18nOptions);
|
|
574
|
+
stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
|
|
621
575
|
}
|
|
622
576
|
} else if (_typeof(child) === 'object') {
|
|
623
|
-
var
|
|
577
|
+
var format = child.format,
|
|
578
|
+
clone = _objectWithoutProperties(child, ["format"]);
|
|
624
579
|
|
|
625
|
-
var format = clone.format;
|
|
626
|
-
delete clone.format;
|
|
627
580
|
var keys = Object.keys(clone);
|
|
628
581
|
|
|
629
|
-
if (
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
stringNode = "".concat(stringNode, "{{").concat(keys[0], "}}");
|
|
582
|
+
if (keys.length === 1) {
|
|
583
|
+
var value = format ? "".concat(keys[0], ", ").concat(format) : keys[0];
|
|
584
|
+
stringNode += "{{".concat(value, "}}");
|
|
633
585
|
} else {
|
|
634
|
-
// not a valid interpolation object (can only contain one value plus format)
|
|
635
586
|
warn("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.", child);
|
|
636
587
|
}
|
|
637
588
|
} else {
|
|
@@ -642,13 +593,10 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
642
593
|
}
|
|
643
594
|
|
|
644
595
|
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
|
|
645
|
-
if (targetString === '') return [];
|
|
646
|
-
|
|
596
|
+
if (targetString === '') return [];
|
|
647
597
|
var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
648
|
-
var emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
649
|
-
|
|
650
|
-
if (!children && !emptyChildrenButNeedsHandling) return [targetString]; // v2 -> interpolates upfront no need for "some <0>{{var}}</0>"" -> will be just "some {{var}}" in translation file
|
|
651
|
-
|
|
598
|
+
var emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
599
|
+
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
652
600
|
var data = {};
|
|
653
601
|
|
|
654
602
|
function getData(childs) {
|
|
@@ -660,77 +608,79 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
660
608
|
}
|
|
661
609
|
|
|
662
610
|
getData(children);
|
|
663
|
-
var interpolatedString = i18n.services.interpolator.interpolate(targetString, _objectSpread2({}, data, {}, combinedTOpts), i18n.language);
|
|
664
|
-
// -> avoids issues in parser removing prepending text nodes
|
|
665
|
-
|
|
611
|
+
var interpolatedString = i18n.services.interpolator.interpolate(targetString, _objectSpread2({}, data, {}, combinedTOpts), i18n.language);
|
|
666
612
|
var ast = htmlParseStringify2.parse("<0>".concat(interpolatedString, "</0>"));
|
|
667
613
|
|
|
668
|
-
function
|
|
614
|
+
function renderInner(child, node, rootReactNode) {
|
|
615
|
+
var childs = getChildren(child);
|
|
616
|
+
var mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
617
|
+
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function pushTranslatedJSX(child, inner, mem, i) {
|
|
621
|
+
if (child.dummy) child.children = inner;
|
|
622
|
+
mem.push(React__default.cloneElement(child, _objectSpread2({}, child.props, {
|
|
623
|
+
key: i
|
|
624
|
+
}), inner));
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function mapAST(reactNode, astNode, rootReactNode) {
|
|
669
628
|
var reactNodes = getAsArray(reactNode);
|
|
670
629
|
var astNodes = getAsArray(astNode);
|
|
671
630
|
return astNodes.reduce(function (mem, node, i) {
|
|
672
631
|
var translationContent = node.children && node.children[0] && node.children[0].content;
|
|
673
632
|
|
|
674
633
|
if (node.type === 'tag') {
|
|
675
|
-
var
|
|
634
|
+
var tmp = reactNodes[parseInt(node.name, 10)];
|
|
635
|
+
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
636
|
+
if (!tmp) tmp = {};
|
|
637
|
+
var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
638
|
+
props: node.attrs
|
|
639
|
+
}, tmp) : tmp;
|
|
676
640
|
var isElement = React__default.isValidElement(child);
|
|
641
|
+
var isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
642
|
+
var isEmptyTransWithHTML = emptyChildrenButNeedsHandling && _typeof(child) === 'object' && child.dummy && !isElement;
|
|
643
|
+
var isKnownComponent = _typeof(children) === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
677
644
|
|
|
678
645
|
if (typeof child === 'string') {
|
|
679
646
|
mem.push(child);
|
|
680
|
-
} else if (hasChildren(child)) {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
mem.push(React__default.cloneElement(child, _objectSpread2({}, child.props, {
|
|
687
|
-
key: i
|
|
688
|
-
}), inner));
|
|
689
|
-
} else if (emptyChildrenButNeedsHandling && _typeof(child) === 'object' && child.dummy && !isElement) {
|
|
690
|
-
// we have a empty Trans node (the dummy element) with a targetstring that contains html tags needing
|
|
691
|
-
// conversion to react nodes
|
|
692
|
-
// so we just need to map the inner stuff
|
|
693
|
-
var _inner = mapAST(reactNodes
|
|
694
|
-
/* wrong but we need something */
|
|
695
|
-
, node.children);
|
|
647
|
+
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
648
|
+
var inner = renderInner(child, node, rootReactNode);
|
|
649
|
+
pushTranslatedJSX(child, inner, mem, i);
|
|
650
|
+
} else if (isEmptyTransWithHTML) {
|
|
651
|
+
var _inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
696
652
|
|
|
697
653
|
mem.push(React__default.cloneElement(child, _objectSpread2({}, child.props, {
|
|
698
654
|
key: i
|
|
699
655
|
}), _inner));
|
|
700
656
|
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
701
|
-
if (
|
|
657
|
+
if (isKnownComponent) {
|
|
658
|
+
var _inner2 = renderInner(child, node, rootReactNode);
|
|
659
|
+
|
|
660
|
+
pushTranslatedJSX(child, _inner2, mem, i);
|
|
661
|
+
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
702
662
|
if (node.voidElement) {
|
|
703
663
|
mem.push(React__default.createElement(node.name, {
|
|
704
664
|
key: "".concat(node.name, "-").concat(i)
|
|
705
665
|
}));
|
|
706
666
|
} else {
|
|
707
|
-
var
|
|
708
|
-
/* wrong but we need something */
|
|
709
|
-
, node.children);
|
|
667
|
+
var _inner3 = mapAST(reactNodes, node.children, rootReactNode);
|
|
710
668
|
|
|
711
669
|
mem.push(React__default.createElement(node.name, {
|
|
712
670
|
key: "".concat(node.name, "-").concat(i)
|
|
713
|
-
},
|
|
671
|
+
}, _inner3));
|
|
714
672
|
}
|
|
715
673
|
} else if (node.voidElement) {
|
|
716
674
|
mem.push("<".concat(node.name, " />"));
|
|
717
675
|
} else {
|
|
718
|
-
var
|
|
719
|
-
/* wrong but we need something */
|
|
720
|
-
, node.children);
|
|
676
|
+
var _inner4 = mapAST(reactNodes, node.children, rootReactNode);
|
|
721
677
|
|
|
722
|
-
mem.push("<".concat(node.name, ">").concat(
|
|
678
|
+
mem.push("<".concat(node.name, ">").concat(_inner4, "</").concat(node.name, ">"));
|
|
723
679
|
}
|
|
724
680
|
} else if (_typeof(child) === 'object' && !isElement) {
|
|
725
|
-
var content = node.children[0] ? translationContent : null;
|
|
726
|
-
// as interpolation was done already we just have a regular content node
|
|
727
|
-
// in the translation AST while having an object in reactNodes
|
|
728
|
-
// -> push the content no need to interpolate again
|
|
729
|
-
|
|
681
|
+
var content = node.children[0] ? translationContent : null;
|
|
730
682
|
if (content) mem.push(content);
|
|
731
683
|
} else if (node.children.length === 1 && translationContent) {
|
|
732
|
-
// If component does not have children, but translation - has
|
|
733
|
-
// with this in component could be components={[<span class='make-beautiful'/>]} and in translation - 'some text <0>some highlighted message</0>'
|
|
734
684
|
mem.push(React__default.cloneElement(child, _objectSpread2({}, child.props, {
|
|
735
685
|
key: i
|
|
736
686
|
}), translationContent));
|
|
@@ -745,15 +695,12 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
745
695
|
|
|
746
696
|
return mem;
|
|
747
697
|
}, []);
|
|
748
|
-
}
|
|
749
|
-
// we did for the string ast from translation
|
|
750
|
-
// return the children of that extra node to get expected result
|
|
751
|
-
|
|
698
|
+
}
|
|
752
699
|
|
|
753
700
|
var result = mapAST([{
|
|
754
701
|
dummy: true,
|
|
755
702
|
children: children
|
|
756
|
-
}], ast);
|
|
703
|
+
}], ast, getAsArray(children || []));
|
|
757
704
|
return getChildren(result[0]);
|
|
758
705
|
}
|
|
759
706
|
|
|
@@ -771,9 +718,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
771
718
|
tFromProps = _ref.t,
|
|
772
719
|
additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
|
|
773
720
|
|
|
774
|
-
var
|
|
775
|
-
|
|
776
|
-
var _ref2 = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
|
|
721
|
+
var _ref2 = React.useContext(I18nContext) || {},
|
|
777
722
|
i18nFromContext = _ref2.i18n,
|
|
778
723
|
defaultNSFromContext = _ref2.defaultNS;
|
|
779
724
|
|
|
@@ -790,11 +735,9 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
790
735
|
|
|
791
736
|
var reactI18nextOptions = _objectSpread2({}, getDefaults(), {}, i18n.options && i18n.options.react);
|
|
792
737
|
|
|
793
|
-
var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
|
|
794
|
-
|
|
795
738
|
var namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
796
739
|
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
797
|
-
var defaultValue = defaults || nodesToString(
|
|
740
|
+
var defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
798
741
|
var hashTransKey = reactI18nextOptions.hashTransKey;
|
|
799
742
|
var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
800
743
|
var interpolationOverride = values ? {} : {
|
|
@@ -812,17 +755,16 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
812
755
|
});
|
|
813
756
|
|
|
814
757
|
var translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
815
|
-
|
|
816
|
-
|
|
758
|
+
var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts);
|
|
759
|
+
var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
760
|
+
return useAsParent ? React__default.createElement(useAsParent, additionalProps, content) : content;
|
|
817
761
|
}
|
|
818
762
|
|
|
819
763
|
function useTranslation(ns) {
|
|
820
764
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
821
|
-
// assert we have the needed i18nInstance
|
|
822
765
|
var i18nFromProps = props.i18n;
|
|
823
|
-
var ReactI18nContext = React.useContext(I18nContext);
|
|
824
766
|
|
|
825
|
-
var _ref =
|
|
767
|
+
var _ref = React.useContext(I18nContext) || {},
|
|
826
768
|
i18nFromContext = _ref.i18n,
|
|
827
769
|
defaultNSFromContext = _ref.defaultNS;
|
|
828
770
|
|
|
@@ -845,16 +787,13 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
845
787
|
|
|
846
788
|
var i18nOptions = _objectSpread2({}, getDefaults(), {}, i18n.options.react, {}, props);
|
|
847
789
|
|
|
848
|
-
var useSuspense = i18nOptions.useSuspense;
|
|
849
|
-
|
|
790
|
+
var useSuspense = i18nOptions.useSuspense;
|
|
850
791
|
var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
851
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
852
|
-
|
|
853
|
-
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); // are we ready? yes if all namespaces in first language are loaded already (either with data or empty object on failed load)
|
|
854
|
-
|
|
792
|
+
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
793
|
+
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
855
794
|
var ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(function (n) {
|
|
856
795
|
return hasLoadedNamespace(n, i18n, i18nOptions);
|
|
857
|
-
});
|
|
796
|
+
});
|
|
858
797
|
|
|
859
798
|
function getT() {
|
|
860
799
|
return {
|
|
@@ -865,15 +804,13 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
865
804
|
var _useState = React.useState(getT()),
|
|
866
805
|
_useState2 = _slicedToArray(_useState, 2),
|
|
867
806
|
t = _useState2[0],
|
|
868
|
-
setT = _useState2[1];
|
|
869
|
-
|
|
807
|
+
setT = _useState2[1];
|
|
870
808
|
|
|
871
809
|
var isMounted = React.useRef(true);
|
|
872
810
|
React.useEffect(function () {
|
|
873
811
|
var bindI18n = i18nOptions.bindI18n,
|
|
874
812
|
bindI18nStore = i18nOptions.bindI18nStore;
|
|
875
|
-
isMounted.current = true;
|
|
876
|
-
// in side effect and do not call resetT if unmounted
|
|
813
|
+
isMounted.current = true;
|
|
877
814
|
|
|
878
815
|
if (!ready && !useSuspense) {
|
|
879
816
|
loadNamespaces(i18n, namespaces, function () {
|
|
@@ -883,12 +820,10 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
883
820
|
|
|
884
821
|
function boundReset() {
|
|
885
822
|
if (isMounted.current) setT(getT());
|
|
886
|
-
}
|
|
887
|
-
|
|
823
|
+
}
|
|
888
824
|
|
|
889
825
|
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
890
|
-
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
891
|
-
|
|
826
|
+
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
892
827
|
return function () {
|
|
893
828
|
isMounted.current = false;
|
|
894
829
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
@@ -898,17 +833,13 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
898
833
|
return i18n.store.off(e, boundReset);
|
|
899
834
|
});
|
|
900
835
|
};
|
|
901
|
-
}, [namespaces.join()]);
|
|
902
|
-
|
|
836
|
+
}, [namespaces.join()]);
|
|
903
837
|
var ret = [t.t, i18n, ready];
|
|
904
838
|
ret.t = t.t;
|
|
905
839
|
ret.i18n = i18n;
|
|
906
|
-
ret.ready = ready;
|
|
907
|
-
|
|
908
|
-
if (ready) return ret;
|
|
909
|
-
|
|
910
|
-
if (!ready && !useSuspense) return ret; // not yet loaded namespaces -> load them -> and trigger suspense
|
|
911
|
-
|
|
840
|
+
ret.ready = ready;
|
|
841
|
+
if (ready) return ret;
|
|
842
|
+
if (!ready && !useSuspense) return ret;
|
|
912
843
|
throw new Promise(function (resolve) {
|
|
913
844
|
loadNamespaces(i18n, namespaces, function () {
|
|
914
845
|
if (isMounted.current) setT(getT());
|
|
@@ -979,8 +910,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
979
910
|
var i18n = _ref.i18n,
|
|
980
911
|
defaultNS = _ref.defaultNS,
|
|
981
912
|
children = _ref.children;
|
|
982
|
-
|
|
983
|
-
return React__default.createElement(I18nContext.Provider, {
|
|
913
|
+
return React.createElement(I18nContext.Provider, {
|
|
984
914
|
value: {
|
|
985
915
|
i18n: i18n,
|
|
986
916
|
defaultNS: defaultNS
|
|
@@ -991,19 +921,15 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
991
921
|
function useSSR(initialI18nStore, initialLanguage) {
|
|
992
922
|
var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
993
923
|
var i18nFromProps = props.i18n;
|
|
994
|
-
var ReactI18nContext = React.useContext(I18nContext);
|
|
995
924
|
|
|
996
|
-
var _ref =
|
|
925
|
+
var _ref = React.useContext(I18nContext) || {},
|
|
997
926
|
i18nFromContext = _ref.i18n;
|
|
998
927
|
|
|
999
|
-
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack
|
|
928
|
+
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
929
|
+
if (i18n.options && i18n.options.isClone) return;
|
|
1003
930
|
|
|
1004
931
|
if (initialI18nStore && !i18n.initializedStoreOnce) {
|
|
1005
|
-
i18n.services.resourceStore.data = initialI18nStore;
|
|
1006
|
-
|
|
932
|
+
i18n.services.resourceStore.data = initialI18nStore;
|
|
1007
933
|
i18n.options.ns = Object.values(initialI18nStore).reduce(function (mem, lngResources) {
|
|
1008
934
|
Object.keys(lngResources).forEach(function (ns) {
|
|
1009
935
|
if (mem.indexOf(ns) < 0) mem.push(ns);
|