react-i18next 11.17.0 → 11.17.3
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 +12 -0
- package/dist/amd/react-i18next.js +43 -31
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/Trans.js +13 -21
- package/dist/commonjs/context.js +2 -4
- package/dist/commonjs/useTranslation.js +15 -1
- package/dist/commonjs/withSSR.js +2 -2
- package/dist/commonjs/withTranslation.js +4 -4
- package/dist/es/Trans.js +13 -13
- package/dist/es/context.js +2 -2
- package/dist/es/useTranslation.js +16 -1
- package/dist/es/withSSR.js +2 -2
- package/dist/es/withTranslation.js +4 -4
- package/dist/umd/react-i18next.js +44 -32
- package/dist/umd/react-i18next.min.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +4 -4
- package/react-i18next.js +44 -32
- package/react-i18next.min.js +1 -1
- package/src/Trans.js +13 -13
- package/src/context.js +2 -2
- package/src/useTranslation.js +16 -1
- package/src/withSSR.js +2 -2
- package/src/withTranslation.js +4 -4
- package/ts4.1/index.d.ts +1 -1
package/react-i18next.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
|
|
4
|
-
(global = global || self, factory(global.ReactI18next = {}, global.
|
|
5
|
-
}(this, function (exports,
|
|
6
|
-
|
|
7
|
-
var React__default = 'default' in React ? React['default'] : React;
|
|
4
|
+
(global = global || self, factory(global.ReactI18next = {}, global.react));
|
|
5
|
+
}(this, function (exports, react) { 'use strict';
|
|
8
6
|
|
|
9
7
|
function ownKeys(object, enumerableOnly) {
|
|
10
8
|
var keys = Object.keys(object);
|
|
@@ -352,7 +350,7 @@
|
|
|
352
350
|
useSuspense: true
|
|
353
351
|
};
|
|
354
352
|
var i18nInstance;
|
|
355
|
-
var I18nContext =
|
|
353
|
+
var I18nContext = react.createContext();
|
|
356
354
|
function setDefaults() {
|
|
357
355
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
358
356
|
defaultOptions = _objectSpread2(_objectSpread2({}, defaultOptions), options);
|
|
@@ -530,7 +528,7 @@
|
|
|
530
528
|
function hasValidReactChildren(children) {
|
|
531
529
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
532
530
|
return children.every(function (child) {
|
|
533
|
-
return
|
|
531
|
+
return react.isValidElement(child);
|
|
534
532
|
});
|
|
535
533
|
}
|
|
536
534
|
|
|
@@ -553,7 +551,7 @@
|
|
|
553
551
|
childrenArray.forEach(function (child, childIndex) {
|
|
554
552
|
if (typeof child === 'string') {
|
|
555
553
|
stringNode += "".concat(child);
|
|
556
|
-
} else if (
|
|
554
|
+
} else if (react.isValidElement(child)) {
|
|
557
555
|
var childPropsCount = Object.keys(child.props).length;
|
|
558
556
|
var shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
559
557
|
var childChildren = child.props.children;
|
|
@@ -602,7 +600,7 @@
|
|
|
602
600
|
var childrenArray = getAsArray(childs);
|
|
603
601
|
childrenArray.forEach(function (child) {
|
|
604
602
|
if (typeof child === 'string') return;
|
|
605
|
-
if (hasChildren(child)) getData(getChildren(child));else if (_typeof(child) === 'object' && !
|
|
603
|
+
if (hasChildren(child)) getData(getChildren(child));else if (_typeof(child) === 'object' && !react.isValidElement(child)) Object.assign(data, child);
|
|
606
604
|
});
|
|
607
605
|
}
|
|
608
606
|
|
|
@@ -619,7 +617,7 @@
|
|
|
619
617
|
|
|
620
618
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
621
619
|
if (child.dummy) child.children = inner;
|
|
622
|
-
mem.push(
|
|
620
|
+
mem.push(react.cloneElement(child, _objectSpread2(_objectSpread2({}, child.props), {}, {
|
|
623
621
|
key: i
|
|
624
622
|
}), isVoid ? undefined : inner));
|
|
625
623
|
}
|
|
@@ -637,7 +635,7 @@
|
|
|
637
635
|
var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
638
636
|
props: node.attrs
|
|
639
637
|
}, tmp) : tmp;
|
|
640
|
-
var isElement =
|
|
638
|
+
var isElement = react.isValidElement(child);
|
|
641
639
|
var isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
642
640
|
var isEmptyTransWithHTML = emptyChildrenButNeedsHandling && _typeof(child) === 'object' && child.dummy && !isElement;
|
|
643
641
|
var isKnownComponent = _typeof(children) === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
@@ -651,7 +649,7 @@
|
|
|
651
649
|
} else if (isEmptyTransWithHTML) {
|
|
652
650
|
var _inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
653
651
|
|
|
654
|
-
mem.push(
|
|
652
|
+
mem.push(react.cloneElement(child, _objectSpread2(_objectSpread2({}, child.props), {}, {
|
|
655
653
|
key: i
|
|
656
654
|
}), _inner));
|
|
657
655
|
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
@@ -661,13 +659,13 @@
|
|
|
661
659
|
pushTranslatedJSX(child, _inner2, mem, i, node.voidElement);
|
|
662
660
|
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
663
661
|
if (node.voidElement) {
|
|
664
|
-
mem.push(
|
|
662
|
+
mem.push(react.createElement(node.name, {
|
|
665
663
|
key: "".concat(node.name, "-").concat(i)
|
|
666
664
|
}));
|
|
667
665
|
} else {
|
|
668
666
|
var _inner3 = mapAST(reactNodes, node.children, rootReactNode);
|
|
669
667
|
|
|
670
|
-
mem.push(
|
|
668
|
+
mem.push(react.createElement(node.name, {
|
|
671
669
|
key: "".concat(node.name, "-").concat(i)
|
|
672
670
|
}, _inner3));
|
|
673
671
|
}
|
|
@@ -682,11 +680,11 @@
|
|
|
682
680
|
var content = node.children[0] ? translationContent : null;
|
|
683
681
|
if (content) mem.push(content);
|
|
684
682
|
} else if (node.children.length === 1 && translationContent) {
|
|
685
|
-
mem.push(
|
|
683
|
+
mem.push(react.cloneElement(child, _objectSpread2(_objectSpread2({}, child.props), {}, {
|
|
686
684
|
key: i
|
|
687
685
|
}), translationContent));
|
|
688
686
|
} else {
|
|
689
|
-
mem.push(
|
|
687
|
+
mem.push(react.cloneElement(child, _objectSpread2(_objectSpread2({}, child.props), {}, {
|
|
690
688
|
key: i
|
|
691
689
|
})));
|
|
692
690
|
}
|
|
@@ -696,7 +694,7 @@
|
|
|
696
694
|
var _content = shouldUnescape ? unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
697
695
|
|
|
698
696
|
if (wrapTextNodes) {
|
|
699
|
-
mem.push(
|
|
697
|
+
mem.push(react.createElement(wrapTextNodes, {
|
|
700
698
|
key: "".concat(node.name, "-").concat(i)
|
|
701
699
|
}, _content));
|
|
702
700
|
} else {
|
|
@@ -732,7 +730,7 @@
|
|
|
732
730
|
shouldUnescape = _ref.shouldUnescape,
|
|
733
731
|
additionalProps = _objectWithoutProperties(_ref, _excluded2);
|
|
734
732
|
|
|
735
|
-
var _ref2 =
|
|
733
|
+
var _ref2 = react.useContext(I18nContext) || {},
|
|
736
734
|
i18nFromContext = _ref2.i18n,
|
|
737
735
|
defaultNSFromContext = _ref2.defaultNS;
|
|
738
736
|
|
|
@@ -773,14 +771,22 @@
|
|
|
773
771
|
var translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
774
772
|
var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
775
773
|
var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
776
|
-
return useAsParent ?
|
|
774
|
+
return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
|
|
777
775
|
}
|
|
778
776
|
|
|
777
|
+
var usePrevious = function usePrevious(value, ignore) {
|
|
778
|
+
var ref = react.useRef();
|
|
779
|
+
react.useEffect(function () {
|
|
780
|
+
ref.current = ignore ? ref.current : value;
|
|
781
|
+
}, [value, ignore]);
|
|
782
|
+
return ref.current;
|
|
783
|
+
};
|
|
784
|
+
|
|
779
785
|
function useTranslation(ns) {
|
|
780
786
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
781
787
|
var i18nFromProps = props.i18n;
|
|
782
788
|
|
|
783
|
-
var _ref =
|
|
789
|
+
var _ref = react.useContext(I18nContext) || {},
|
|
784
790
|
i18nFromContext = _ref.i18n,
|
|
785
791
|
defaultNSFromContext = _ref.defaultNS;
|
|
786
792
|
|
|
@@ -818,13 +824,15 @@
|
|
|
818
824
|
return i18n.getFixedT(null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
819
825
|
}
|
|
820
826
|
|
|
821
|
-
var _useState =
|
|
827
|
+
var _useState = react.useState(getT),
|
|
822
828
|
_useState2 = _slicedToArray(_useState, 2),
|
|
823
829
|
t = _useState2[0],
|
|
824
830
|
setT = _useState2[1];
|
|
825
831
|
|
|
826
|
-
var
|
|
827
|
-
|
|
832
|
+
var joinedNS = namespaces.join();
|
|
833
|
+
var previousJoinedNS = usePrevious(joinedNS);
|
|
834
|
+
var isMounted = react.useRef(true);
|
|
835
|
+
react.useEffect(function () {
|
|
828
836
|
var bindI18n = i18nOptions.bindI18n,
|
|
829
837
|
bindI18nStore = i18nOptions.bindI18nStore;
|
|
830
838
|
isMounted.current = true;
|
|
@@ -835,6 +843,10 @@
|
|
|
835
843
|
});
|
|
836
844
|
}
|
|
837
845
|
|
|
846
|
+
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
847
|
+
setT(getT);
|
|
848
|
+
}
|
|
849
|
+
|
|
838
850
|
function boundReset() {
|
|
839
851
|
if (isMounted.current) setT(getT);
|
|
840
852
|
}
|
|
@@ -850,9 +862,9 @@
|
|
|
850
862
|
return i18n.store.off(e, boundReset);
|
|
851
863
|
});
|
|
852
864
|
};
|
|
853
|
-
}, [i18n,
|
|
854
|
-
var isInitial =
|
|
855
|
-
|
|
865
|
+
}, [i18n, joinedNS]);
|
|
866
|
+
var isInitial = react.useRef(true);
|
|
867
|
+
react.useEffect(function () {
|
|
856
868
|
if (isMounted.current && !isInitial.current) {
|
|
857
869
|
setT(getT);
|
|
858
870
|
}
|
|
@@ -900,19 +912,19 @@
|
|
|
900
912
|
passDownProps.forwardedRef = forwardedRef;
|
|
901
913
|
}
|
|
902
914
|
|
|
903
|
-
return
|
|
915
|
+
return react.createElement(WrappedComponent, passDownProps);
|
|
904
916
|
}
|
|
905
917
|
|
|
906
918
|
I18nextWithTranslation.displayName = "withI18nextTranslation(".concat(getDisplayName(WrappedComponent), ")");
|
|
907
919
|
I18nextWithTranslation.WrappedComponent = WrappedComponent;
|
|
908
920
|
|
|
909
921
|
var forwardRef = function forwardRef(props, ref) {
|
|
910
|
-
return
|
|
922
|
+
return react.createElement(I18nextWithTranslation, Object.assign({}, props, {
|
|
911
923
|
forwardedRef: ref
|
|
912
924
|
}));
|
|
913
925
|
};
|
|
914
926
|
|
|
915
|
-
return options.withRef ?
|
|
927
|
+
return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
|
|
916
928
|
};
|
|
917
929
|
}
|
|
918
930
|
|
|
@@ -938,13 +950,13 @@
|
|
|
938
950
|
var i18n = _ref.i18n,
|
|
939
951
|
defaultNS = _ref.defaultNS,
|
|
940
952
|
children = _ref.children;
|
|
941
|
-
var value =
|
|
953
|
+
var value = react.useMemo(function () {
|
|
942
954
|
return {
|
|
943
955
|
i18n: i18n,
|
|
944
956
|
defaultNS: defaultNS
|
|
945
957
|
};
|
|
946
958
|
}, [i18n, defaultNS]);
|
|
947
|
-
return
|
|
959
|
+
return react.createElement(I18nContext.Provider, {
|
|
948
960
|
value: value
|
|
949
961
|
}, children);
|
|
950
962
|
}
|
|
@@ -953,7 +965,7 @@
|
|
|
953
965
|
var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
954
966
|
var i18nFromProps = props.i18n;
|
|
955
967
|
|
|
956
|
-
var _ref =
|
|
968
|
+
var _ref = react.useContext(I18nContext) || {},
|
|
957
969
|
i18nFromContext = _ref.i18n;
|
|
958
970
|
|
|
959
971
|
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
@@ -986,7 +998,7 @@
|
|
|
986
998
|
rest = _objectWithoutProperties(_ref, _excluded$3);
|
|
987
999
|
|
|
988
1000
|
useSSR(initialI18nStore, initialLanguage);
|
|
989
|
-
return
|
|
1001
|
+
return react.createElement(WrappedComponent, _objectSpread2({}, rest));
|
|
990
1002
|
}
|
|
991
1003
|
|
|
992
1004
|
I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
|
package/react-i18next.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";var t="default"in n?n.default:n;function r(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function a(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?r(Object(t),!0).forEach((function(n){c(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):r(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function c(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function s(e,n){if(null==e)return{};var t,r,a=function(e,n){if(null==e)return{};var t,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}function u(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==t)return;var r,a,i=[],o=!0,c=!1;try{for(t=t.call(e);!(o=(r=t.next()).done)&&(i.push(r.value),!n||i.length!==n);o=!0);}catch(e){c=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(c)throw a}}return i}(e,n)||function(e,n){if(!e)return;if("string"==typeof e)return l(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return l(e,n)}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var f={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},p=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function d(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(f[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var a=new RegExp(p),i=null;null!==(i=a.exec(e));)if(i[0].trim())if(i[1]){var o=i[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],a.lastIndex--}else i[2]&&(n.attrs[i[2]]=i[3].trim().substring(1,i[3].length-1));return n}var g=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,m=/^\s*$/,h=Object.create(null);var v=function(e,n){n||(n={}),n.components||(n.components=h);var t,r=[],a=[],i=-1,o=!1;if(0!==e.indexOf("<")){var c=e.indexOf("<");r.push({type:"text",content:-1===c?e:e.substring(0,c)})}return e.replace(g,(function(c,s){if(o){if(c!=="</"+t.name+">")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),p=s+c.length,g=e.charAt(p);if(f){var h=d(c);return i<0?(r.push(h),r):((u=a[i]).children.push(h),r)}if(l&&(i++,"tag"===(t=d(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!g||"<"===g||t.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===i&&r.push(t),(u=a[i-1])&&u.children.push(t),a[i]=t),(!l||t.voidElement)&&(i>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(i--,t=-1===i?r:a[i]),!o&&"<"!==g&&g)){u=-1===i?r:a[i].children;var v=e.indexOf("<",p),y=e.slice(p,-1===v?void 0:v);m.test(y)&&(y=" "),(v>-1&&i+u.length>=0||" "!==y)&&u.push({type:"text",content:y})}})),r},y="".replace,b=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,O={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'};function x(e){return O[e]}var w,j={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},S=t.createContext();function E(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};j=a(a({},j),e)}function N(){return j}var k=function(){function e(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.usedNamespaces={}}var n,t,r;return n=e,(t=[{key:"addUsedNamespaces",value:function(e){var n=this;e.forEach((function(e){n.usedNamespaces[e]||(n.usedNamespaces[e]=!0)}))}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}])&&o(n.prototype,t),r&&o(n,r),e}();function I(e){w=e}function P(){return w}var R={type:"3rdParty",init:function(e){E(e.options.react),I(e)}};function C(e){return function(n){return new Promise((function(t){var r=T();e.getInitialProps?e.getInitialProps(n).then((function(e){t(a(a({},e),r))})):t(r)}))}}function T(){var e=P(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},r={};return e.languages.forEach((function(t){r[t]={},n.forEach((function(n){r[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=r,t.initialLanguage=e.language,t}function A(){if(console&&console.warn){for(var e,n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];"string"==typeof t[0]&&(t[0]="react-i18next:: ".concat(t[0])),(e=console).warn.apply(e,t)}}var L={};function z(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&L[n[0]]||("string"==typeof n[0]&&(L[n[0]]=new Date),A.apply(void 0,n))}function B(e,n,t){e.loadNamespaces(n,(function(){if(e.isInitialized)t();else{e.on("initialized",(function n(){setTimeout((function(){e.off("initialized",n)}),0),t()}))}}))}function U(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.languages[0],a=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===r.toLowerCase())return!0;var o=function(e,t){var r=n.services.backendConnector.state["".concat(e,"|").concat(t)];return-1===r||2===r};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e))&&(!!n.hasResourceBundle(r,e)||(!(n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages))||!(!o(r,e)||a&&!o(i,e))))}function D(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return z("i18n.languages were undefined or empty",n.languages),!0;var r=void 0!==n.options.ignoreJSONStructure;return r?n.hasLoadedNamespace(e,{precheck:function(n,r){if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!r(n.isLanguageChangingTo,e))return!1}}):U(e,n,t)}function H(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}var K=["format"],V=["children","count","parent","i18nKey","context","tOptions","values","defaults","components","ns","i18n","t","shouldUnescape"];function F(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function W(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function M(e){return Array.isArray(e)?e:[e]}function $(e,n,r,o,c,s){if(""===n)return[];var u=o.transKeepBasicHtmlNodesFor||[],l=n&&new RegExp(u.join("|")).test(n);if(!e&&!l)return[n];var f={};!function e(n){M(n).forEach((function(n){"string"!=typeof n&&(F(n)?e(W(n)):"object"!==i(n)||t.isValidElement(n)||Object.assign(f,n))}))}(e);var p=v("<0>".concat(n,"</0>")),d=a(a({},f),c);function g(e,n,r){var a=W(e),i=h(a,n.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(a)&&0===i.length?a:i}function m(e,n,r,i,o){e.dummy&&(e.children=n),r.push(t.cloneElement(e,a(a({},e.props),{},{key:i}),o?void 0:n))}function h(n,c,f){var p=M(n);return M(c).reduce((function(n,c,v){var O,w,j,S,E=c.children&&c.children[0]&&c.children[0].content&&r.services.interpolator.interpolate(c.children[0].content,d,r.language);if("tag"===c.type){var N=p[parseInt(c.name,10)];!N&&1===f.length&&f[0][c.name]&&(N=f[0][c.name]),N||(N={});var k=0!==Object.keys(c.attrs).length?(w={props:c.attrs},(S=a({},j=N)).props=Object.assign(w.props,j.props),S):N,I=t.isValidElement(k),P=I&&F(c,!0)&&!c.voidElement,R=l&&"object"===i(k)&&k.dummy&&!I,C="object"===i(e)&&null!==e&&Object.hasOwnProperty.call(e,c.name);if("string"==typeof k){var T=r.services.interpolator.interpolate(k,d,r.language);n.push(T)}else if(F(k)||P){m(k,g(k,c,f),n,v)}else if(R){var A=h(p,c.children,f);n.push(t.cloneElement(k,a(a({},k.props),{},{key:v}),A))}else if(Number.isNaN(parseFloat(c.name))){if(C)m(k,g(k,c,f),n,v,c.voidElement);else if(o.transSupportBasicHtmlNodes&&u.indexOf(c.name)>-1)if(c.voidElement)n.push(t.createElement(c.name,{key:"".concat(c.name,"-").concat(v)}));else{var L=h(p,c.children,f);n.push(t.createElement(c.name,{key:"".concat(c.name,"-").concat(v)},L))}else if(c.voidElement)n.push("<".concat(c.name," />"));else{var z=h(p,c.children,f);n.push("<".concat(c.name,">").concat(z,"</").concat(c.name,">"))}}else if("object"!==i(k)||I)1===c.children.length&&E?n.push(t.cloneElement(k,a(a({},k.props),{},{key:v}),E)):n.push(t.cloneElement(k,a(a({},k.props),{},{key:v})));else{var B=c.children[0]?E:null;B&&n.push(B)}}else if("text"===c.type){var U=o.transWrapTextNodes,D=s?(O=r.services.interpolator.interpolate(c.content,d,r.language),y.call(O,b,x)):r.services.interpolator.interpolate(c.content,d,r.language);U?n.push(t.createElement(U,{key:"".concat(c.name,"-").concat(v)},D)):n.push(D)}return n}),[])}return W(h([{dummy:!0,children:e||[]}],p,M(e||[]))[0])}function q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,i=n.useContext(S)||{},o=i.i18n,c=i.defaultNS,s=r||o||P();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new k),!s){z("You will need to pass in an i18next instance by using initReactI18next");var l=function(e){return Array.isArray(e)?e[e.length-1]:e},f=[l,{},!1];return f.t=l,f.i18n={},f.ready=!1,f}s.options.react&&void 0!==s.options.react.wait&&z("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=a(a(a({},N()),s.options.react),t),d=p.useSuspense,g=p.keyPrefix,m=e||c||s.options&&s.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(m);var h=(s.isInitialized||s.initializedStoreOnce)&&m.every((function(e){return D(e,s,p)}));function v(){return s.getFixedT(null,"fallback"===p.nsMode?m:m[0],g)}var y=n.useState(v),b=u(y,2),O=b[0],x=b[1],w=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){w.current&&x(v)}return w.current=!0,h||d||B(s,m,(function(){w.current&&x(v)})),e&&s&&s.on(e,t),n&&s&&s.store.on(n,t),function(){w.current=!1,e&&s&&e.split(" ").forEach((function(e){return s.off(e,t)})),n&&s&&n.split(" ").forEach((function(e){return s.store.off(e,t)}))}}),[s,m.join()]);var j=n.useRef(!0);n.useEffect((function(){w.current&&!j.current&&x(v),j.current=!1}),[s]);var E=[O,s,h];if(E.t=O,E.i18n=s,E.ready=h,h)return E;if(!h&&!d)return E;throw new Promise((function(e){B(s,m,(function(){e()}))}))}var Y=["forwardedRef"];var _=["ns","children"];function J(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=r.i18n,i=n.useContext(S)||{},o=i.i18n,c=a||o||P();c.options&&c.options.isClone||(e&&!c.initializedStoreOnce&&(c.services.resourceStore.data=e,c.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),c.options.ns),c.initializedStoreOnce=!0,c.isInitialized=!0),t&&!c.initializedLanguageOnce&&(c.changeLanguage(t),c.initializedLanguageOnce=!0))}var Z=["initialI18nStore","initialLanguage"];e.I18nContext=S,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,a=e.children,i=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(S.Provider,{value:i},a)},e.Trans=function(e){var r=e.children,o=e.count,c=e.parent,u=e.i18nKey,l=e.context,f=e.tOptions,p=void 0===f?{}:f,d=e.values,g=e.defaults,m=e.components,h=e.ns,v=e.i18n,y=e.t,b=e.shouldUnescape,O=s(e,V),x=n.useContext(S)||{},w=x.i18n,j=x.defaultNS,E=v||w||P();if(!E)return z("You will need to pass in an i18next instance by using i18nextReactModule"),r;var k=y||E.t.bind(E)||function(e){return e};l&&(p.context=l);var I=a(a({},N()),E.options&&E.options.react),R=h||k.ns||j||E.options&&E.options.defaultNS;R="string"==typeof R?[R]:R||["translation"];var C=g||function e(n,r){if(!n)return"";var a="",o=M(n),c=r.transSupportBasicHtmlNodes&&r.transKeepBasicHtmlNodesFor?r.transKeepBasicHtmlNodesFor:[];return o.forEach((function(n,o){if("string"==typeof n)a+="".concat(n);else if(t.isValidElement(n)){var u=Object.keys(n.props).length,l=c.indexOf(n.type)>-1,f=n.props.children;if(!f&&l&&0===u)a+="<".concat(n.type,"/>");else if(f||l&&0===u)if(n.props.i18nIsDynamicList)a+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)a+="<".concat(n.type,">").concat(f,"</").concat(n.type,">");else{var p=e(f,r);a+="<".concat(o,">").concat(p,"</").concat(o,">")}else a+="<".concat(o,"></").concat(o,">")}else if(null===n)A("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===i(n)){var d=n.format,g=s(n,K),m=Object.keys(g);if(1===m.length){var h=d?"".concat(m[0],", ").concat(d):m[0];a+="{{".concat(h,"}}")}else A("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else A("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}}.",n)})),a}(r,I)||I.transEmptyNodeValue||u,T=I.hashTransKey,L=u||(T?T(C):C),B=d?p.interpolation:{interpolation:a(a({},p.interpolation),{},{prefix:"#$?",suffix:"?$#"})},U=a(a(a(a({},p),{},{count:o},d),B),{},{defaultValue:C,ns:R}),D=$(m||r,L?k(L,U):C,E,I,U,b),H=void 0!==c?c:I.defaultTransParent;return H?t.createElement(H,O,D):D},e.Translation=function(e){var n=e.ns,t=e.children,r=u(q(n,s(e,_)),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=C,e.date=function(){return""},e.getDefaults=N,e.getI18n=P,e.getInitialProps=T,e.initReactI18next=R,e.number=function(){return""},e.plural=function(){return""},e.select=function(){return""},e.selectOrdinal=function(){return""},e.setDefaults=E,e.setI18n=I,e.time=function(){return""},e.useSSR=J,e.useTranslation=q,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,i=n.initialLanguage,o=s(n,Z);return J(r,i),t.createElement(e,a({},o))}return n.getInitialProps=C(e),n.displayName="withI18nextSSR(".concat(H(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function i(i){var o=i.forwardedRef,c=s(i,Y),l=u(q(e,a(a({},c),{},{keyPrefix:n.keyPrefix})),3),f=l[0],p=l[1],d=l[2],g=a(a({},c),{},{t:f,i18n:p,tReady:d});return n.withRef&&o?g.ref=o:!n.withRef&&o&&(g.forwardedRef=o),t.createElement(r,g)}i.displayName="withI18nextTranslation(".concat(H(r),")"),i.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(i,Object.assign({},e,{forwardedRef:n}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).ReactI18next={},e.react)}(this,(function(e,n){"use strict";function t(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function r(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?t(Object(r),!0).forEach((function(n){o(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))}))}return e}function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function c(e,n){if(null==e)return{};var t,r,a=function(e,n){if(null==e)return{};var t,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}function s(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==t)return;var r,a,i=[],o=!0,c=!1;try{for(t=t.call(e);!(o=(r=t.next()).done)&&(i.push(r.value),!n||i.length!==n);o=!0);}catch(e){c=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(c)throw a}}return i}(e,n)||function(e,n){if(!e)return;if("string"==typeof e)return u(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return u(e,n)}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function p(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(l[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var a=new RegExp(f),i=null;null!==(i=a.exec(e));)if(i[0].trim())if(i[1]){var o=i[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],a.lastIndex--}else i[2]&&(n.attrs[i[2]]=i[3].trim().substring(1,i[3].length-1));return n}var d=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,g=/^\s*$/,m=Object.create(null);var h=function(e,n){n||(n={}),n.components||(n.components=m);var t,r=[],a=[],i=-1,o=!1;if(0!==e.indexOf("<")){var c=e.indexOf("<");r.push({type:"text",content:-1===c?e:e.substring(0,c)})}return e.replace(d,(function(c,s){if(o){if(c!=="</"+t.name+">")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),d=s+c.length,m=e.charAt(d);if(f){var h=p(c);return i<0?(r.push(h),r):((u=a[i]).children.push(h),r)}if(l&&(i++,"tag"===(t=p(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(d,e.indexOf("<",d))}),0===i&&r.push(t),(u=a[i-1])&&u.children.push(t),a[i]=t),(!l||t.voidElement)&&(i>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(i--,t=-1===i?r:a[i]),!o&&"<"!==m&&m)){u=-1===i?r:a[i].children;var v=e.indexOf("<",d),y=e.slice(d,-1===v?void 0:v);g.test(y)&&(y=" "),(v>-1&&i+u.length>=0||" "!==y)&&u.push({type:"text",content:y})}})),r},v="".replace,y=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'};function O(e){return b[e]}var x,w={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},j=n.createContext();function E(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w=r(r({},w),e)}function S(){return w}var N=function(){function e(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.usedNamespaces={}}var n,t,r;return n=e,(t=[{key:"addUsedNamespaces",value:function(e){var n=this;e.forEach((function(e){n.usedNamespaces[e]||(n.usedNamespaces[e]=!0)}))}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}])&&i(n.prototype,t),r&&i(n,r),e}();function k(e){x=e}function I(){return x}var P={type:"3rdParty",init:function(e){E(e.options.react),k(e)}};function R(e){return function(n){return new Promise((function(t){var a=C();e.getInitialProps?e.getInitialProps(n).then((function(e){t(r(r({},e),a))})):t(a)}))}}function C(){var e=I(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},r={};return e.languages.forEach((function(t){r[t]={},n.forEach((function(n){r[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=r,t.initialLanguage=e.language,t}function T(){if(console&&console.warn){for(var e,n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];"string"==typeof t[0]&&(t[0]="react-i18next:: ".concat(t[0])),(e=console).warn.apply(e,t)}}var A={};function L(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&A[n[0]]||("string"==typeof n[0]&&(A[n[0]]=new Date),T.apply(void 0,n))}function z(e,n,t){e.loadNamespaces(n,(function(){if(e.isInitialized)t();else{e.on("initialized",(function n(){setTimeout((function(){e.off("initialized",n)}),0),t()}))}}))}function B(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.languages[0],a=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===r.toLowerCase())return!0;var o=function(e,t){var r=n.services.backendConnector.state["".concat(e,"|").concat(t)];return-1===r||2===r};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e))&&(!!n.hasResourceBundle(r,e)||(!(n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages))||!(!o(r,e)||a&&!o(i,e))))}function U(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return L("i18n.languages were undefined or empty",n.languages),!0;var r=void 0!==n.options.ignoreJSONStructure;return r?n.hasLoadedNamespace(e,{precheck:function(n,r){if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!r(n.isLanguageChangingTo,e))return!1}}):B(e,n,t)}function D(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}var H=["format"],K=["children","count","parent","i18nKey","context","tOptions","values","defaults","components","ns","i18n","t","shouldUnescape"];function V(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function F(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function W(e){return Array.isArray(e)?e:[e]}function M(e,t,i,o,c,s){if(""===t)return[];var u=o.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(u.join("|")).test(t);if(!e&&!l)return[t];var f={};!function e(t){W(t).forEach((function(t){"string"!=typeof t&&(V(t)?e(F(t)):"object"!==a(t)||n.isValidElement(t)||Object.assign(f,t))}))}(e);var p=h("<0>".concat(t,"</0>")),d=r(r({},f),c);function g(e,t,r){var a=F(e),i=b(a,t.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return n.isValidElement(e)}))}(a)&&0===i.length?a:i}function m(e,t,a,i,o){e.dummy&&(e.children=t),a.push(n.cloneElement(e,r(r({},e.props),{},{key:i}),o?void 0:t))}function b(t,c,f){var p=W(t);return W(c).reduce((function(t,c,h){var x,w,j,E,S=c.children&&c.children[0]&&c.children[0].content&&i.services.interpolator.interpolate(c.children[0].content,d,i.language);if("tag"===c.type){var N=p[parseInt(c.name,10)];!N&&1===f.length&&f[0][c.name]&&(N=f[0][c.name]),N||(N={});var k=0!==Object.keys(c.attrs).length?(w={props:c.attrs},(E=r({},j=N)).props=Object.assign(w.props,j.props),E):N,I=n.isValidElement(k),P=I&&V(c,!0)&&!c.voidElement,R=l&&"object"===a(k)&&k.dummy&&!I,C="object"===a(e)&&null!==e&&Object.hasOwnProperty.call(e,c.name);if("string"==typeof k){var T=i.services.interpolator.interpolate(k,d,i.language);t.push(T)}else if(V(k)||P){m(k,g(k,c,f),t,h)}else if(R){var A=b(p,c.children,f);t.push(n.cloneElement(k,r(r({},k.props),{},{key:h}),A))}else if(Number.isNaN(parseFloat(c.name))){if(C)m(k,g(k,c,f),t,h,c.voidElement);else if(o.transSupportBasicHtmlNodes&&u.indexOf(c.name)>-1)if(c.voidElement)t.push(n.createElement(c.name,{key:"".concat(c.name,"-").concat(h)}));else{var L=b(p,c.children,f);t.push(n.createElement(c.name,{key:"".concat(c.name,"-").concat(h)},L))}else if(c.voidElement)t.push("<".concat(c.name," />"));else{var z=b(p,c.children,f);t.push("<".concat(c.name,">").concat(z,"</").concat(c.name,">"))}}else if("object"!==a(k)||I)1===c.children.length&&S?t.push(n.cloneElement(k,r(r({},k.props),{},{key:h}),S)):t.push(n.cloneElement(k,r(r({},k.props),{},{key:h})));else{var B=c.children[0]?S:null;B&&t.push(B)}}else if("text"===c.type){var U=o.transWrapTextNodes,D=s?(x=i.services.interpolator.interpolate(c.content,d,i.language),v.call(x,y,O)):i.services.interpolator.interpolate(c.content,d,i.language);U?t.push(n.createElement(U,{key:"".concat(c.name,"-").concat(h)},D)):t.push(D)}return t}),[])}return F(b([{dummy:!0,children:e||[]}],p,W(e||[]))[0])}var $=function(e,t){var r=n.useRef();return n.useEffect((function(){r.current=t?r.current:e}),[e,t]),r.current};function q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=t.i18n,i=n.useContext(j)||{},o=i.i18n,c=i.defaultNS,u=a||o||I();if(u&&!u.reportNamespaces&&(u.reportNamespaces=new N),!u){L("You will need to pass in an i18next instance by using initReactI18next");var l=function(e){return Array.isArray(e)?e[e.length-1]:e},f=[l,{},!1];return f.t=l,f.i18n={},f.ready=!1,f}u.options.react&&void 0!==u.options.react.wait&&L("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=r(r(r({},S()),u.options.react),t),d=p.useSuspense,g=p.keyPrefix,m=e||c||u.options&&u.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],u.reportNamespaces.addUsedNamespaces&&u.reportNamespaces.addUsedNamespaces(m);var h=(u.isInitialized||u.initializedStoreOnce)&&m.every((function(e){return U(e,u,p)}));function v(){return u.getFixedT(null,"fallback"===p.nsMode?m:m[0],g)}var y=n.useState(v),b=s(y,2),O=b[0],x=b[1],w=m.join(),E=$(w),k=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){k.current&&x(v)}return k.current=!0,h||d||z(u,m,(function(){k.current&&x(v)})),h&&E&&E!==w&&k.current&&x(v),e&&u&&u.on(e,t),n&&u&&u.store.on(n,t),function(){k.current=!1,e&&u&&e.split(" ").forEach((function(e){return u.off(e,t)})),n&&u&&n.split(" ").forEach((function(e){return u.store.off(e,t)}))}}),[u,w]);var P=n.useRef(!0);n.useEffect((function(){k.current&&!P.current&&x(v),P.current=!1}),[u]);var R=[O,u,h];if(R.t=O,R.i18n=u,R.ready=h,h)return R;if(!h&&!d)return R;throw new Promise((function(e){z(u,m,(function(){e()}))}))}var Y=["forwardedRef"];var _=["ns","children"];function J(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=r.i18n,i=n.useContext(j)||{},o=i.i18n,c=a||o||I();c.options&&c.options.isClone||(e&&!c.initializedStoreOnce&&(c.services.resourceStore.data=e,c.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),c.options.ns),c.initializedStoreOnce=!0,c.isInitialized=!0),t&&!c.initializedLanguageOnce&&(c.changeLanguage(t),c.initializedLanguageOnce=!0))}var Z=["initialI18nStore","initialLanguage"];e.I18nContext=j,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,a=e.children,i=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(j.Provider,{value:i},a)},e.Trans=function(e){var t=e.children,i=e.count,o=e.parent,s=e.i18nKey,u=e.context,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,g=e.components,m=e.ns,h=e.i18n,v=e.t,y=e.shouldUnescape,b=c(e,K),O=n.useContext(j)||{},x=O.i18n,w=O.defaultNS,E=h||x||I();if(!E)return L("You will need to pass in an i18next instance by using i18nextReactModule"),t;var N=v||E.t.bind(E)||function(e){return e};u&&(f.context=u);var k=r(r({},S()),E.options&&E.options.react),P=m||N.ns||w||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];var R=d||function e(t,r){if(!t)return"";var i="",o=W(t),s=r.transSupportBasicHtmlNodes&&r.transKeepBasicHtmlNodesFor?r.transKeepBasicHtmlNodesFor:[];return o.forEach((function(t,o){if("string"==typeof t)i+="".concat(t);else if(n.isValidElement(t)){var u=Object.keys(t.props).length,l=s.indexOf(t.type)>-1,f=t.props.children;if(!f&&l&&0===u)i+="<".concat(t.type,"/>");else if(f||l&&0===u)if(t.props.i18nIsDynamicList)i+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)i+="<".concat(t.type,">").concat(f,"</").concat(t.type,">");else{var p=e(f,r);i+="<".concat(o,">").concat(p,"</").concat(o,">")}else i+="<".concat(o,"></").concat(o,">")}else if(null===t)T("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===a(t)){var d=t.format,g=c(t,H),m=Object.keys(g);if(1===m.length){var h=d?"".concat(m[0],", ").concat(d):m[0];i+="{{".concat(h,"}}")}else T("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",t)}else T("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}}.",t)})),i}(t,k)||k.transEmptyNodeValue||s,C=k.hashTransKey,A=s||(C?C(R):R),z=p?f.interpolation:{interpolation:r(r({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},B=r(r(r(r({},f),{},{count:i},p),z),{},{defaultValue:R,ns:P}),U=M(g||t,A?N(A,B):R,E,k,B,y),D=void 0!==o?o:k.defaultTransParent;return D?n.createElement(D,b,U):U},e.Translation=function(e){var n=e.ns,t=e.children,r=s(q(n,c(e,_)),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=R,e.date=function(){return""},e.getDefaults=S,e.getI18n=I,e.getInitialProps=C,e.initReactI18next=P,e.number=function(){return""},e.plural=function(){return""},e.select=function(){return""},e.selectOrdinal=function(){return""},e.setDefaults=E,e.setI18n=k,e.time=function(){return""},e.useSSR=J,e.useTranslation=q,e.withSSR=function(){return function(e){function t(t){var a=t.initialI18nStore,i=t.initialLanguage,o=c(t,Z);return J(a,i),n.createElement(e,r({},o))}return t.getInitialProps=R(e),t.displayName="withI18nextSSR(".concat(D(e),")"),t.WrappedComponent=e,t}},e.withTranslation=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(a){function i(i){var o=i.forwardedRef,u=c(i,Y),l=s(q(e,r(r({},u),{},{keyPrefix:t.keyPrefix})),3),f=l[0],p=l[1],d=l[2],g=r(r({},u),{},{t:f,i18n:p,tReady:d});return t.withRef&&o?g.ref=o:!t.withRef&&o&&(g.forwardedRef=o),n.createElement(a,g)}i.displayName="withI18nextTranslation(".concat(D(a),")"),i.WrappedComponent=a;return t.withRef?n.forwardRef((function(e,t){return n.createElement(i,Object.assign({},e,{forwardedRef:t}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/src/Trans.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useContext, isValidElement, cloneElement, createElement } from 'react';
|
|
2
2
|
import HTML from 'html-parse-stringify';
|
|
3
3
|
import { unescape } from 'html-escaper';
|
|
4
4
|
import { getI18n, I18nContext, getDefaults } from './context';
|
|
@@ -18,7 +18,7 @@ function getChildren(node) {
|
|
|
18
18
|
|
|
19
19
|
function hasValidReactChildren(children) {
|
|
20
20
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
21
|
-
return children.every((child) =>
|
|
21
|
+
return children.every((child) => isValidElement(child));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function getAsArray(data) {
|
|
@@ -49,7 +49,7 @@ export function nodesToString(children, i18nOptions) {
|
|
|
49
49
|
// actual e.g. lorem
|
|
50
50
|
// expected e.g. lorem
|
|
51
51
|
stringNode += `${child}`;
|
|
52
|
-
} else if (
|
|
52
|
+
} else if (isValidElement(child)) {
|
|
53
53
|
const childPropsCount = Object.keys(child.props).length;
|
|
54
54
|
const shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
55
55
|
const childChildren = child.props.children;
|
|
@@ -124,7 +124,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
124
124
|
childrenArray.forEach((child) => {
|
|
125
125
|
if (typeof child === 'string') return;
|
|
126
126
|
if (hasChildren(child)) getData(getChildren(child));
|
|
127
|
-
else if (typeof child === 'object' && !
|
|
127
|
+
else if (typeof child === 'object' && !isValidElement(child))
|
|
128
128
|
Object.assign(data, child);
|
|
129
129
|
});
|
|
130
130
|
}
|
|
@@ -145,7 +145,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
145
145
|
|
|
146
146
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
147
147
|
if (child.dummy) child.children = inner; // needed on preact!
|
|
148
|
-
mem.push(
|
|
148
|
+
mem.push(cloneElement(child, { ...child.props, key: i }, isVoid ? undefined : inner));
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// reactNode (the jsx root element or child)
|
|
@@ -171,7 +171,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
171
171
|
const child =
|
|
172
172
|
Object.keys(node.attrs).length !== 0 ? mergeProps({ props: node.attrs }, tmp) : tmp;
|
|
173
173
|
|
|
174
|
-
const isElement =
|
|
174
|
+
const isElement = isValidElement(child);
|
|
175
175
|
|
|
176
176
|
const isValidTranslationWithChildren =
|
|
177
177
|
isElement && hasChildren(node, true) && !node.voidElement;
|
|
@@ -203,14 +203,14 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
203
203
|
node.children,
|
|
204
204
|
rootReactNode,
|
|
205
205
|
);
|
|
206
|
-
mem.push(
|
|
206
|
+
mem.push(cloneElement(child, { ...child.props, key: i }, inner));
|
|
207
207
|
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
208
208
|
if (isKnownComponent) {
|
|
209
209
|
const inner = renderInner(child, node, rootReactNode);
|
|
210
210
|
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
211
211
|
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
212
212
|
if (node.voidElement) {
|
|
213
|
-
mem.push(
|
|
213
|
+
mem.push(createElement(node.name, { key: `${node.name}-${i}` }));
|
|
214
214
|
} else {
|
|
215
215
|
const inner = mapAST(
|
|
216
216
|
reactNodes /* wrong but we need something */,
|
|
@@ -218,7 +218,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
218
218
|
rootReactNode,
|
|
219
219
|
);
|
|
220
220
|
|
|
221
|
-
mem.push(
|
|
221
|
+
mem.push(createElement(node.name, { key: `${node.name}-${i}` }, inner));
|
|
222
222
|
}
|
|
223
223
|
} else if (node.voidElement) {
|
|
224
224
|
mem.push(`<${node.name} />`);
|
|
@@ -242,9 +242,9 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
242
242
|
} else if (node.children.length === 1 && translationContent) {
|
|
243
243
|
// If component does not have children, but translation - has
|
|
244
244
|
// with this in component could be components={[<span class='make-beautiful'/>]} and in translation - 'some text <0>some highlighted message</0>'
|
|
245
|
-
mem.push(
|
|
245
|
+
mem.push(cloneElement(child, { ...child.props, key: i }, translationContent));
|
|
246
246
|
} else {
|
|
247
|
-
mem.push(
|
|
247
|
+
mem.push(cloneElement(child, { ...child.props, key: i }));
|
|
248
248
|
}
|
|
249
249
|
} else if (node.type === 'text') {
|
|
250
250
|
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
@@ -252,7 +252,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
252
252
|
? unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language))
|
|
253
253
|
: i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
254
254
|
if (wrapTextNodes) {
|
|
255
|
-
mem.push(
|
|
255
|
+
mem.push(createElement(wrapTextNodes, { key: `${node.name}-${i}` }, content));
|
|
256
256
|
} else {
|
|
257
257
|
mem.push(content);
|
|
258
258
|
}
|
|
@@ -339,5 +339,5 @@ export function Trans({
|
|
|
339
339
|
// and override `defaultTransParent` if is present
|
|
340
340
|
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
341
341
|
|
|
342
|
-
return useAsParent ?
|
|
342
|
+
return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
|
|
343
343
|
}
|
package/src/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext } from 'react';
|
|
2
2
|
|
|
3
3
|
let defaultOptions = {
|
|
4
4
|
bindI18n: 'languageChanged',
|
|
@@ -14,7 +14,7 @@ let defaultOptions = {
|
|
|
14
14
|
|
|
15
15
|
let i18nInstance;
|
|
16
16
|
|
|
17
|
-
export const I18nContext =
|
|
17
|
+
export const I18nContext = createContext();
|
|
18
18
|
|
|
19
19
|
export function setDefaults(options = {}) {
|
|
20
20
|
defaultOptions = { ...defaultOptions, ...options };
|
package/src/useTranslation.js
CHANGED
|
@@ -2,6 +2,14 @@ import { useState, useEffect, useContext, useRef } from 'react';
|
|
|
2
2
|
import { getI18n, getDefaults, ReportNamespaces, I18nContext } from './context';
|
|
3
3
|
import { warnOnce, loadNamespaces, hasLoadedNamespace } from './utils';
|
|
4
4
|
|
|
5
|
+
const usePrevious = (value, ignore) => {
|
|
6
|
+
const ref = useRef();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
ref.current = ignore ? ref.current : value;
|
|
9
|
+
}, [value, ignore]);
|
|
10
|
+
return ref.current;
|
|
11
|
+
};
|
|
12
|
+
|
|
5
13
|
export function useTranslation(ns, props = {}) {
|
|
6
14
|
// assert we have the needed i18nInstance
|
|
7
15
|
const { i18n: i18nFromProps } = props;
|
|
@@ -48,6 +56,9 @@ export function useTranslation(ns, props = {}) {
|
|
|
48
56
|
}
|
|
49
57
|
const [t, setT] = useState(getT);
|
|
50
58
|
|
|
59
|
+
const joinedNS = namespaces.join();
|
|
60
|
+
const previousJoinedNS = usePrevious(joinedNS);
|
|
61
|
+
|
|
51
62
|
const isMounted = useRef(true);
|
|
52
63
|
useEffect(() => {
|
|
53
64
|
const { bindI18n, bindI18nStore } = i18nOptions;
|
|
@@ -61,6 +72,10 @@ export function useTranslation(ns, props = {}) {
|
|
|
61
72
|
});
|
|
62
73
|
}
|
|
63
74
|
|
|
75
|
+
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
76
|
+
setT(getT);
|
|
77
|
+
}
|
|
78
|
+
|
|
64
79
|
function boundReset() {
|
|
65
80
|
if (isMounted.current) setT(getT);
|
|
66
81
|
}
|
|
@@ -76,7 +91,7 @@ export function useTranslation(ns, props = {}) {
|
|
|
76
91
|
if (bindI18nStore && i18n)
|
|
77
92
|
bindI18nStore.split(' ').forEach((e) => i18n.store.off(e, boundReset));
|
|
78
93
|
};
|
|
79
|
-
}, [i18n,
|
|
94
|
+
}, [i18n, joinedNS]); // re-run effect whenever list of namespaces changes
|
|
80
95
|
|
|
81
96
|
// t is correctly initialized by useState hook. We only need to update it after i18n
|
|
82
97
|
// instance was replaced (for example in the provider).
|
package/src/withSSR.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createElement } from 'react';
|
|
2
2
|
import { useSSR } from './useSSR';
|
|
3
3
|
import { composeInitialProps } from './context';
|
|
4
4
|
import { getDisplayName } from './utils';
|
|
@@ -8,7 +8,7 @@ export function withSSR() {
|
|
|
8
8
|
function I18nextWithSSR({ initialI18nStore, initialLanguage, ...rest }) {
|
|
9
9
|
useSSR(initialI18nStore, initialLanguage);
|
|
10
10
|
|
|
11
|
-
return
|
|
11
|
+
return createElement(WrappedComponent, {
|
|
12
12
|
...rest,
|
|
13
13
|
});
|
|
14
14
|
}
|
package/src/withTranslation.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createElement, forwardRef as forwardRefReact } from 'react';
|
|
2
2
|
import { useTranslation } from './useTranslation';
|
|
3
3
|
import { getDisplayName } from './utils';
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ export function withTranslation(ns, options = {}) {
|
|
|
18
18
|
} else if (!options.withRef && forwardedRef) {
|
|
19
19
|
passDownProps.forwardedRef = forwardedRef;
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return createElement(WrappedComponent, passDownProps);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(
|
|
@@ -28,8 +28,8 @@ export function withTranslation(ns, options = {}) {
|
|
|
28
28
|
I18nextWithTranslation.WrappedComponent = WrappedComponent;
|
|
29
29
|
|
|
30
30
|
const forwardRef = (props, ref) =>
|
|
31
|
-
|
|
31
|
+
createElement(I18nextWithTranslation, Object.assign({}, props, { forwardedRef: ref }));
|
|
32
32
|
|
|
33
|
-
return options.withRef ?
|
|
33
|
+
return options.withRef ? forwardRefReact(forwardRef) : I18nextWithTranslation;
|
|
34
34
|
};
|
|
35
35
|
}
|
package/ts4.1/index.d.ts
CHANGED
|
@@ -264,7 +264,7 @@ export type TransProps<
|
|
|
264
264
|
E = React.HTMLProps<HTMLDivElement>
|
|
265
265
|
> = E & {
|
|
266
266
|
children?: TransChild | TransChild[];
|
|
267
|
-
components?: readonly React.
|
|
267
|
+
components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement };
|
|
268
268
|
count?: number;
|
|
269
269
|
context?: string;
|
|
270
270
|
defaults?: string;
|