react-i18next 11.3.3 → 11.3.4
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 +4 -0
- package/README.md +4 -4
- package/dist/amd/react-i18next.js +7 -6
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/useTranslation.js +7 -6
- package/dist/es/useTranslation.js +8 -7
- package/dist/umd/react-i18next.js +7 -6
- package/dist/umd/react-i18next.min.js +1 -1
- package/package.json +3 -2
- package/react-i18next.js +7 -6
- package/react-i18next.min.js +1 -1
- package/src/useTranslation.js +7 -6
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -73,12 +73,12 @@ Head over to the **interactive playground** at [codesandbox](https://codesandbox
|
|
|
73
73
|
- [Building i18n with Gatsby](https://www.gatsbyjs.org/blog/2017-10-17-building-i18n-with-gatsby/) via gatsbyjs.org by Samuel Goudie
|
|
74
74
|
- [Get your react.js application translated with style](https://medium.com/@jamuhl/get-your-react-js-application-translated-with-style-4ad090aefc2c) by Jan Mühlemann
|
|
75
75
|
- [Translate your expo.io / react-native mobile application](https://medium.com/@jamuhl/translate-your-expo-io-react-native-mobile-application-aa220b2362d2) by Jan Mühlemann
|
|
76
|
-
-
|
|
76
|
+
- You're welcome to share your story...
|
|
77
77
|
|
|
78
78
|
### Why i18next?
|
|
79
79
|
|
|
80
|
-
- **Simplicity:** no need to change your webpack configuration or
|
|
81
|
-
- **Production ready** we know there are more needs for production than just doing i18n on the clientside
|
|
80
|
+
- **Simplicity:** no need to change your webpack configuration or add additional babel transpilers, just use create-react-app and go.
|
|
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
|
<img src="https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-L9iS6Wm2hynS5H9Gj7j%2F-L9iS7LlT2W7wFtJH-2n%2F-L9iSBP9U65-bHJBRSDv%2Fi18next-ecosystem.jpg?generation=1523345318122913&alt=media" alt="i18next ecossystem" width="400">
|
|
@@ -152,7 +152,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
|
|
|
152
152
|
|
|
153
153
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
154
154
|
|
|
155
|
-
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
|
|
155
|
+
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome!
|
|
156
156
|
|
|
157
157
|
---
|
|
158
158
|
|
|
@@ -868,20 +868,21 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
868
868
|
setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
|
|
869
869
|
|
|
870
870
|
|
|
871
|
+
var isMounted = React.useRef(true);
|
|
871
872
|
React.useEffect(function () {
|
|
872
|
-
var isMounted = true;
|
|
873
873
|
var bindI18n = i18nOptions.bindI18n,
|
|
874
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
874
|
+
bindI18nStore = i18nOptions.bindI18nStore;
|
|
875
|
+
isMounted.current = true; // if not ready and not using suspense load the namespaces
|
|
875
876
|
// in side effect and do not call resetT if unmounted
|
|
876
877
|
|
|
877
878
|
if (!ready && !useSuspense) {
|
|
878
879
|
loadNamespaces(i18n, namespaces, function () {
|
|
879
|
-
if (isMounted) setT(getT());
|
|
880
|
+
if (isMounted.current) setT(getT());
|
|
880
881
|
});
|
|
881
882
|
}
|
|
882
883
|
|
|
883
884
|
function boundReset() {
|
|
884
|
-
if (isMounted) setT(getT());
|
|
885
|
+
if (isMounted.current) setT(getT());
|
|
885
886
|
} // bind events to trigger change, like languageChanged
|
|
886
887
|
|
|
887
888
|
|
|
@@ -889,7 +890,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
889
890
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
|
|
890
891
|
|
|
891
892
|
return function () {
|
|
892
|
-
isMounted = false;
|
|
893
|
+
isMounted.current = false;
|
|
893
894
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
894
895
|
return i18n.off(e, boundReset);
|
|
895
896
|
});
|
|
@@ -910,7 +911,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
910
911
|
|
|
911
912
|
throw new Promise(function (resolve) {
|
|
912
913
|
loadNamespaces(i18n, namespaces, function () {
|
|
913
|
-
setT(getT());
|
|
914
|
+
if (isMounted.current) setT(getT());
|
|
914
915
|
resolve();
|
|
915
916
|
});
|
|
916
917
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
define(["exports","react"],(function(e,n){"use strict";var t="default"in n?n.default:n;function r(e){return(r="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 a(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 i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(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 c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(t,!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(t).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return 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){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,p=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,d=Object.create?Object.create(null):{};function g(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function m(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(m,"")+"</"+n.name+">"}}var h,y,v={parse:function(e,n){n||(n={}),n.components||(n.components=d);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(p,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var p,d="/"!==s.charAt(1),m=0===s.indexOf("\x3c!--"),h=u+s.length,y=e.charAt(h);d&&!m&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(f,(function(i){if("="===i)return r=!0,void t++;r?0===t?((l[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!y||"<"===y||g(t.children,e,a,h,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(p=i[a-1])&&p.children.push(t),i[a]=t),(m||!d||t.voidElement)&&(m||a--,!c&&"<"!==y&&y&&g(p=-1===a?r:i[a].children,e,a,h,n.ignoreWhitespace))})),!r.length&&e.length&&g(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce((function(e,n){return e+m("",n)}),"")}},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){return y}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c({},b,{},e)}function S(){return b}var E=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)}}])&&a(n.prototype,t),r&&a(n,r),e}();function N(e){h=e}function x(){return h}var k={type:"3rdParty",init:function(e){j(e.options.react),N(e)}};function I(e){return function(n){return new Promise((function(t){var r=P();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function P(){var e=x(),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 R(){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 C={};function T(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&C[n[0]]||("string"==typeof n[0]&&(C[n[0]]=new Date),R.apply(void 0,n))}function A(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 L(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function z(e){return e&&(e.children||e.props&&e.props.children)}function D(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function B(e){return Array.isArray(e)?e:[e]}function V(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(z(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=B(n);return B(a).reduce((function(n,a,l){var f=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var p=o[parseInt(a.name,10)]||{},d=t.isValidElement(p);if("string"==typeof p)n.push(p);else if(z(p)){var g=D(p),m=e(g,a.children),h=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(g)&&0===m.length?g:m;p.dummy&&(p.children=h),n.push(t.cloneElement(p,c({},p.props,{key:l}),h))}else if(u&&"object"===r(p)&&p.dummy&&!d){var y=e(o,a.children);n.push(t.cloneElement(p,c({},p.props,{key:l}),y))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var v=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},v))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var b=e(o,a.children);n.push("<".concat(a.name,">").concat(b,"</").concat(a.name,">"))}else if("object"!==r(p)||d)1===a.children.length&&f?n.push(t.cloneElement(p,c({},p.props,{key:l}),f)):n.push(t.cloneElement(p,c({},p.props,{key:l})));else{var O=a.children[0]?f:null;O&&n.push(O)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],v.parse("<0>".concat(f,"</0>")));return D(p[0])}function K(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(O),i=w()&&a||{},o=i.i18n,s=i.defaultNS,l=r||o||x();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new E),!l){T("You will need pass in an i18next instance by using initReactI18next");var f=function(e){return Array.isArray(e)?e[e.length-1]:e},p=[f,{},!1];return p.t=f,p.i18n={},p.ready=!1,p}var d=c({},S(),{},l.options.react,{},t),g=d.useSuspense,m=e||s||l.options&&l.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(m);var h=(l.isInitialized||l.initializedStoreOnce)&&m.every((function(e){return function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return T("i18n.languages were undefined or empty",n.languages),!0;var 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||!(!o(r,e)||a&&!o(i,e))))}(e,l,d)}));function y(){return{t:l.getFixedT(null,"fallback"===d.nsMode?m:m[0])}}var v=u(n.useState(y()),2),b=v[0],j=v[1];n.useEffect((function(){var e=!0,n=d.bindI18n,t=d.bindI18nStore;function r(){e&&j(y())}return h||g||A(l,m,(function(){e&&j(y())})),n&&l&&l.on(n,r),t&&l&&l.store.on(t,r),function(){e=!1,n&&l&&n.split(" ").forEach((function(e){return l.off(e,r)})),t&&l&&t.split(" ").forEach((function(e){return l.store.off(e,r)}))}}),[m.join()]);var N=[b.t,l,h];if(N.t=b.t,N.i18n=l,N.ready=h,h)return N;if(!h&&!g)return N;throw new Promise((function(e){A(l,m,(function(){j(y()),e()}))}))}function U(e,t){var r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,a=n.useContext(O),i=(w()&&a||{}).i18n,o=r||i||x();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var n=e.i18n,r=e.defaultNS,a=e.children;return y=!0,t.createElement(O.Provider,{value:{i18n:n,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,h=e.t,y=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(O),b=w()&&v||{},j=b.i18n,E=b.defaultNS,N=m||j||x();if(!N)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var k=h||N.t.bind(N)||function(e){return e},I=c({},S(),{},N.options&&N.options.react),P=void 0!==o?o:I.defaultTransParent,C=g||k.ns||E||N.options&&N.options.defaultNS;C="string"==typeof C?[C]:C||["translation"];var A=p||function e(n,a,i,o){if(!a)return"";var s=n,u=B(a),l=o.transKeepBasicHtmlNodesFor||[];return u.forEach((function(n,a){var i="".concat(a);if("string"==typeof n)s="".concat(s).concat(n);else if(z(n)){var u=l.indexOf(n.type)>-1&&1===Object.keys(n.props).length&&"string"==typeof z(n)?n.type:i;s=n.props&&n.props.i18nIsDynamicList?"".concat(s,"<").concat(u,"></").concat(u,">"):"".concat(s,"<").concat(u,">").concat(e("",D(n),a+1,o),"</").concat(u,">")}else if(t.isValidElement(n))s=l.indexOf(n.type)>-1&&0===Object.keys(n.props).length?"".concat(s,"<").concat(n.type,"/>"):"".concat(s,"<").concat(i,"></").concat(i,">");else if("object"===r(n)){var f=c({},n),p=f.format;delete f.format;var d=Object.keys(f);p&&1===d.length?s="".concat(s,"{{").concat(d[0],", ").concat(p,"}}"):1===d.length?s="".concat(s,"{{").concat(d[0],"}}"):R("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else R("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)})),s}("",a,0,I)||I.transEmptyNodeValue,L=I.hashTransKey,K=u||(L?L(A):A),U=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:A,ns:C}),F=K?k(K,U):A;return P?t.createElement(P,y,V(d||a,F,N,I,U)):V(d||a,F,N,I,U)},e.Translation=function(e){var n=e.ns,t=e.children,r=u(K(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=I,e.getDefaults=S,e.getI18n=x,e.getInitialProps=P,e.initReactI18next=k,e.setDefaults=j,e.setI18n=N,e.useSSR=U,e.useTranslation=K,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return U(r,a),t.createElement(e,c({},i))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(L(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(K(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(L(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
define(["exports","react"],(function(e,n){"use strict";var t="default"in n?n.default:n;function r(e){return(r="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 a(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 i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(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 c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(t,!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(t).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return 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){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,p=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,d=Object.create?Object.create(null):{};function g(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function m(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(m,"")+"</"+n.name+">"}}var h,y,v={parse:function(e,n){n||(n={}),n.components||(n.components=d);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(p,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var p,d="/"!==s.charAt(1),m=0===s.indexOf("\x3c!--"),h=u+s.length,y=e.charAt(h);d&&!m&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(f,(function(i){if("="===i)return r=!0,void t++;r?0===t?((l[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!y||"<"===y||g(t.children,e,a,h,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(p=i[a-1])&&p.children.push(t),i[a]=t),(m||!d||t.voidElement)&&(m||a--,!c&&"<"!==y&&y&&g(p=-1===a?r:i[a].children,e,a,h,n.ignoreWhitespace))})),!r.length&&e.length&&g(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce((function(e,n){return e+m("",n)}),"")}},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){return y}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c({},b,{},e)}function S(){return b}var E=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)}}])&&a(n.prototype,t),r&&a(n,r),e}();function N(e){h=e}function x(){return h}var k={type:"3rdParty",init:function(e){j(e.options.react),N(e)}};function I(e){return function(n){return new Promise((function(t){var r=P();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function P(){var e=x(),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 R(){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 C={};function T(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&C[n[0]]||("string"==typeof n[0]&&(C[n[0]]=new Date),R.apply(void 0,n))}function A(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 L(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function z(e){return e&&(e.children||e.props&&e.props.children)}function D(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function B(e){return Array.isArray(e)?e:[e]}function V(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(z(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=B(n);return B(a).reduce((function(n,a,l){var f=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var p=o[parseInt(a.name,10)]||{},d=t.isValidElement(p);if("string"==typeof p)n.push(p);else if(z(p)){var g=D(p),m=e(g,a.children),h=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(g)&&0===m.length?g:m;p.dummy&&(p.children=h),n.push(t.cloneElement(p,c({},p.props,{key:l}),h))}else if(u&&"object"===r(p)&&p.dummy&&!d){var y=e(o,a.children);n.push(t.cloneElement(p,c({},p.props,{key:l}),y))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var v=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},v))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var b=e(o,a.children);n.push("<".concat(a.name,">").concat(b,"</").concat(a.name,">"))}else if("object"!==r(p)||d)1===a.children.length&&f?n.push(t.cloneElement(p,c({},p.props,{key:l}),f)):n.push(t.cloneElement(p,c({},p.props,{key:l})));else{var O=a.children[0]?f:null;O&&n.push(O)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],v.parse("<0>".concat(f,"</0>")));return D(p[0])}function K(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(O),i=w()&&a||{},o=i.i18n,s=i.defaultNS,l=r||o||x();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new E),!l){T("You will need pass in an i18next instance by using initReactI18next");var f=function(e){return Array.isArray(e)?e[e.length-1]:e},p=[f,{},!1];return p.t=f,p.i18n={},p.ready=!1,p}var d=c({},S(),{},l.options.react,{},t),g=d.useSuspense,m=e||s||l.options&&l.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(m);var h=(l.isInitialized||l.initializedStoreOnce)&&m.every((function(e){return function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return T("i18n.languages were undefined or empty",n.languages),!0;var 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||!(!o(r,e)||a&&!o(i,e))))}(e,l,d)}));function y(){return{t:l.getFixedT(null,"fallback"===d.nsMode?m:m[0])}}var v=u(n.useState(y()),2),b=v[0],j=v[1],N=n.useRef(!0);n.useEffect((function(){var e=d.bindI18n,n=d.bindI18nStore;function t(){N.current&&j(y())}return N.current=!0,h||g||A(l,m,(function(){N.current&&j(y())})),e&&l&&l.on(e,t),n&&l&&l.store.on(n,t),function(){N.current=!1,e&&l&&e.split(" ").forEach((function(e){return l.off(e,t)})),n&&l&&n.split(" ").forEach((function(e){return l.store.off(e,t)}))}}),[m.join()]);var k=[b.t,l,h];if(k.t=b.t,k.i18n=l,k.ready=h,h)return k;if(!h&&!g)return k;throw new Promise((function(e){A(l,m,(function(){N.current&&j(y()),e()}))}))}function U(e,t){var r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,a=n.useContext(O),i=(w()&&a||{}).i18n,o=r||i||x();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var n=e.i18n,r=e.defaultNS,a=e.children;return y=!0,t.createElement(O.Provider,{value:{i18n:n,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,h=e.t,y=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(O),b=w()&&v||{},j=b.i18n,E=b.defaultNS,N=m||j||x();if(!N)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var k=h||N.t.bind(N)||function(e){return e},I=c({},S(),{},N.options&&N.options.react),P=void 0!==o?o:I.defaultTransParent,C=g||k.ns||E||N.options&&N.options.defaultNS;C="string"==typeof C?[C]:C||["translation"];var A=p||function e(n,a,i,o){if(!a)return"";var s=n,u=B(a),l=o.transKeepBasicHtmlNodesFor||[];return u.forEach((function(n,a){var i="".concat(a);if("string"==typeof n)s="".concat(s).concat(n);else if(z(n)){var u=l.indexOf(n.type)>-1&&1===Object.keys(n.props).length&&"string"==typeof z(n)?n.type:i;s=n.props&&n.props.i18nIsDynamicList?"".concat(s,"<").concat(u,"></").concat(u,">"):"".concat(s,"<").concat(u,">").concat(e("",D(n),a+1,o),"</").concat(u,">")}else if(t.isValidElement(n))s=l.indexOf(n.type)>-1&&0===Object.keys(n.props).length?"".concat(s,"<").concat(n.type,"/>"):"".concat(s,"<").concat(i,"></").concat(i,">");else if("object"===r(n)){var f=c({},n),p=f.format;delete f.format;var d=Object.keys(f);p&&1===d.length?s="".concat(s,"{{").concat(d[0],", ").concat(p,"}}"):1===d.length?s="".concat(s,"{{").concat(d[0],"}}"):R("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else R("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)})),s}("",a,0,I)||I.transEmptyNodeValue,L=I.hashTransKey,K=u||(L?L(A):A),U=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:A,ns:C}),F=K?k(K,U):A;return P?t.createElement(P,y,V(d||a,F,N,I,U)):V(d||a,F,N,I,U)},e.Translation=function(e){var n=e.ns,t=e.children,r=u(K(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=I,e.getDefaults=S,e.getI18n=x,e.getInitialProps=P,e.initReactI18next=k,e.setDefaults=j,e.setI18n=N,e.useSSR=U,e.useTranslation=K,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return U(r,a),t.createElement(e,c({},i))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(L(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(K(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(L(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
@@ -73,20 +73,21 @@ function useTranslation(ns) {
|
|
|
73
73
|
setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
|
|
74
74
|
|
|
75
75
|
|
|
76
|
+
var isMounted = (0, _react.useRef)(true);
|
|
76
77
|
(0, _react.useEffect)(function () {
|
|
77
|
-
var isMounted = true;
|
|
78
78
|
var bindI18n = i18nOptions.bindI18n,
|
|
79
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
79
|
+
bindI18nStore = i18nOptions.bindI18nStore;
|
|
80
|
+
isMounted.current = true; // if not ready and not using suspense load the namespaces
|
|
80
81
|
// in side effect and do not call resetT if unmounted
|
|
81
82
|
|
|
82
83
|
if (!ready && !useSuspense) {
|
|
83
84
|
(0, _utils.loadNamespaces)(i18n, namespaces, function () {
|
|
84
|
-
if (isMounted) setT(getT());
|
|
85
|
+
if (isMounted.current) setT(getT());
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
function boundReset() {
|
|
89
|
-
if (isMounted) setT(getT());
|
|
90
|
+
if (isMounted.current) setT(getT());
|
|
90
91
|
} // bind events to trigger change, like languageChanged
|
|
91
92
|
|
|
92
93
|
|
|
@@ -94,7 +95,7 @@ function useTranslation(ns) {
|
|
|
94
95
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
|
|
95
96
|
|
|
96
97
|
return function () {
|
|
97
|
-
isMounted = false;
|
|
98
|
+
isMounted.current = false;
|
|
98
99
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
99
100
|
return i18n.off(e, boundReset);
|
|
100
101
|
});
|
|
@@ -115,7 +116,7 @@ function useTranslation(ns) {
|
|
|
115
116
|
|
|
116
117
|
throw new Promise(function (resolve) {
|
|
117
118
|
(0, _utils.loadNamespaces)(i18n, namespaces, function () {
|
|
118
|
-
setT(getT());
|
|
119
|
+
if (isMounted.current) setT(getT());
|
|
119
120
|
resolve();
|
|
120
121
|
});
|
|
121
122
|
});
|
|
@@ -5,7 +5,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
5
5
|
|
|
6
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
7
7
|
|
|
8
|
-
import { useState, useEffect, useContext } from 'react';
|
|
8
|
+
import { useState, useEffect, useContext, useRef } from 'react';
|
|
9
9
|
import { getI18n, getDefaults, ReportNamespaces, getHasUsedI18nextProvider, I18nContext } from './context';
|
|
10
10
|
import { warnOnce, loadNamespaces, hasLoadedNamespace } from './utils';
|
|
11
11
|
export function useTranslation(ns) {
|
|
@@ -60,20 +60,21 @@ export function useTranslation(ns) {
|
|
|
60
60
|
setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
var isMounted = useRef(true);
|
|
63
64
|
useEffect(function () {
|
|
64
|
-
var isMounted = true;
|
|
65
65
|
var bindI18n = i18nOptions.bindI18n,
|
|
66
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
66
|
+
bindI18nStore = i18nOptions.bindI18nStore;
|
|
67
|
+
isMounted.current = true; // if not ready and not using suspense load the namespaces
|
|
67
68
|
// in side effect and do not call resetT if unmounted
|
|
68
69
|
|
|
69
70
|
if (!ready && !useSuspense) {
|
|
70
71
|
loadNamespaces(i18n, namespaces, function () {
|
|
71
|
-
if (isMounted) setT(getT());
|
|
72
|
+
if (isMounted.current) setT(getT());
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
function boundReset() {
|
|
76
|
-
if (isMounted) setT(getT());
|
|
77
|
+
if (isMounted.current) setT(getT());
|
|
77
78
|
} // bind events to trigger change, like languageChanged
|
|
78
79
|
|
|
79
80
|
|
|
@@ -81,7 +82,7 @@ export function useTranslation(ns) {
|
|
|
81
82
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
|
|
82
83
|
|
|
83
84
|
return function () {
|
|
84
|
-
isMounted = false;
|
|
85
|
+
isMounted.current = false;
|
|
85
86
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
86
87
|
return i18n.off(e, boundReset);
|
|
87
88
|
});
|
|
@@ -102,7 +103,7 @@ export function useTranslation(ns) {
|
|
|
102
103
|
|
|
103
104
|
throw new Promise(function (resolve) {
|
|
104
105
|
loadNamespaces(i18n, namespaces, function () {
|
|
105
|
-
setT(getT());
|
|
106
|
+
if (isMounted.current) setT(getT());
|
|
106
107
|
resolve();
|
|
107
108
|
});
|
|
108
109
|
});
|
|
@@ -872,20 +872,21 @@
|
|
|
872
872
|
setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
|
|
873
873
|
|
|
874
874
|
|
|
875
|
+
var isMounted = React.useRef(true);
|
|
875
876
|
React.useEffect(function () {
|
|
876
|
-
var isMounted = true;
|
|
877
877
|
var bindI18n = i18nOptions.bindI18n,
|
|
878
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
878
|
+
bindI18nStore = i18nOptions.bindI18nStore;
|
|
879
|
+
isMounted.current = true; // if not ready and not using suspense load the namespaces
|
|
879
880
|
// in side effect and do not call resetT if unmounted
|
|
880
881
|
|
|
881
882
|
if (!ready && !useSuspense) {
|
|
882
883
|
loadNamespaces(i18n, namespaces, function () {
|
|
883
|
-
if (isMounted) setT(getT());
|
|
884
|
+
if (isMounted.current) setT(getT());
|
|
884
885
|
});
|
|
885
886
|
}
|
|
886
887
|
|
|
887
888
|
function boundReset() {
|
|
888
|
-
if (isMounted) setT(getT());
|
|
889
|
+
if (isMounted.current) setT(getT());
|
|
889
890
|
} // bind events to trigger change, like languageChanged
|
|
890
891
|
|
|
891
892
|
|
|
@@ -893,7 +894,7 @@
|
|
|
893
894
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
|
|
894
895
|
|
|
895
896
|
return function () {
|
|
896
|
-
isMounted = false;
|
|
897
|
+
isMounted.current = false;
|
|
897
898
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
898
899
|
return i18n.off(e, boundReset);
|
|
899
900
|
});
|
|
@@ -914,7 +915,7 @@
|
|
|
914
915
|
|
|
915
916
|
throw new Promise(function (resolve) {
|
|
916
917
|
loadNamespaces(i18n, namespaces, function () {
|
|
917
|
-
setT(getT());
|
|
918
|
+
if (isMounted.current) setT(getT());
|
|
918
919
|
resolve();
|
|
919
920
|
});
|
|
920
921
|
});
|
|
@@ -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){return(r="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 a(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 i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(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 c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(t,!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(t).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return 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){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,p=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,d=Object.create?Object.create(null):{};function g(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function m(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(m,"")+"</"+n.name+">"}}var h,y,v={parse:function(e,n){n||(n={}),n.components||(n.components=d);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(p,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var p,d="/"!==s.charAt(1),m=0===s.indexOf("\x3c!--"),h=u+s.length,y=e.charAt(h);d&&!m&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(f,(function(i){if("="===i)return r=!0,void t++;r?0===t?((l[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!y||"<"===y||g(t.children,e,a,h,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(p=i[a-1])&&p.children.push(t),i[a]=t),(m||!d||t.voidElement)&&(m||a--,!c&&"<"!==y&&y&&g(p=-1===a?r:i[a].children,e,a,h,n.ignoreWhitespace))})),!r.length&&e.length&&g(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce((function(e,n){return e+m("",n)}),"")}},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){return y}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c({},b,{},e)}function S(){return b}var E=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)}}])&&a(n.prototype,t),r&&a(n,r),e}();function x(e){h=e}function N(){return h}var k={type:"3rdParty",init:function(e){j(e.options.react),x(e)}};function I(e){return function(n){return new Promise((function(t){var r=P();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function P(){var e=N(),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 R(){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 C={};function T(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&C[n[0]]||("string"==typeof n[0]&&(C[n[0]]=new Date),R.apply(void 0,n))}function A(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 L(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function z(e){return e&&(e.children||e.props&&e.props.children)}function D(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function B(e){return Array.isArray(e)?e:[e]}function V(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(z(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=B(n);return B(a).reduce((function(n,a,l){var f=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var p=o[parseInt(a.name,10)]||{},d=t.isValidElement(p);if("string"==typeof p)n.push(p);else if(z(p)){var g=D(p),m=e(g,a.children),h=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(g)&&0===m.length?g:m;p.dummy&&(p.children=h),n.push(t.cloneElement(p,c({},p.props,{key:l}),h))}else if(u&&"object"===r(p)&&p.dummy&&!d){var y=e(o,a.children);n.push(t.cloneElement(p,c({},p.props,{key:l}),y))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var v=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},v))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var b=e(o,a.children);n.push("<".concat(a.name,">").concat(b,"</").concat(a.name,">"))}else if("object"!==r(p)||d)1===a.children.length&&f?n.push(t.cloneElement(p,c({},p.props,{key:l}),f)):n.push(t.cloneElement(p,c({},p.props,{key:l})));else{var O=a.children[0]?f:null;O&&n.push(O)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],v.parse("<0>".concat(f,"</0>")));return D(p[0])}function K(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(O),i=w()&&a||{},o=i.i18n,s=i.defaultNS,l=r||o||N();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new E),!l){T("You will need pass in an i18next instance by using initReactI18next");var f=function(e){return Array.isArray(e)?e[e.length-1]:e},p=[f,{},!1];return p.t=f,p.i18n={},p.ready=!1,p}var d=c({},S(),{},l.options.react,{},t),g=d.useSuspense,m=e||s||l.options&&l.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(m);var h=(l.isInitialized||l.initializedStoreOnce)&&m.every((function(e){return function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return T("i18n.languages were undefined or empty",n.languages),!0;var 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||!(!o(r,e)||a&&!o(i,e))))}(e,l,d)}));function y(){return{t:l.getFixedT(null,"fallback"===d.nsMode?m:m[0])}}var v=u(n.useState(y()),2),b=v[0],j=v[1];n.useEffect((function(){var e=!0,n=d.bindI18n,t=d.bindI18nStore;function r(){e&&j(y())}return h||g||A(l,m,(function(){e&&j(y())})),n&&l&&l.on(n,r),t&&l&&l.store.on(t,r),function(){e=!1,n&&l&&n.split(" ").forEach((function(e){return l.off(e,r)})),t&&l&&t.split(" ").forEach((function(e){return l.store.off(e,r)}))}}),[m.join()]);var x=[b.t,l,h];if(x.t=b.t,x.i18n=l,x.ready=h,h)return x;if(!h&&!g)return x;throw new Promise((function(e){A(l,m,(function(){j(y()),e()}))}))}function U(e,t){var r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,a=n.useContext(O),i=(w()&&a||{}).i18n,o=r||i||N();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var n=e.i18n,r=e.defaultNS,a=e.children;return y=!0,t.createElement(O.Provider,{value:{i18n:n,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,h=e.t,y=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(O),b=w()&&v||{},j=b.i18n,E=b.defaultNS,x=m||j||N();if(!x)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var k=h||x.t.bind(x)||function(e){return e},I=c({},S(),{},x.options&&x.options.react),P=void 0!==o?o:I.defaultTransParent,C=g||k.ns||E||x.options&&x.options.defaultNS;C="string"==typeof C?[C]:C||["translation"];var A=p||function e(n,a,i,o){if(!a)return"";var s=n,u=B(a),l=o.transKeepBasicHtmlNodesFor||[];return u.forEach((function(n,a){var i="".concat(a);if("string"==typeof n)s="".concat(s).concat(n);else if(z(n)){var u=l.indexOf(n.type)>-1&&1===Object.keys(n.props).length&&"string"==typeof z(n)?n.type:i;s=n.props&&n.props.i18nIsDynamicList?"".concat(s,"<").concat(u,"></").concat(u,">"):"".concat(s,"<").concat(u,">").concat(e("",D(n),a+1,o),"</").concat(u,">")}else if(t.isValidElement(n))s=l.indexOf(n.type)>-1&&0===Object.keys(n.props).length?"".concat(s,"<").concat(n.type,"/>"):"".concat(s,"<").concat(i,"></").concat(i,">");else if("object"===r(n)){var f=c({},n),p=f.format;delete f.format;var d=Object.keys(f);p&&1===d.length?s="".concat(s,"{{").concat(d[0],", ").concat(p,"}}"):1===d.length?s="".concat(s,"{{").concat(d[0],"}}"):R("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else R("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)})),s}("",a,0,I)||I.transEmptyNodeValue,L=I.hashTransKey,K=u||(L?L(A):A),U=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:A,ns:C}),F=K?k(K,U):A;return P?t.createElement(P,y,V(d||a,F,x,I,U)):V(d||a,F,x,I,U)},e.Translation=function(e){var n=e.ns,t=e.children,r=u(K(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=I,e.getDefaults=S,e.getI18n=N,e.getInitialProps=P,e.initReactI18next=k,e.setDefaults=j,e.setI18n=x,e.useSSR=U,e.useTranslation=K,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return U(r,a),t.createElement(e,c({},i))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(L(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(K(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(L(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},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";var t="default"in n?n.default:n;function r(e){return(r="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 a(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 i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(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 c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(t,!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(t).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return 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){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,p=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,d=Object.create?Object.create(null):{};function g(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function m(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(m,"")+"</"+n.name+">"}}var h,y,v={parse:function(e,n){n||(n={}),n.components||(n.components=d);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(p,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var p,d="/"!==s.charAt(1),m=0===s.indexOf("\x3c!--"),h=u+s.length,y=e.charAt(h);d&&!m&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(f,(function(i){if("="===i)return r=!0,void t++;r?0===t?((l[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!y||"<"===y||g(t.children,e,a,h,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(p=i[a-1])&&p.children.push(t),i[a]=t),(m||!d||t.voidElement)&&(m||a--,!c&&"<"!==y&&y&&g(p=-1===a?r:i[a].children,e,a,h,n.ignoreWhitespace))})),!r.length&&e.length&&g(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce((function(e,n){return e+m("",n)}),"")}},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){return y}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c({},b,{},e)}function S(){return b}var E=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)}}])&&a(n.prototype,t),r&&a(n,r),e}();function x(e){h=e}function N(){return h}var k={type:"3rdParty",init:function(e){j(e.options.react),x(e)}};function I(e){return function(n){return new Promise((function(t){var r=P();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function P(){var e=N(),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 R(){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 C={};function T(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&C[n[0]]||("string"==typeof n[0]&&(C[n[0]]=new Date),R.apply(void 0,n))}function A(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 L(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function z(e){return e&&(e.children||e.props&&e.props.children)}function D(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function B(e){return Array.isArray(e)?e:[e]}function V(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(z(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=B(n);return B(a).reduce((function(n,a,l){var f=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var p=o[parseInt(a.name,10)]||{},d=t.isValidElement(p);if("string"==typeof p)n.push(p);else if(z(p)){var g=D(p),m=e(g,a.children),h=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(g)&&0===m.length?g:m;p.dummy&&(p.children=h),n.push(t.cloneElement(p,c({},p.props,{key:l}),h))}else if(u&&"object"===r(p)&&p.dummy&&!d){var y=e(o,a.children);n.push(t.cloneElement(p,c({},p.props,{key:l}),y))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var v=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},v))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var b=e(o,a.children);n.push("<".concat(a.name,">").concat(b,"</").concat(a.name,">"))}else if("object"!==r(p)||d)1===a.children.length&&f?n.push(t.cloneElement(p,c({},p.props,{key:l}),f)):n.push(t.cloneElement(p,c({},p.props,{key:l})));else{var O=a.children[0]?f:null;O&&n.push(O)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],v.parse("<0>".concat(f,"</0>")));return D(p[0])}function K(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(O),i=w()&&a||{},o=i.i18n,s=i.defaultNS,l=r||o||N();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new E),!l){T("You will need pass in an i18next instance by using initReactI18next");var f=function(e){return Array.isArray(e)?e[e.length-1]:e},p=[f,{},!1];return p.t=f,p.i18n={},p.ready=!1,p}var d=c({},S(),{},l.options.react,{},t),g=d.useSuspense,m=e||s||l.options&&l.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(m);var h=(l.isInitialized||l.initializedStoreOnce)&&m.every((function(e){return function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return T("i18n.languages were undefined or empty",n.languages),!0;var 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||!(!o(r,e)||a&&!o(i,e))))}(e,l,d)}));function y(){return{t:l.getFixedT(null,"fallback"===d.nsMode?m:m[0])}}var v=u(n.useState(y()),2),b=v[0],j=v[1],x=n.useRef(!0);n.useEffect((function(){var e=d.bindI18n,n=d.bindI18nStore;function t(){x.current&&j(y())}return x.current=!0,h||g||A(l,m,(function(){x.current&&j(y())})),e&&l&&l.on(e,t),n&&l&&l.store.on(n,t),function(){x.current=!1,e&&l&&e.split(" ").forEach((function(e){return l.off(e,t)})),n&&l&&n.split(" ").forEach((function(e){return l.store.off(e,t)}))}}),[m.join()]);var k=[b.t,l,h];if(k.t=b.t,k.i18n=l,k.ready=h,h)return k;if(!h&&!g)return k;throw new Promise((function(e){A(l,m,(function(){x.current&&j(y()),e()}))}))}function U(e,t){var r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,a=n.useContext(O),i=(w()&&a||{}).i18n,o=r||i||N();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var n=e.i18n,r=e.defaultNS,a=e.children;return y=!0,t.createElement(O.Provider,{value:{i18n:n,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,h=e.t,y=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(O),b=w()&&v||{},j=b.i18n,E=b.defaultNS,x=m||j||N();if(!x)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var k=h||x.t.bind(x)||function(e){return e},I=c({},S(),{},x.options&&x.options.react),P=void 0!==o?o:I.defaultTransParent,C=g||k.ns||E||x.options&&x.options.defaultNS;C="string"==typeof C?[C]:C||["translation"];var A=p||function e(n,a,i,o){if(!a)return"";var s=n,u=B(a),l=o.transKeepBasicHtmlNodesFor||[];return u.forEach((function(n,a){var i="".concat(a);if("string"==typeof n)s="".concat(s).concat(n);else if(z(n)){var u=l.indexOf(n.type)>-1&&1===Object.keys(n.props).length&&"string"==typeof z(n)?n.type:i;s=n.props&&n.props.i18nIsDynamicList?"".concat(s,"<").concat(u,"></").concat(u,">"):"".concat(s,"<").concat(u,">").concat(e("",D(n),a+1,o),"</").concat(u,">")}else if(t.isValidElement(n))s=l.indexOf(n.type)>-1&&0===Object.keys(n.props).length?"".concat(s,"<").concat(n.type,"/>"):"".concat(s,"<").concat(i,"></").concat(i,">");else if("object"===r(n)){var f=c({},n),p=f.format;delete f.format;var d=Object.keys(f);p&&1===d.length?s="".concat(s,"{{").concat(d[0],", ").concat(p,"}}"):1===d.length?s="".concat(s,"{{").concat(d[0],"}}"):R("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else R("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)})),s}("",a,0,I)||I.transEmptyNodeValue,L=I.hashTransKey,K=u||(L?L(A):A),U=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:A,ns:C}),F=K?k(K,U):A;return P?t.createElement(P,y,V(d||a,F,x,I,U)):V(d||a,F,x,I,U)},e.Translation=function(e){var n=e.ns,t=e.children,r=u(K(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=I,e.getDefaults=S,e.getI18n=N,e.getInitialProps=P,e.initReactI18next=k,e.setDefaults=j,e.setI18n=x,e.useSSR=U,e.useTranslation=K,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return U(r,a),t.createElement(e,c({},i))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(L(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(K(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(L(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-i18next",
|
|
3
|
-
"version": "11.3.
|
|
3
|
+
"version": "11.3.4",
|
|
4
4
|
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
|
|
5
5
|
"main": "dist/commonjs/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"babel-plugin-macros": "^2.5.0",
|
|
47
47
|
"babel-plugin-tester": "^6.0.0",
|
|
48
48
|
"coveralls": "^3.0.2",
|
|
49
|
+
"cp-cli": "^2.0.0",
|
|
49
50
|
"cross-env": "^6.0.3",
|
|
50
51
|
"dtslint": "^0.9.1",
|
|
51
52
|
"enzyme": "^3.8.0",
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
},
|
|
86
87
|
"scripts": {
|
|
87
88
|
"clean": "rimraf dist && mkdirp dist",
|
|
88
|
-
"copy": "cp ./dist/umd/react-i18next.min.js ./react-i18next.min.js && cp ./dist/umd/react-i18next.js ./react-i18next.js",
|
|
89
|
+
"copy": "cp-cli ./dist/umd/react-i18next.min.js ./react-i18next.min.js && cp-cli ./dist/umd/react-i18next.js ./react-i18next.js",
|
|
89
90
|
"build:es": "cross-env BABEL_ENV=jsnext babel src --out-dir dist/es",
|
|
90
91
|
"build:cjs": "babel src --out-dir dist/commonjs",
|
|
91
92
|
"build:umd": "rollup -c rollup.config.js --format umd && rollup -c rollup.config.js --format umd --uglify",
|
package/react-i18next.js
CHANGED
|
@@ -872,20 +872,21 @@
|
|
|
872
872
|
setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
|
|
873
873
|
|
|
874
874
|
|
|
875
|
+
var isMounted = React.useRef(true);
|
|
875
876
|
React.useEffect(function () {
|
|
876
|
-
var isMounted = true;
|
|
877
877
|
var bindI18n = i18nOptions.bindI18n,
|
|
878
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
878
|
+
bindI18nStore = i18nOptions.bindI18nStore;
|
|
879
|
+
isMounted.current = true; // if not ready and not using suspense load the namespaces
|
|
879
880
|
// in side effect and do not call resetT if unmounted
|
|
880
881
|
|
|
881
882
|
if (!ready && !useSuspense) {
|
|
882
883
|
loadNamespaces(i18n, namespaces, function () {
|
|
883
|
-
if (isMounted) setT(getT());
|
|
884
|
+
if (isMounted.current) setT(getT());
|
|
884
885
|
});
|
|
885
886
|
}
|
|
886
887
|
|
|
887
888
|
function boundReset() {
|
|
888
|
-
if (isMounted) setT(getT());
|
|
889
|
+
if (isMounted.current) setT(getT());
|
|
889
890
|
} // bind events to trigger change, like languageChanged
|
|
890
891
|
|
|
891
892
|
|
|
@@ -893,7 +894,7 @@
|
|
|
893
894
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
|
|
894
895
|
|
|
895
896
|
return function () {
|
|
896
|
-
isMounted = false;
|
|
897
|
+
isMounted.current = false;
|
|
897
898
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
898
899
|
return i18n.off(e, boundReset);
|
|
899
900
|
});
|
|
@@ -914,7 +915,7 @@
|
|
|
914
915
|
|
|
915
916
|
throw new Promise(function (resolve) {
|
|
916
917
|
loadNamespaces(i18n, namespaces, function () {
|
|
917
|
-
setT(getT());
|
|
918
|
+
if (isMounted.current) setT(getT());
|
|
918
919
|
resolve();
|
|
919
920
|
});
|
|
920
921
|
});
|
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){return(r="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 a(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 i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(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 c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(t,!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(t).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return 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){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,p=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,d=Object.create?Object.create(null):{};function g(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function m(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(m,"")+"</"+n.name+">"}}var h,y,v={parse:function(e,n){n||(n={}),n.components||(n.components=d);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(p,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var p,d="/"!==s.charAt(1),m=0===s.indexOf("\x3c!--"),h=u+s.length,y=e.charAt(h);d&&!m&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(f,(function(i){if("="===i)return r=!0,void t++;r?0===t?((l[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!y||"<"===y||g(t.children,e,a,h,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(p=i[a-1])&&p.children.push(t),i[a]=t),(m||!d||t.voidElement)&&(m||a--,!c&&"<"!==y&&y&&g(p=-1===a?r:i[a].children,e,a,h,n.ignoreWhitespace))})),!r.length&&e.length&&g(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce((function(e,n){return e+m("",n)}),"")}},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){return y}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c({},b,{},e)}function S(){return b}var E=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)}}])&&a(n.prototype,t),r&&a(n,r),e}();function x(e){h=e}function N(){return h}var k={type:"3rdParty",init:function(e){j(e.options.react),x(e)}};function I(e){return function(n){return new Promise((function(t){var r=P();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function P(){var e=N(),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 R(){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 C={};function T(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&C[n[0]]||("string"==typeof n[0]&&(C[n[0]]=new Date),R.apply(void 0,n))}function A(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 L(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function z(e){return e&&(e.children||e.props&&e.props.children)}function D(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function B(e){return Array.isArray(e)?e:[e]}function V(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(z(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=B(n);return B(a).reduce((function(n,a,l){var f=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var p=o[parseInt(a.name,10)]||{},d=t.isValidElement(p);if("string"==typeof p)n.push(p);else if(z(p)){var g=D(p),m=e(g,a.children),h=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(g)&&0===m.length?g:m;p.dummy&&(p.children=h),n.push(t.cloneElement(p,c({},p.props,{key:l}),h))}else if(u&&"object"===r(p)&&p.dummy&&!d){var y=e(o,a.children);n.push(t.cloneElement(p,c({},p.props,{key:l}),y))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var v=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},v))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var b=e(o,a.children);n.push("<".concat(a.name,">").concat(b,"</").concat(a.name,">"))}else if("object"!==r(p)||d)1===a.children.length&&f?n.push(t.cloneElement(p,c({},p.props,{key:l}),f)):n.push(t.cloneElement(p,c({},p.props,{key:l})));else{var O=a.children[0]?f:null;O&&n.push(O)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],v.parse("<0>".concat(f,"</0>")));return D(p[0])}function K(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(O),i=w()&&a||{},o=i.i18n,s=i.defaultNS,l=r||o||N();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new E),!l){T("You will need pass in an i18next instance by using initReactI18next");var f=function(e){return Array.isArray(e)?e[e.length-1]:e},p=[f,{},!1];return p.t=f,p.i18n={},p.ready=!1,p}var d=c({},S(),{},l.options.react,{},t),g=d.useSuspense,m=e||s||l.options&&l.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(m);var h=(l.isInitialized||l.initializedStoreOnce)&&m.every((function(e){return function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return T("i18n.languages were undefined or empty",n.languages),!0;var 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||!(!o(r,e)||a&&!o(i,e))))}(e,l,d)}));function y(){return{t:l.getFixedT(null,"fallback"===d.nsMode?m:m[0])}}var v=u(n.useState(y()),2),b=v[0],j=v[1];n.useEffect((function(){var e=!0,n=d.bindI18n,t=d.bindI18nStore;function r(){e&&j(y())}return h||g||A(l,m,(function(){e&&j(y())})),n&&l&&l.on(n,r),t&&l&&l.store.on(t,r),function(){e=!1,n&&l&&n.split(" ").forEach((function(e){return l.off(e,r)})),t&&l&&t.split(" ").forEach((function(e){return l.store.off(e,r)}))}}),[m.join()]);var x=[b.t,l,h];if(x.t=b.t,x.i18n=l,x.ready=h,h)return x;if(!h&&!g)return x;throw new Promise((function(e){A(l,m,(function(){j(y()),e()}))}))}function U(e,t){var r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,a=n.useContext(O),i=(w()&&a||{}).i18n,o=r||i||N();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var n=e.i18n,r=e.defaultNS,a=e.children;return y=!0,t.createElement(O.Provider,{value:{i18n:n,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,h=e.t,y=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(O),b=w()&&v||{},j=b.i18n,E=b.defaultNS,x=m||j||N();if(!x)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var k=h||x.t.bind(x)||function(e){return e},I=c({},S(),{},x.options&&x.options.react),P=void 0!==o?o:I.defaultTransParent,C=g||k.ns||E||x.options&&x.options.defaultNS;C="string"==typeof C?[C]:C||["translation"];var A=p||function e(n,a,i,o){if(!a)return"";var s=n,u=B(a),l=o.transKeepBasicHtmlNodesFor||[];return u.forEach((function(n,a){var i="".concat(a);if("string"==typeof n)s="".concat(s).concat(n);else if(z(n)){var u=l.indexOf(n.type)>-1&&1===Object.keys(n.props).length&&"string"==typeof z(n)?n.type:i;s=n.props&&n.props.i18nIsDynamicList?"".concat(s,"<").concat(u,"></").concat(u,">"):"".concat(s,"<").concat(u,">").concat(e("",D(n),a+1,o),"</").concat(u,">")}else if(t.isValidElement(n))s=l.indexOf(n.type)>-1&&0===Object.keys(n.props).length?"".concat(s,"<").concat(n.type,"/>"):"".concat(s,"<").concat(i,"></").concat(i,">");else if("object"===r(n)){var f=c({},n),p=f.format;delete f.format;var d=Object.keys(f);p&&1===d.length?s="".concat(s,"{{").concat(d[0],", ").concat(p,"}}"):1===d.length?s="".concat(s,"{{").concat(d[0],"}}"):R("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else R("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)})),s}("",a,0,I)||I.transEmptyNodeValue,L=I.hashTransKey,K=u||(L?L(A):A),U=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:A,ns:C}),F=K?k(K,U):A;return P?t.createElement(P,y,V(d||a,F,x,I,U)):V(d||a,F,x,I,U)},e.Translation=function(e){var n=e.ns,t=e.children,r=u(K(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=I,e.getDefaults=S,e.getI18n=N,e.getInitialProps=P,e.initReactI18next=k,e.setDefaults=j,e.setI18n=x,e.useSSR=U,e.useTranslation=K,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return U(r,a),t.createElement(e,c({},i))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(L(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(K(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(L(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},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";var t="default"in n?n.default:n;function r(e){return(r="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 a(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 i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(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 c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(t,!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(t).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return 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){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,p=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,d=Object.create?Object.create(null):{};function g(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function m(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(m,"")+"</"+n.name+">"}}var h,y,v={parse:function(e,n){n||(n={}),n.components||(n.components=d);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(p,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var p,d="/"!==s.charAt(1),m=0===s.indexOf("\x3c!--"),h=u+s.length,y=e.charAt(h);d&&!m&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(f,(function(i){if("="===i)return r=!0,void t++;r?0===t?((l[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!y||"<"===y||g(t.children,e,a,h,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(p=i[a-1])&&p.children.push(t),i[a]=t),(m||!d||t.voidElement)&&(m||a--,!c&&"<"!==y&&y&&g(p=-1===a?r:i[a].children,e,a,h,n.ignoreWhitespace))})),!r.length&&e.length&&g(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce((function(e,n){return e+m("",n)}),"")}},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){return y}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c({},b,{},e)}function S(){return b}var E=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)}}])&&a(n.prototype,t),r&&a(n,r),e}();function x(e){h=e}function N(){return h}var k={type:"3rdParty",init:function(e){j(e.options.react),x(e)}};function I(e){return function(n){return new Promise((function(t){var r=P();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function P(){var e=N(),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 R(){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 C={};function T(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&C[n[0]]||("string"==typeof n[0]&&(C[n[0]]=new Date),R.apply(void 0,n))}function A(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 L(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function z(e){return e&&(e.children||e.props&&e.props.children)}function D(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function B(e){return Array.isArray(e)?e:[e]}function V(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(z(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=B(n);return B(a).reduce((function(n,a,l){var f=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var p=o[parseInt(a.name,10)]||{},d=t.isValidElement(p);if("string"==typeof p)n.push(p);else if(z(p)){var g=D(p),m=e(g,a.children),h=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(g)&&0===m.length?g:m;p.dummy&&(p.children=h),n.push(t.cloneElement(p,c({},p.props,{key:l}),h))}else if(u&&"object"===r(p)&&p.dummy&&!d){var y=e(o,a.children);n.push(t.cloneElement(p,c({},p.props,{key:l}),y))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var v=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},v))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var b=e(o,a.children);n.push("<".concat(a.name,">").concat(b,"</").concat(a.name,">"))}else if("object"!==r(p)||d)1===a.children.length&&f?n.push(t.cloneElement(p,c({},p.props,{key:l}),f)):n.push(t.cloneElement(p,c({},p.props,{key:l})));else{var O=a.children[0]?f:null;O&&n.push(O)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],v.parse("<0>".concat(f,"</0>")));return D(p[0])}function K(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(O),i=w()&&a||{},o=i.i18n,s=i.defaultNS,l=r||o||N();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new E),!l){T("You will need pass in an i18next instance by using initReactI18next");var f=function(e){return Array.isArray(e)?e[e.length-1]:e},p=[f,{},!1];return p.t=f,p.i18n={},p.ready=!1,p}var d=c({},S(),{},l.options.react,{},t),g=d.useSuspense,m=e||s||l.options&&l.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(m);var h=(l.isInitialized||l.initializedStoreOnce)&&m.every((function(e){return function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return T("i18n.languages were undefined or empty",n.languages),!0;var 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||!(!o(r,e)||a&&!o(i,e))))}(e,l,d)}));function y(){return{t:l.getFixedT(null,"fallback"===d.nsMode?m:m[0])}}var v=u(n.useState(y()),2),b=v[0],j=v[1],x=n.useRef(!0);n.useEffect((function(){var e=d.bindI18n,n=d.bindI18nStore;function t(){x.current&&j(y())}return x.current=!0,h||g||A(l,m,(function(){x.current&&j(y())})),e&&l&&l.on(e,t),n&&l&&l.store.on(n,t),function(){x.current=!1,e&&l&&e.split(" ").forEach((function(e){return l.off(e,t)})),n&&l&&n.split(" ").forEach((function(e){return l.store.off(e,t)}))}}),[m.join()]);var k=[b.t,l,h];if(k.t=b.t,k.i18n=l,k.ready=h,h)return k;if(!h&&!g)return k;throw new Promise((function(e){A(l,m,(function(){x.current&&j(y()),e()}))}))}function U(e,t){var r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,a=n.useContext(O),i=(w()&&a||{}).i18n,o=r||i||N();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var n=e.i18n,r=e.defaultNS,a=e.children;return y=!0,t.createElement(O.Provider,{value:{i18n:n,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,h=e.t,y=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(O),b=w()&&v||{},j=b.i18n,E=b.defaultNS,x=m||j||N();if(!x)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var k=h||x.t.bind(x)||function(e){return e},I=c({},S(),{},x.options&&x.options.react),P=void 0!==o?o:I.defaultTransParent,C=g||k.ns||E||x.options&&x.options.defaultNS;C="string"==typeof C?[C]:C||["translation"];var A=p||function e(n,a,i,o){if(!a)return"";var s=n,u=B(a),l=o.transKeepBasicHtmlNodesFor||[];return u.forEach((function(n,a){var i="".concat(a);if("string"==typeof n)s="".concat(s).concat(n);else if(z(n)){var u=l.indexOf(n.type)>-1&&1===Object.keys(n.props).length&&"string"==typeof z(n)?n.type:i;s=n.props&&n.props.i18nIsDynamicList?"".concat(s,"<").concat(u,"></").concat(u,">"):"".concat(s,"<").concat(u,">").concat(e("",D(n),a+1,o),"</").concat(u,">")}else if(t.isValidElement(n))s=l.indexOf(n.type)>-1&&0===Object.keys(n.props).length?"".concat(s,"<").concat(n.type,"/>"):"".concat(s,"<").concat(i,"></").concat(i,">");else if("object"===r(n)){var f=c({},n),p=f.format;delete f.format;var d=Object.keys(f);p&&1===d.length?s="".concat(s,"{{").concat(d[0],", ").concat(p,"}}"):1===d.length?s="".concat(s,"{{").concat(d[0],"}}"):R("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else R("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)})),s}("",a,0,I)||I.transEmptyNodeValue,L=I.hashTransKey,K=u||(L?L(A):A),U=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:A,ns:C}),F=K?k(K,U):A;return P?t.createElement(P,y,V(d||a,F,x,I,U)):V(d||a,F,x,I,U)},e.Translation=function(e){var n=e.ns,t=e.children,r=u(K(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=I,e.getDefaults=S,e.getI18n=N,e.getInitialProps=P,e.initReactI18next=k,e.setDefaults=j,e.setI18n=x,e.useSSR=U,e.useTranslation=K,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return U(r,a),t.createElement(e,c({},i))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(L(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(K(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(L(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/src/useTranslation.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useEffect, useContext } from 'react';
|
|
1
|
+
import { useState, useEffect, useContext, useRef } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
getI18n,
|
|
4
4
|
getDefaults,
|
|
@@ -50,20 +50,21 @@ export function useTranslation(ns, props = {}) {
|
|
|
50
50
|
}
|
|
51
51
|
const [t, setT] = useState(getT()); // seems we can't have functions as value -> wrap it in obj
|
|
52
52
|
|
|
53
|
+
const isMounted = useRef(true);
|
|
53
54
|
useEffect(() => {
|
|
54
|
-
let isMounted = true;
|
|
55
55
|
const { bindI18n, bindI18nStore } = i18nOptions;
|
|
56
|
+
isMounted.current = true
|
|
56
57
|
|
|
57
58
|
// if not ready and not using suspense load the namespaces
|
|
58
59
|
// in side effect and do not call resetT if unmounted
|
|
59
60
|
if (!ready && !useSuspense) {
|
|
60
61
|
loadNamespaces(i18n, namespaces, () => {
|
|
61
|
-
if (isMounted) setT(getT());
|
|
62
|
+
if (isMounted.current) setT(getT());
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
function boundReset() {
|
|
66
|
-
if (isMounted) setT(getT());
|
|
67
|
+
if (isMounted.current) setT(getT());
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
// bind events to trigger change, like languageChanged
|
|
@@ -72,7 +73,7 @@ export function useTranslation(ns, props = {}) {
|
|
|
72
73
|
|
|
73
74
|
// unbinding on unmount
|
|
74
75
|
return () => {
|
|
75
|
-
isMounted = false;
|
|
76
|
+
isMounted.current = false;
|
|
76
77
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
|
|
77
78
|
if (bindI18nStore && i18n)
|
|
78
79
|
bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
|
|
@@ -93,7 +94,7 @@ export function useTranslation(ns, props = {}) {
|
|
|
93
94
|
// not yet loaded namespaces -> load them -> and trigger suspense
|
|
94
95
|
throw new Promise(resolve => {
|
|
95
96
|
loadNamespaces(i18n, namespaces, () => {
|
|
96
|
-
setT(getT());
|
|
97
|
+
if (isMounted.current) setT(getT());
|
|
97
98
|
resolve();
|
|
98
99
|
});
|
|
99
100
|
});
|