|
163 | 163 | });
|
164 | 164 | i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
165 | 165 | };
|
166 |
| - const hasLoadedNamespace = function (ns, i18n) { |
167 |
| - let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
| 166 | + const hasLoadedNamespace = (ns, i18n, options = {}) => { |
168 | 167 | if (!i18n.languages || !i18n.languages.length) {
|
169 | 168 | warnOnce(i18n, 'NO_LANGUAGES', 'i18n.languages were undefined or empty', {
|
170 | 169 | languages: i18n.languages
|
|
218 | 217 | useSuspense: true,
|
219 | 218 | unescape
|
220 | 219 | };
|
221 |
| - const setDefaults = function () { |
222 |
| - let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
| 220 | + const setDefaults = (options = {}) => { |
223 | 221 | defaultOptions = {
|
224 | 222 | ...defaultOptions,
|
225 | 223 | ...options
|
|
471 | 469 | });
|
472 | 470 | return null;
|
473 | 471 | };
|
474 |
| - function Trans$1(_ref) { |
475 |
| - let { |
476 |
| - children, |
477 |
| - count, |
478 |
| - parent, |
479 |
| - i18nKey, |
480 |
| - context, |
481 |
| - tOptions = {}, |
482 |
| - values, |
483 |
| - defaults, |
484 |
| - components, |
485 |
| - ns, |
486 |
| - i18n: i18nFromProps, |
487 |
| - t: tFromProps, |
488 |
| - shouldUnescape, |
489 |
| - ...additionalProps |
490 |
| - } = _ref; |
| 472 | + function Trans$1({ |
| 473 | + children, |
| 474 | + count, |
| 475 | + parent, |
| 476 | + i18nKey, |
| 477 | + context, |
| 478 | + tOptions = {}, |
| 479 | + values, |
| 480 | + defaults, |
| 481 | + components, |
| 482 | + ns, |
| 483 | + i18n: i18nFromProps, |
| 484 | + t: tFromProps, |
| 485 | + shouldUnescape, |
| 486 | + ...additionalProps |
| 487 | + }) { |
491 | 488 | const i18n = i18nFromProps || getI18n();
|
492 | 489 | if (!i18n) {
|
493 | 490 | warnOnce(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
|
|
585 | 582 | return ret;
|
586 | 583 | };
|
587 | 584 |
|
588 |
| - function Trans(_ref) { |
589 |
| - let { |
590 |
| - children, |
591 |
| - count, |
592 |
| - parent, |
593 |
| - i18nKey, |
594 |
| - context, |
595 |
| - tOptions = {}, |
596 |
| - values, |
597 |
| - defaults, |
598 |
| - components, |
599 |
| - ns, |
600 |
| - i18n: i18nFromProps, |
601 |
| - t: tFromProps, |
602 |
| - shouldUnescape, |
603 |
| - ...additionalProps |
604 |
| - } = _ref; |
| 585 | + function Trans({ |
| 586 | + children, |
| 587 | + count, |
| 588 | + parent, |
| 589 | + i18nKey, |
| 590 | + context, |
| 591 | + tOptions = {}, |
| 592 | + values, |
| 593 | + defaults, |
| 594 | + components, |
| 595 | + ns, |
| 596 | + i18n: i18nFromProps, |
| 597 | + t: tFromProps, |
| 598 | + shouldUnescape, |
| 599 | + ...additionalProps |
| 600 | + }) { |
605 | 601 | const {
|
606 | 602 | i18n: i18nFromContext,
|
607 | 603 | defaultNS: defaultNSFromContext
|
|
635 | 631 | };
|
636 | 632 | const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
|
637 | 633 | const useMemoizedT = (i18n, language, namespace, keyPrefix) => react.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
|
638 |
| - const useTranslation = function (ns) { |
639 |
| - let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 634 | + const useTranslation = (ns, props = {}) => { |
640 | 635 | const {
|
641 | 636 | i18n: i18nFromProps
|
642 | 637 | } = props;
|
|
732 | 727 | });
|
733 | 728 | };
|
734 | 729 |
|
735 |
| - const withTranslation = function (ns) { |
736 |
| - let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
737 |
| - return function Extend(WrappedComponent) { |
738 |
| - function I18nextWithTranslation(_ref) { |
739 |
| - let { |
740 |
| - forwardedRef, |
741 |
| - ...rest |
742 |
| - } = _ref; |
743 |
| - const [t, i18n, ready] = useTranslation(ns, { |
744 |
| - ...rest, |
745 |
| - keyPrefix: options.keyPrefix |
746 |
| - }); |
747 |
| - const passDownProps = { |
748 |
| - ...rest, |
749 |
| - t, |
750 |
| - i18n, |
751 |
| - tReady: ready |
752 |
| - }; |
753 |
| - if (options.withRef && forwardedRef) { |
754 |
| - passDownProps.ref = forwardedRef; |
755 |
| - } else if (!options.withRef && forwardedRef) { |
756 |
| - passDownProps.forwardedRef = forwardedRef; |
757 |
| - } |
758 |
| - return react.createElement(WrappedComponent, passDownProps); |
| 730 | + const withTranslation = (ns, options = {}) => function Extend(WrappedComponent) { |
| 731 | + function I18nextWithTranslation({ |
| 732 | + forwardedRef, |
| 733 | + ...rest |
| 734 | + }) { |
| 735 | + const [t, i18n, ready] = useTranslation(ns, { |
| 736 | + ...rest, |
| 737 | + keyPrefix: options.keyPrefix |
| 738 | + }); |
| 739 | + const passDownProps = { |
| 740 | + ...rest, |
| 741 | + t, |
| 742 | + i18n, |
| 743 | + tReady: ready |
| 744 | + }; |
| 745 | + if (options.withRef && forwardedRef) { |
| 746 | + passDownProps.ref = forwardedRef; |
| 747 | + } else if (!options.withRef && forwardedRef) { |
| 748 | + passDownProps.forwardedRef = forwardedRef; |
759 | 749 | }
|
760 |
| - I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`; |
761 |
| - I18nextWithTranslation.WrappedComponent = WrappedComponent; |
762 |
| - const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, { |
763 |
| - forwardedRef: ref |
764 |
| - })); |
765 |
| - return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation; |
766 |
| - }; |
| 750 | + return react.createElement(WrappedComponent, passDownProps); |
| 751 | + } |
| 752 | + I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`; |
| 753 | + I18nextWithTranslation.WrappedComponent = WrappedComponent; |
| 754 | + const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, { |
| 755 | + forwardedRef: ref |
| 756 | + })); |
| 757 | + return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation; |
767 | 758 | };
|
768 | 759 |
|
769 |
| - const Translation = _ref => { |
770 |
| - let { |
771 |
| - ns, |
772 |
| - children, |
773 |
| - ...options |
774 |
| - } = _ref; |
| 760 | + const Translation = ({ |
| 761 | + ns, |
| 762 | + children, |
| 763 | + ...options |
| 764 | + }) => { |
775 | 765 | const [t, i18n, ready] = useTranslation(ns, options);
|
776 | 766 | return children(t, {
|
777 | 767 | i18n,
|
778 | 768 | lng: i18n.language
|
779 | 769 | }, ready);
|
780 | 770 | };
|
781 | 771 |
|
782 |
| - function I18nextProvider(_ref) { |
783 |
| - let { |
784 |
| - i18n, |
785 |
| - defaultNS, |
786 |
| - children |
787 |
| - } = _ref; |
| 772 | + function I18nextProvider({ |
| 773 | + i18n, |
| 774 | + defaultNS, |
| 775 | + children |
| 776 | + }) { |
788 | 777 | const value = react.useMemo(() => ({
|
789 | 778 | i18n,
|
790 | 779 | defaultNS
|
|
794 | 783 | }, children);
|
795 | 784 | }
|
796 | 785 |
|
797 |
| - const useSSR = function (initialI18nStore, initialLanguage) { |
798 |
| - let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
| 786 | + const useSSR = (initialI18nStore, initialLanguage, props = {}) => { |
799 | 787 | const {
|
800 | 788 | i18n: i18nFromProps
|
801 | 789 | } = props;
|
|
822 | 810 | };
|
823 | 811 |
|
824 | 812 | const withSSR = () => function Extend(WrappedComponent) {
|
825 |
| - function I18nextWithSSR(_ref) { |
826 |
| - let { |
827 |
| - initialI18nStore, |
828 |
| - initialLanguage, |
829 |
| - ...rest |
830 |
| - } = _ref; |
| 813 | + function I18nextWithSSR({ |
| 814 | + initialI18nStore, |
| 815 | + initialLanguage, |
| 816 | + ...rest |
| 817 | + }) { |
831 | 818 | useSSR(initialI18nStore, initialLanguage);
|
832 | 819 | return react.createElement(WrappedComponent, {
|
833 | 820 | ...rest
|
|
0 commit comments