react-i18next 11.3.0 → 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 +17 -0
- package/README.md +4 -4
- package/dist/amd/react-i18next.js +11 -8
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/Trans.js +2 -1
- package/dist/commonjs/useSSR.js +1 -1
- package/dist/commonjs/useTranslation.js +7 -6
- package/dist/es/Trans.js +3 -1
- package/dist/es/useSSR.js +1 -1
- package/dist/es/useTranslation.js +8 -7
- package/dist/umd/react-i18next.js +11 -8
- package/dist/umd/react-i18next.min.js +1 -1
- package/package.json +3 -2
- package/react-i18next.js +11 -8
- package/react-i18next.min.js +1 -1
- package/src/Trans.js +2 -1
- package/src/index.d.ts +2 -0
- package/src/useSSR.js +1 -1
- package/src/useTranslation.js +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
### 11.3.4
|
|
2
|
+
|
|
3
|
+
- [useTranslation] Avoid setting the new `t` function if the component is unmounted. (1051)[https://github.com/i18next/react-i18next/pull/1051]
|
|
4
|
+
|
|
5
|
+
### 11.3.3
|
|
6
|
+
|
|
7
|
+
- fixes copying ns in useSSR
|
|
8
|
+
|
|
9
|
+
### 11.3.2
|
|
10
|
+
|
|
11
|
+
- typescript: Add optional defaultN [1050](https://github.com/i18next/react-i18next/pull/1050)
|
|
12
|
+
|
|
13
|
+
### 11.3.1
|
|
14
|
+
|
|
15
|
+
- typescript: Translation component's ready parameter is missing in TypeScript definition [1044](https://github.com/i18next/react-i18next/pull/1044)
|
|
16
|
+
- change hook condition in Trans to equal useTranslations implementation
|
|
17
|
+
|
|
1
18
|
### 11.3.0
|
|
2
19
|
|
|
3
20
|
- useSSR: add namespaces to init options options.ns [1031](https://github.com/i18next/react-i18next/issues/1031)
|
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
|
|
|
@@ -771,7 +771,9 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
771
771
|
tFromProps = _ref.t,
|
|
772
772
|
additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
|
|
773
773
|
|
|
774
|
-
var
|
|
774
|
+
var ReactI18nContext = React.useContext(I18nContext);
|
|
775
|
+
|
|
776
|
+
var _ref2 = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
|
|
775
777
|
i18nFromContext = _ref2.i18n,
|
|
776
778
|
defaultNSFromContext = _ref2.defaultNS;
|
|
777
779
|
|
|
@@ -866,20 +868,21 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
866
868
|
setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
|
|
867
869
|
|
|
868
870
|
|
|
871
|
+
var isMounted = React.useRef(true);
|
|
869
872
|
React.useEffect(function () {
|
|
870
|
-
var isMounted = true;
|
|
871
873
|
var bindI18n = i18nOptions.bindI18n,
|
|
872
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
874
|
+
bindI18nStore = i18nOptions.bindI18nStore;
|
|
875
|
+
isMounted.current = true; // if not ready and not using suspense load the namespaces
|
|
873
876
|
// in side effect and do not call resetT if unmounted
|
|
874
877
|
|
|
875
878
|
if (!ready && !useSuspense) {
|
|
876
879
|
loadNamespaces(i18n, namespaces, function () {
|
|
877
|
-
if (isMounted) setT(getT());
|
|
880
|
+
if (isMounted.current) setT(getT());
|
|
878
881
|
});
|
|
879
882
|
}
|
|
880
883
|
|
|
881
884
|
function boundReset() {
|
|
882
|
-
if (isMounted) setT(getT());
|
|
885
|
+
if (isMounted.current) setT(getT());
|
|
883
886
|
} // bind events to trigger change, like languageChanged
|
|
884
887
|
|
|
885
888
|
|
|
@@ -887,7 +890,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
887
890
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
|
|
888
891
|
|
|
889
892
|
return function () {
|
|
890
|
-
isMounted = false;
|
|
893
|
+
isMounted.current = false;
|
|
891
894
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
892
895
|
return i18n.off(e, boundReset);
|
|
893
896
|
});
|
|
@@ -908,7 +911,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
908
911
|
|
|
909
912
|
throw new Promise(function (resolve) {
|
|
910
913
|
loadNamespaces(i18n, namespaces, function () {
|
|
911
|
-
setT(getT());
|
|
914
|
+
if (isMounted.current) setT(getT());
|
|
912
915
|
resolve();
|
|
913
916
|
});
|
|
914
917
|
});
|
|
@@ -1003,7 +1006,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
|
|
|
1003
1006
|
|
|
1004
1007
|
i18n.options.ns = Object.values(initialI18nStore).reduce(function (mem, lngResources) {
|
|
1005
1008
|
Object.keys(lngResources).forEach(function (ns) {
|
|
1006
|
-
if (mem.indexOf(ns) <
|
|
1009
|
+
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
1007
1010
|
});
|
|
1008
1011
|
return mem;
|
|
1009
1012
|
}, i18n.options.ns);
|
|
@@ -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)<-1&&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=w()&&n.useContext(O)||{},b=v.i18n,j=v.defaultNS,E=m||b||x();if(!E)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var N=h||E.t.bind(E)||function(e){return e},k=c({},S(),{},E.options&&E.options.react),I=void 0!==o?o:k.defaultTransParent,P=g||N.ns||j||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];var C=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,k)||k.transEmptyNodeValue,A=k.hashTransKey,L=u||(A?A(C):C),K=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:C,ns:P}),U=L?N(L,K):C;return I?t.createElement(I,y,V(d||a,U,E,k,K)):V(d||a,U,E,k,K)},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})}));
|
package/dist/commonjs/Trans.js
CHANGED
|
@@ -227,8 +227,9 @@ function Trans(_ref) {
|
|
|
227
227
|
i18nFromProps = _ref.i18n,
|
|
228
228
|
tFromProps = _ref.t,
|
|
229
229
|
additionalProps = (0, _objectWithoutProperties2["default"])(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
|
|
230
|
+
var ReactI18nContext = (0, _react.useContext)(_context.I18nContext);
|
|
230
231
|
|
|
231
|
-
var _ref2 = (0, _context.getHasUsedI18nextProvider)() ?
|
|
232
|
+
var _ref2 = (0, _context.getHasUsedI18nextProvider)() ? ReactI18nContext || {} : {},
|
|
232
233
|
i18nFromContext = _ref2.i18n,
|
|
233
234
|
defaultNSFromContext = _ref2.defaultNS;
|
|
234
235
|
|
package/dist/commonjs/useSSR.js
CHANGED
|
@@ -27,7 +27,7 @@ function useSSR(initialI18nStore, initialLanguage) {
|
|
|
27
27
|
|
|
28
28
|
i18n.options.ns = Object.values(initialI18nStore).reduce(function (mem, lngResources) {
|
|
29
29
|
Object.keys(lngResources).forEach(function (ns) {
|
|
30
|
-
if (mem.indexOf(ns) <
|
|
30
|
+
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
31
31
|
});
|
|
32
32
|
return mem;
|
|
33
33
|
}, i18n.options.ns);
|
|
@@ -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
|
});
|
package/dist/es/Trans.js
CHANGED
|
@@ -210,7 +210,9 @@ export function Trans(_ref) {
|
|
|
210
210
|
tFromProps = _ref.t,
|
|
211
211
|
additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
|
|
212
212
|
|
|
213
|
-
var
|
|
213
|
+
var ReactI18nContext = useContext(I18nContext);
|
|
214
|
+
|
|
215
|
+
var _ref2 = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
|
|
214
216
|
i18nFromContext = _ref2.i18n,
|
|
215
217
|
defaultNSFromContext = _ref2.defaultNS;
|
|
216
218
|
|
package/dist/es/useSSR.js
CHANGED
|
@@ -18,7 +18,7 @@ export function useSSR(initialI18nStore, initialLanguage) {
|
|
|
18
18
|
|
|
19
19
|
i18n.options.ns = Object.values(initialI18nStore).reduce(function (mem, lngResources) {
|
|
20
20
|
Object.keys(lngResources).forEach(function (ns) {
|
|
21
|
-
if (mem.indexOf(ns) <
|
|
21
|
+
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
22
22
|
});
|
|
23
23
|
return mem;
|
|
24
24
|
}, i18n.options.ns);
|
|
@@ -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
|
});
|
|
@@ -775,7 +775,9 @@
|
|
|
775
775
|
tFromProps = _ref.t,
|
|
776
776
|
additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
|
|
777
777
|
|
|
778
|
-
var
|
|
778
|
+
var ReactI18nContext = React.useContext(I18nContext);
|
|
779
|
+
|
|
780
|
+
var _ref2 = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
|
|
779
781
|
i18nFromContext = _ref2.i18n,
|
|
780
782
|
defaultNSFromContext = _ref2.defaultNS;
|
|
781
783
|
|
|
@@ -870,20 +872,21 @@
|
|
|
870
872
|
setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
|
|
871
873
|
|
|
872
874
|
|
|
875
|
+
var isMounted = React.useRef(true);
|
|
873
876
|
React.useEffect(function () {
|
|
874
|
-
var isMounted = true;
|
|
875
877
|
var bindI18n = i18nOptions.bindI18n,
|
|
876
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
878
|
+
bindI18nStore = i18nOptions.bindI18nStore;
|
|
879
|
+
isMounted.current = true; // if not ready and not using suspense load the namespaces
|
|
877
880
|
// in side effect and do not call resetT if unmounted
|
|
878
881
|
|
|
879
882
|
if (!ready && !useSuspense) {
|
|
880
883
|
loadNamespaces(i18n, namespaces, function () {
|
|
881
|
-
if (isMounted) setT(getT());
|
|
884
|
+
if (isMounted.current) setT(getT());
|
|
882
885
|
});
|
|
883
886
|
}
|
|
884
887
|
|
|
885
888
|
function boundReset() {
|
|
886
|
-
if (isMounted) setT(getT());
|
|
889
|
+
if (isMounted.current) setT(getT());
|
|
887
890
|
} // bind events to trigger change, like languageChanged
|
|
888
891
|
|
|
889
892
|
|
|
@@ -891,7 +894,7 @@
|
|
|
891
894
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
|
|
892
895
|
|
|
893
896
|
return function () {
|
|
894
|
-
isMounted = false;
|
|
897
|
+
isMounted.current = false;
|
|
895
898
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
896
899
|
return i18n.off(e, boundReset);
|
|
897
900
|
});
|
|
@@ -912,7 +915,7 @@
|
|
|
912
915
|
|
|
913
916
|
throw new Promise(function (resolve) {
|
|
914
917
|
loadNamespaces(i18n, namespaces, function () {
|
|
915
|
-
setT(getT());
|
|
918
|
+
if (isMounted.current) setT(getT());
|
|
916
919
|
resolve();
|
|
917
920
|
});
|
|
918
921
|
});
|
|
@@ -1007,7 +1010,7 @@
|
|
|
1007
1010
|
|
|
1008
1011
|
i18n.options.ns = Object.values(initialI18nStore).reduce(function (mem, lngResources) {
|
|
1009
1012
|
Object.keys(lngResources).forEach(function (ns) {
|
|
1010
|
-
if (mem.indexOf(ns) <
|
|
1013
|
+
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
1011
1014
|
});
|
|
1012
1015
|
return mem;
|
|
1013
1016
|
}, i18n.options.ns);
|
|
@@ -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)<-1&&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=w()&&n.useContext(O)||{},b=v.i18n,j=v.defaultNS,E=m||b||N();if(!E)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var x=h||E.t.bind(E)||function(e){return e},k=c({},S(),{},E.options&&E.options.react),I=void 0!==o?o:k.defaultTransParent,P=g||x.ns||j||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];var C=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,k)||k.transEmptyNodeValue,A=k.hashTransKey,L=u||(A?A(C):C),K=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:C,ns:P}),U=L?x(L,K):C;return I?t.createElement(I,y,V(d||a,U,E,k,K)):V(d||a,U,E,k,K)},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
|
@@ -775,7 +775,9 @@
|
|
|
775
775
|
tFromProps = _ref.t,
|
|
776
776
|
additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
|
|
777
777
|
|
|
778
|
-
var
|
|
778
|
+
var ReactI18nContext = React.useContext(I18nContext);
|
|
779
|
+
|
|
780
|
+
var _ref2 = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
|
|
779
781
|
i18nFromContext = _ref2.i18n,
|
|
780
782
|
defaultNSFromContext = _ref2.defaultNS;
|
|
781
783
|
|
|
@@ -870,20 +872,21 @@
|
|
|
870
872
|
setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
|
|
871
873
|
|
|
872
874
|
|
|
875
|
+
var isMounted = React.useRef(true);
|
|
873
876
|
React.useEffect(function () {
|
|
874
|
-
var isMounted = true;
|
|
875
877
|
var bindI18n = i18nOptions.bindI18n,
|
|
876
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
878
|
+
bindI18nStore = i18nOptions.bindI18nStore;
|
|
879
|
+
isMounted.current = true; // if not ready and not using suspense load the namespaces
|
|
877
880
|
// in side effect and do not call resetT if unmounted
|
|
878
881
|
|
|
879
882
|
if (!ready && !useSuspense) {
|
|
880
883
|
loadNamespaces(i18n, namespaces, function () {
|
|
881
|
-
if (isMounted) setT(getT());
|
|
884
|
+
if (isMounted.current) setT(getT());
|
|
882
885
|
});
|
|
883
886
|
}
|
|
884
887
|
|
|
885
888
|
function boundReset() {
|
|
886
|
-
if (isMounted) setT(getT());
|
|
889
|
+
if (isMounted.current) setT(getT());
|
|
887
890
|
} // bind events to trigger change, like languageChanged
|
|
888
891
|
|
|
889
892
|
|
|
@@ -891,7 +894,7 @@
|
|
|
891
894
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
|
|
892
895
|
|
|
893
896
|
return function () {
|
|
894
|
-
isMounted = false;
|
|
897
|
+
isMounted.current = false;
|
|
895
898
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
896
899
|
return i18n.off(e, boundReset);
|
|
897
900
|
});
|
|
@@ -912,7 +915,7 @@
|
|
|
912
915
|
|
|
913
916
|
throw new Promise(function (resolve) {
|
|
914
917
|
loadNamespaces(i18n, namespaces, function () {
|
|
915
|
-
setT(getT());
|
|
918
|
+
if (isMounted.current) setT(getT());
|
|
916
919
|
resolve();
|
|
917
920
|
});
|
|
918
921
|
});
|
|
@@ -1007,7 +1010,7 @@
|
|
|
1007
1010
|
|
|
1008
1011
|
i18n.options.ns = Object.values(initialI18nStore).reduce(function (mem, lngResources) {
|
|
1009
1012
|
Object.keys(lngResources).forEach(function (ns) {
|
|
1010
|
-
if (mem.indexOf(ns) <
|
|
1013
|
+
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
1011
1014
|
});
|
|
1012
1015
|
return mem;
|
|
1013
1016
|
}, i18n.options.ns);
|
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)<-1&&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=w()&&n.useContext(O)||{},b=v.i18n,j=v.defaultNS,E=m||b||N();if(!E)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var x=h||E.t.bind(E)||function(e){return e},k=c({},S(),{},E.options&&E.options.react),I=void 0!==o?o:k.defaultTransParent,P=g||x.ns||j||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];var C=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,k)||k.transEmptyNodeValue,A=k.hashTransKey,L=u||(A?A(C):C),K=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:C,ns:P}),U=L?x(L,K):C;return I?t.createElement(I,y,V(d||a,U,E,k,K)):V(d||a,U,E,k,K)},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/Trans.js
CHANGED
|
@@ -215,8 +215,9 @@ export function Trans({
|
|
|
215
215
|
t: tFromProps,
|
|
216
216
|
...additionalProps
|
|
217
217
|
}) {
|
|
218
|
+
const ReactI18nContext = useContext(I18nContext);
|
|
218
219
|
const { i18n: i18nFromContext, defaultNS: defaultNSFromContext } = getHasUsedI18nextProvider()
|
|
219
|
-
?
|
|
220
|
+
? ReactI18nContext || {}
|
|
220
221
|
: {};
|
|
221
222
|
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
222
223
|
if (!i18n) {
|
package/src/index.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ export function withTranslation(
|
|
|
98
98
|
|
|
99
99
|
export interface I18nextProviderProps {
|
|
100
100
|
i18n: i18n;
|
|
101
|
+
defaultNS?: string;
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
export const I18nextProvider: React.FunctionComponent<I18nextProviderProps>;
|
|
@@ -110,6 +111,7 @@ export interface TranslationProps {
|
|
|
110
111
|
i18n: i18n;
|
|
111
112
|
lng: string;
|
|
112
113
|
},
|
|
114
|
+
ready: boolean,
|
|
113
115
|
) => React.ReactNode;
|
|
114
116
|
ns?: Namespace;
|
|
115
117
|
i18n?: i18n;
|
package/src/useSSR.js
CHANGED
|
@@ -18,7 +18,7 @@ export function useSSR(initialI18nStore, initialLanguage, props = {}) {
|
|
|
18
18
|
// add namespaces to the config - so a languageChange call loads all namespaces needed
|
|
19
19
|
i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
|
|
20
20
|
Object.keys(lngResources).forEach(ns => {
|
|
21
|
-
if (mem.indexOf(ns) <
|
|
21
|
+
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
22
22
|
});
|
|
23
23
|
return mem;
|
|
24
24
|
}, i18n.options.ns);
|
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
|
});
|