react-i18next 10.11.0 → 10.11.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/.DS_Store ADDED
Binary file
@@ -0,0 +1 @@
1
+ custom: https://locize.com
package/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 10.11.4
2
+
3
+ - assert edge case trans component get set a key
4
+ - assert context get destructed of empty object if context gets used falsely on a component got pulled out of main tree from react-portal or similar
5
+
6
+ ### 10.11.3
7
+
8
+ - only apply initial values in useSSR, withSSR on i18next instances not being a clone (eg. created by express middleware on server) ==> don't apply on serverside
9
+
10
+ ### 10.11.2
11
+
12
+ - Reload translations whenever namespaces passed to useTranslation() change [878](https://github.com/i18next/react-i18next/pull/878)
13
+
14
+ ### 10.11.1
15
+
16
+ - fixes a regression in Trans component taking namespace from passed t function [867](https://github.com/i18next/react-i18next/issues/867#issuecomment-502395958)
17
+
1
18
  ### 10.11.0
2
19
 
3
20
  - Restore support passing the defaultNS via I18nextProvider prop [860](https://github.com/i18next/react-i18next/pull/860)
package/README.md CHANGED
@@ -38,7 +38,7 @@ npm i react-i18next@legacy
38
38
 
39
39
  The documentation is published on [react.i18next.com](https://react.i18next.com)
40
40
 
41
- ### How will my code look like?
41
+ ### What will my code look like?
42
42
 
43
43
  **Before:** Your react code would have looked something like:
44
44
 
@@ -643,7 +643,9 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
643
643
  key: i
644
644
  }), translationContent));
645
645
  } else {
646
- mem.push(child);
646
+ mem.push(React__default.cloneElement(child, _objectSpread({}, child.props, {
647
+ key: i
648
+ })));
647
649
  }
648
650
  } else if (node.type === 'text') {
649
651
  mem.push(node.content);
@@ -677,7 +679,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
677
679
  tFromProps = _ref.t,
678
680
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
679
681
 
680
- const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
682
+ const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {},
681
683
  i18nFromContext = _ref2.i18n,
682
684
  defaultNSFromContext = _ref2.defaultNS;
683
685
 
@@ -688,13 +690,13 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
688
690
  return children;
689
691
  }
690
692
 
691
- const t = tFromProps || i18n.t.bind(i18n);
693
+ const t = tFromProps || i18n.t.bind(i18n) || (k => k);
692
694
 
693
695
  const reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react);
694
696
 
695
697
  const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
696
698
 
697
- let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
699
+ let namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
698
700
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
699
701
  const defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
700
702
  const hashTransKey = reactI18nextOptions.hashTransKey;
@@ -722,7 +724,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
722
724
  // assert we have the needed i18nInstance
723
725
  const i18nFromProps = props.i18n;
724
726
 
725
- const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
727
+ const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {},
726
728
  i18nFromContext = _ref.i18n,
727
729
  defaultNSFromContext = _ref.defaultNS;
728
730
 
@@ -789,7 +791,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
789
791
  if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
790
792
  if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
791
793
  };
792
- }, []); // define props to trigger using effect on rerender (none here)
794
+ }, [namespaces.join()]); // re-run effect whenever list of namespaces changes
793
795
 
794
796
  const ret = [t.t, i18n, ready];
795
797
  ret.t = t.t;
@@ -874,7 +876,10 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
874
876
  const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
875
877
  i18nFromContext = _ref.i18n;
876
878
 
877
- const i18n = i18nFromProps || i18nFromContext || getI18n(); // nextjs / SSR: getting data from next.js or other ssr stack
879
+ const i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request
880
+ // -> do not set initial stuff on server side
881
+
882
+ if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack
878
883
 
879
884
  if (initialI18nStore && !i18n.initializedStoreOnce) {
880
885
  i18n.services.resourceStore.data = initialI18nStore;
@@ -1 +1 @@
1
- define(["exports","react"],function(e,t){"use strict";var n="default"in t?t.default:t;function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(t){r(e,t,n[t])})}return e}function o(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var s={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},c=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,l=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,u=Object.create?Object.create(null):{};function p(e,t,n,r,i){var o=t.indexOf("<",r),a=t.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&o>-1&&n+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(f,"")+"</"+t.name+">"}}var d={parse:function(e,t){t||(t={}),t.components||(t.components=u);var n,r=[],i=-1,o=[],a={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="</"+n.name+">")return;f=!1}var d,g="/"!==l.charAt(1),h=0===l.indexOf("\x3c!--"),m=u+l.length,y=e.charAt(m);g&&!h&&(i++,"tag"===(n=function(e){var t,n=0,r=!0,i={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(c,function(o){if("="===o)return r=!0,void n++;r?0===n?((s[o]||"/"===e.charAt(e.length-2))&&(i.voidElement=!0),i.name=o):(i.attrs[t]=o.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(i.attrs[t]=t),t=o),n++,r=!1}),i}(l)).type&&t.components[n.name]&&(n.type="component",f=!0),n.voidElement||f||!y||"<"===y||p(n.children,e,i,m,t.ignoreWhitespace),a[n.tagName]=n,0===i&&r.push(n),(d=o[i-1])&&d.children.push(n),o[i]=n),(h||!g||n.voidElement)&&(h||i--,!f&&"<"!==y&&y&&p(d=-1===i?r:o[i].children,e,i,m,t.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,t.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,t){return e+f("",t)},"")}};let g,h,m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0};const y=n.createContext();function b(){return h}function v(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m=i({},m,e)}function O(){return m}class S{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function j(e){g=e}function w(){return g}const N={type:"3rdParty",init(e){v(e.options.react),j(e)}};function E(e){return t=>new Promise(n=>{const r=$();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function $(){const e=w(),t=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],n={},r={};return e.languages.forEach(n=>{r[n]={},t.forEach(t=>{r[n][t]=e.getResourceBundle(n,t)||{}})}),n.initialI18nStore=r,n.initialLanguage=e.language,n}function x(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t)}}const I={};function k(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&I[t[0]]||("string"==typeof t[0]&&(I[t[0]]=new Date),x(...t))}function P(e,t,n){e.loadNamespaces(t,()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout(()=>{e.off("initialized",t)},0),n()};e.on("initialized",t)}})}function R(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function A(e){return e&&(e.children||e.props&&e.props.children)}function C(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function T(e,t,r,o,a){if(""===t)return[];const s=o.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(s.join("|")).test(t);if(!e&&!c)return[t];const l={};!function e(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(t=>{"string"!=typeof t&&(A(t)?e(C(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))})}(e),t=r.services.interpolator.interpolate(t,i({},l,a),r.language);const u=function e(t,r){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]),r.reduce((r,a,s)=>{const l=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){const u=t[parseInt(a.name,10)]||{},p=n.isValidElement(u);if("string"==typeof u)r.push(u);else if(A(u)){const t=C(u),o=e(t,a.children),c=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>n.isValidElement(e))}(t)&&0===o.length?t:o;u.dummy&&(u.children=c),r.push(n.cloneElement(u,i({},u.props,{key:s}),c))}else if(c&&"object"==typeof u&&u.dummy&&!p){const o=e(t,a.children);r.push(n.cloneElement(u,i({},u.props,{key:s}),o))}else if(isNaN(a.name)&&o.transSupportBasicHtmlNodes)if(a.voidElement)r.push(n.createElement(a.name,{key:`${a.name}-${s}`}));else{const i=e(t,a.children);r.push(n.createElement(a.name,{key:`${a.name}-${s}`},i))}else if("object"!=typeof u||p)1===a.children.length&&l?r.push(n.cloneElement(u,i({},u.props,{key:s}),l)):r.push(u);else{const e=a.children[0]?l:null;e&&r.push(e)}}else"text"===a.type&&r.push(a.content);return r},[])}([{dummy:!0,children:e}],d.parse(`<0>${t}</0>`));return C(u[0])}function z(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=n.i18n,o=b()?t.useContext(y):{},s=o.i18n,c=o.defaultNS,l=r||s||w();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new S),!l){k("You will need pass in an i18next instance by using initReactI18next");const e=[e=>e,{},!0];return e.t=(e=>e),e.i18n={},e.ready=!0,e}const u=i({},O(),l.options.react),p=n.useSuspense,f=void 0===p?u.useSuspense:p;let d=e||c||l.options&&l.options.defaultNS;d="string"==typeof d?[d]:d||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(d);const g=(l.isInitialized||l.initializedStoreOnce)&&d.every(e=>(function(e,t){if(!t.languages||!t.languages.length)return k("i18n.languages were undefined or empty",t.languages),!0;const n=t.languages[0],r=!!t.options&&t.options.fallbackLng,i=t.languages[t.languages.length-1];if("cimode"===n.toLowerCase())return!0;const o=(e,n)=>{const r=t.services.backendConnector.state[`${e}|${n}`];return-1===r||2===r};return!!t.hasResourceBundle(n,e)||!t.services.backendConnector.backend||!(!o(n,e)||r&&!o(i,e))})(e,l));function h(){return{t:l.getFixedT(null,"fallback"===u.nsMode?d:d[0])}}const m=a(t.useState(h()),2),v=m[0],j=m[1];t.useEffect(()=>{let e=!0;const t=u.bindI18n,n=u.bindI18nStore;function r(){e&&j(h())}return g||f||P(l,d,()=>{e&&j(h())}),t&&l&&l.on(t,r),n&&l&&l.store.on(n,r),()=>{e=!1,t&&l&&t.split(" ").forEach(e=>l.off(e,r)),n&&l&&n.split(" ").forEach(e=>l.store.off(e,r))}},[]);const N=[v.t,l,g];if(N.t=v.t,N.i18n=l,N.ready=g,g)return N;if(!g&&!f)return N;throw new Promise(e=>{P(l,d,()=>{j(h()),e()})})}function L(e,n){const r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,i=(b()?t.useContext(y):{}).i18n,o=r||i||w();e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),n&&!o.initializedLanguageOnce&&(o.changeLanguage(n),o.initializedLanguageOnce=!0)}e.Trans=function(e){let r=e.children,a=e.count,s=e.parent,c=e.i18nKey,l=e.tOptions,u=e.values,p=e.defaults,f=e.components,d=e.ns,g=e.i18n,h=e.t,m=o(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]);const v=b()?t.useContext(y):{},S=v.i18n,j=v.defaultNS,N=g||S||w();if(!N)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const E=h||N.t.bind(N),$=i({},O(),N.options&&N.options.react),I=void 0!==s?s:$.defaultTransParent;let P=d||j||N.options&&N.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];const R=p||function e(t,r,o,a){if(!r)return"";"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);const s=a.transKeepBasicHtmlNodesFor||[];return r.forEach((r,o)=>{const c=`${o}`;if("string"==typeof r)t=`${t}${r}`;else if(A(r)){const n=s.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof A(r)?r.type:c;t=r.props&&r.props.i18nIsDynamicList?`${t}<${n}></${n}>`:`${t}<${n}>${e("",C(r),o+1,a)}</${n}>`}else if(n.isValidElement(r))t=s.indexOf(r.type)>-1&&0===Object.keys(r.props).length?`${t}<${r.type}/>`:`${t}<${c}></${c}>`;else if("object"==typeof r){const e=i({},r),n=e.format;delete e.format;const o=Object.keys(e);n&&1===o.length?t=`${t}{{${o[0]}, ${n}}}`:1===o.length?t=`${t}{{${o[0]}}}`:x("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else x("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}}.",r)}),t}("",r,0,$)||$.transEmptyNodeValue,z=$.hashTransKey,L=c||(z?z(R):R),B=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:R,count:a,ns:P}),V=L?E(L,B):R;return I?n.createElement(I,m,T(f||r,V,N,$,B)):T(f||r,V,N,$,B)},e.useTranslation=z,e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function o(o,s){const c=a(z(e,o),3),l=i({},o,{t:c[0],i18n:c[1],tReady:c[2]});return t.withRef&&s&&(l.ref=s),n.createElement(r,l)}return o.displayName=`withI18nextTranslation(${R(r)})`,o.WrappedComponent=r,t.withRef?n.forwardRef(o):o}},e.Translation=function(e){const t=e.ns,n=e.children,r=a(z(t,o(e,["ns","children"])),3),i=r[0],s=r[1],c=r[2];return n(i,{i18n:s,lng:s.language},c)},e.I18nextProvider=function(e){let t=e.i18n,r=e.defaultNS,i=e.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t,defaultNS:r}},i)},e.withSSR=function(){return function(e){function t(t){let r=t.initialI18nStore,a=t.initialLanguage,s=o(t,["initialI18nStore","initialLanguage"]);return L(r,a),n.createElement(e,i({},s))}return t.getInitialProps=E(e),t.displayName=`withI18nextSSR(${R(e)})`,t.WrappedComponent=e,t}},e.useSSR=L,e.I18nContext=y,e.initReactI18next=N,e.setDefaults=v,e.getDefaults=O,e.setI18n=j,e.getI18n=w,e.composeInitialProps=E,e.getInitialProps=$,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ define(["exports","react"],function(e,t){"use strict";var n="default"in t?t.default:t;function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(t){r(e,t,n[t])})}return e}function o(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var s={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},c=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,l=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,u=Object.create?Object.create(null):{};function p(e,t,n,r,i){var o=t.indexOf("<",r),a=t.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&o>-1&&n+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(f,"")+"</"+t.name+">"}}var d={parse:function(e,t){t||(t={}),t.components||(t.components=u);var n,r=[],i=-1,o=[],a={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="</"+n.name+">")return;f=!1}var d,g="/"!==l.charAt(1),h=0===l.indexOf("\x3c!--"),m=u+l.length,y=e.charAt(m);g&&!h&&(i++,"tag"===(n=function(e){var t,n=0,r=!0,i={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(c,function(o){if("="===o)return r=!0,void n++;r?0===n?((s[o]||"/"===e.charAt(e.length-2))&&(i.voidElement=!0),i.name=o):(i.attrs[t]=o.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(i.attrs[t]=t),t=o),n++,r=!1}),i}(l)).type&&t.components[n.name]&&(n.type="component",f=!0),n.voidElement||f||!y||"<"===y||p(n.children,e,i,m,t.ignoreWhitespace),a[n.tagName]=n,0===i&&r.push(n),(d=o[i-1])&&d.children.push(n),o[i]=n),(h||!g||n.voidElement)&&(h||i--,!f&&"<"!==y&&y&&p(d=-1===i?r:o[i].children,e,i,m,t.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,t.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,t){return e+f("",t)},"")}};let g,h,m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0};const y=n.createContext();function b(){return h}function v(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m=i({},m,e)}function O(){return m}class S{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function j(e){g=e}function w(){return g}const E={type:"3rdParty",init(e){v(e.options.react),j(e)}};function N(e){return t=>new Promise(n=>{const r=$();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function $(){const e=w(),t=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],n={},r={};return e.languages.forEach(n=>{r[n]={},t.forEach(t=>{r[n][t]=e.getResourceBundle(n,t)||{}})}),n.initialI18nStore=r,n.initialLanguage=e.language,n}function x(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t)}}const I={};function k(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&I[t[0]]||("string"==typeof t[0]&&(I[t[0]]=new Date),x(...t))}function P(e,t,n){e.loadNamespaces(t,()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout(()=>{e.off("initialized",t)},0),n()};e.on("initialized",t)}})}function C(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function R(e){return e&&(e.children||e.props&&e.props.children)}function A(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function T(e,t,r,o,a){if(""===t)return[];const s=o.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(s.join("|")).test(t);if(!e&&!c)return[t];const l={};!function e(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(t=>{"string"!=typeof t&&(R(t)?e(A(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))})}(e),t=r.services.interpolator.interpolate(t,i({},l,a),r.language);const u=function e(t,r){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]),r.reduce((r,a,s)=>{const l=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){const u=t[parseInt(a.name,10)]||{},p=n.isValidElement(u);if("string"==typeof u)r.push(u);else if(R(u)){const t=A(u),o=e(t,a.children),c=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>n.isValidElement(e))}(t)&&0===o.length?t:o;u.dummy&&(u.children=c),r.push(n.cloneElement(u,i({},u.props,{key:s}),c))}else if(c&&"object"==typeof u&&u.dummy&&!p){const o=e(t,a.children);r.push(n.cloneElement(u,i({},u.props,{key:s}),o))}else if(isNaN(a.name)&&o.transSupportBasicHtmlNodes)if(a.voidElement)r.push(n.createElement(a.name,{key:`${a.name}-${s}`}));else{const i=e(t,a.children);r.push(n.createElement(a.name,{key:`${a.name}-${s}`},i))}else if("object"!=typeof u||p)1===a.children.length&&l?r.push(n.cloneElement(u,i({},u.props,{key:s}),l)):r.push(n.cloneElement(u,i({},u.props,{key:s})));else{const e=a.children[0]?l:null;e&&r.push(e)}}else"text"===a.type&&r.push(a.content);return r},[])}([{dummy:!0,children:e}],d.parse(`<0>${t}</0>`));return A(u[0])}function z(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=n.i18n,o=b()&&t.useContext(y)||{},s=o.i18n,c=o.defaultNS,l=r||s||w();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new S),!l){k("You will need pass in an i18next instance by using initReactI18next");const e=[e=>e,{},!0];return e.t=(e=>e),e.i18n={},e.ready=!0,e}const u=i({},O(),l.options.react),p=n.useSuspense,f=void 0===p?u.useSuspense:p;let d=e||c||l.options&&l.options.defaultNS;d="string"==typeof d?[d]:d||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(d);const g=(l.isInitialized||l.initializedStoreOnce)&&d.every(e=>(function(e,t){if(!t.languages||!t.languages.length)return k("i18n.languages were undefined or empty",t.languages),!0;const n=t.languages[0],r=!!t.options&&t.options.fallbackLng,i=t.languages[t.languages.length-1];if("cimode"===n.toLowerCase())return!0;const o=(e,n)=>{const r=t.services.backendConnector.state[`${e}|${n}`];return-1===r||2===r};return!!t.hasResourceBundle(n,e)||!t.services.backendConnector.backend||!(!o(n,e)||r&&!o(i,e))})(e,l));function h(){return{t:l.getFixedT(null,"fallback"===u.nsMode?d:d[0])}}const m=a(t.useState(h()),2),v=m[0],j=m[1];t.useEffect(()=>{let e=!0;const t=u.bindI18n,n=u.bindI18nStore;function r(){e&&j(h())}return g||f||P(l,d,()=>{e&&j(h())}),t&&l&&l.on(t,r),n&&l&&l.store.on(n,r),()=>{e=!1,t&&l&&t.split(" ").forEach(e=>l.off(e,r)),n&&l&&n.split(" ").forEach(e=>l.store.off(e,r))}},[d.join()]);const E=[v.t,l,g];if(E.t=v.t,E.i18n=l,E.ready=g,g)return E;if(!g&&!f)return E;throw new Promise(e=>{P(l,d,()=>{j(h()),e()})})}function L(e,n){const r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,i=(b()?t.useContext(y):{}).i18n,o=r||i||w();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),n&&!o.initializedLanguageOnce&&(o.changeLanguage(n),o.initializedLanguageOnce=!0))}e.Trans=function(e){let r=e.children,a=e.count,s=e.parent,c=e.i18nKey,l=e.tOptions,u=e.values,p=e.defaults,f=e.components,d=e.ns,g=e.i18n,h=e.t,m=o(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]);const v=b()&&t.useContext(y)||{},S=v.i18n,j=v.defaultNS,E=g||S||w();if(!E)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const N=h||E.t.bind(E)||(e=>e),$=i({},O(),E.options&&E.options.react),I=void 0!==s?s:$.defaultTransParent;let P=d||N.ns||j||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];const C=p||function e(t,r,o,a){if(!r)return"";"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);const s=a.transKeepBasicHtmlNodesFor||[];return r.forEach((r,o)=>{const c=`${o}`;if("string"==typeof r)t=`${t}${r}`;else if(R(r)){const n=s.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof R(r)?r.type:c;t=r.props&&r.props.i18nIsDynamicList?`${t}<${n}></${n}>`:`${t}<${n}>${e("",A(r),o+1,a)}</${n}>`}else if(n.isValidElement(r))t=s.indexOf(r.type)>-1&&0===Object.keys(r.props).length?`${t}<${r.type}/>`:`${t}<${c}></${c}>`;else if("object"==typeof r){const e=i({},r),n=e.format;delete e.format;const o=Object.keys(e);n&&1===o.length?t=`${t}{{${o[0]}, ${n}}}`:1===o.length?t=`${t}{{${o[0]}}}`:x("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else x("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}}.",r)}),t}("",r,0,$)||$.transEmptyNodeValue,z=$.hashTransKey,L=c||(z?z(C):C),B=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:C,count:a,ns:P}),V=L?N(L,B):C;return I?n.createElement(I,m,T(f||r,V,E,$,B)):T(f||r,V,E,$,B)},e.useTranslation=z,e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function o(o,s){const c=a(z(e,o),3),l=i({},o,{t:c[0],i18n:c[1],tReady:c[2]});return t.withRef&&s&&(l.ref=s),n.createElement(r,l)}return o.displayName=`withI18nextTranslation(${C(r)})`,o.WrappedComponent=r,t.withRef?n.forwardRef(o):o}},e.Translation=function(e){const t=e.ns,n=e.children,r=a(z(t,o(e,["ns","children"])),3),i=r[0],s=r[1],c=r[2];return n(i,{i18n:s,lng:s.language},c)},e.I18nextProvider=function(e){let t=e.i18n,r=e.defaultNS,i=e.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t,defaultNS:r}},i)},e.withSSR=function(){return function(e){function t(t){let r=t.initialI18nStore,a=t.initialLanguage,s=o(t,["initialI18nStore","initialLanguage"]);return L(r,a),n.createElement(e,i({},s))}return t.getInitialProps=N(e),t.displayName=`withI18nextSSR(${C(e)})`,t.WrappedComponent=e,t}},e.useSSR=L,e.I18nContext=y,e.initReactI18next=E,e.setDefaults=v,e.getDefaults=O,e.setI18n=j,e.getI18n=w,e.composeInitialProps=N,e.getInitialProps=$,Object.defineProperty(e,"__esModule",{value:!0})});
@@ -174,7 +174,9 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
174
174
  key: i
175
175
  }), translationContent));
176
176
  } else {
177
- mem.push(child);
177
+ mem.push(_react.default.cloneElement(child, (0, _objectSpread2.default)({}, child.props, {
178
+ key: i
179
+ })));
178
180
  }
179
181
  } else if (node.type === 'text') {
180
182
  mem.push(node.content);
@@ -208,7 +210,7 @@ function Trans(_ref) {
208
210
  tFromProps = _ref.t,
209
211
  additionalProps = (0, _objectWithoutProperties2.default)(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
210
212
 
211
- var _ref2 = (0, _context.getHasUsedI18nextProvider)() ? (0, _react.useContext)(_context.I18nContext) : {},
213
+ var _ref2 = (0, _context.getHasUsedI18nextProvider)() ? (0, _react.useContext)(_context.I18nContext) || {} : {},
212
214
  i18nFromContext = _ref2.i18n,
213
215
  defaultNSFromContext = _ref2.defaultNS;
214
216
 
@@ -219,11 +221,14 @@ function Trans(_ref) {
219
221
  return children;
220
222
  }
221
223
 
222
- var t = tFromProps || i18n.t.bind(i18n);
224
+ var t = tFromProps || i18n.t.bind(i18n) || function (k) {
225
+ return k;
226
+ };
227
+
223
228
  var reactI18nextOptions = (0, _objectSpread2.default)({}, (0, _context.getDefaults)(), i18n.options && i18n.options.react);
224
229
  var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
225
230
 
226
- var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
231
+ var namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
227
232
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
228
233
  var defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
229
234
  var hashTransKey = reactI18nextOptions.hashTransKey;
@@ -16,7 +16,10 @@ function useSSR(initialI18nStore, initialLanguage) {
16
16
  var _ref = (0, _context.getHasUsedI18nextProvider)() ? (0, _react.useContext)(_context.I18nContext) : {},
17
17
  i18nFromContext = _ref.i18n;
18
18
 
19
- var i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)(); // nextjs / SSR: getting data from next.js or other ssr stack
19
+ var i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request
20
+ // -> do not set initial stuff on server side
21
+
22
+ if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack
20
23
 
21
24
  if (initialI18nStore && !i18n.initializedStoreOnce) {
22
25
  i18n.services.resourceStore.data = initialI18nStore;
@@ -22,7 +22,7 @@ function useTranslation(ns) {
22
22
  // assert we have the needed i18nInstance
23
23
  var i18nFromProps = props.i18n;
24
24
 
25
- var _ref = (0, _context.getHasUsedI18nextProvider)() ? (0, _react.useContext)(_context.I18nContext) : {},
25
+ var _ref = (0, _context.getHasUsedI18nextProvider)() ? (0, _react.useContext)(_context.I18nContext) || {} : {},
26
26
  i18nFromContext = _ref.i18n,
27
27
  defaultNSFromContext = _ref.defaultNS;
28
28
 
@@ -98,7 +98,7 @@ function useTranslation(ns) {
98
98
  return i18n.store.off(e, boundReset);
99
99
  });
100
100
  };
101
- }, []); // define props to trigger using effect on rerender (none here)
101
+ }, [namespaces.join()]); // re-run effect whenever list of namespaces changes
102
102
 
103
103
  var ret = [t.t, i18n, ready];
104
104
  ret.t = t.t;
package/dist/es/Trans.js CHANGED
@@ -156,7 +156,9 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
156
156
  key: i
157
157
  }), translationContent));
158
158
  } else {
159
- mem.push(child);
159
+ mem.push(React.cloneElement(child, _objectSpread({}, child.props, {
160
+ key: i
161
+ })));
160
162
  }
161
163
  } else if (node.type === 'text') {
162
164
  mem.push(node.content);
@@ -190,7 +192,7 @@ export function Trans(_ref) {
190
192
  tFromProps = _ref.t,
191
193
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
192
194
 
193
- var _ref2 = getHasUsedI18nextProvider() ? useContext(I18nContext) : {},
195
+ var _ref2 = getHasUsedI18nextProvider() ? useContext(I18nContext) || {} : {},
194
196
  i18nFromContext = _ref2.i18n,
195
197
  defaultNSFromContext = _ref2.defaultNS;
196
198
 
@@ -201,13 +203,15 @@ export function Trans(_ref) {
201
203
  return children;
202
204
  }
203
205
 
204
- var t = tFromProps || i18n.t.bind(i18n);
206
+ var t = tFromProps || i18n.t.bind(i18n) || function (k) {
207
+ return k;
208
+ };
205
209
 
206
210
  var reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react);
207
211
 
208
212
  var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
209
213
 
210
- var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
214
+ var namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
211
215
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
212
216
  var defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
213
217
  var hashTransKey = reactI18nextOptions.hashTransKey;
package/dist/es/useSSR.js CHANGED
@@ -7,7 +7,10 @@ export function useSSR(initialI18nStore, initialLanguage) {
7
7
  var _ref = getHasUsedI18nextProvider() ? useContext(I18nContext) : {},
8
8
  i18nFromContext = _ref.i18n;
9
9
 
10
- var i18n = i18nFromProps || i18nFromContext || getI18n(); // nextjs / SSR: getting data from next.js or other ssr stack
10
+ var i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request
11
+ // -> do not set initial stuff on server side
12
+
13
+ if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack
11
14
 
12
15
  if (initialI18nStore && !i18n.initializedStoreOnce) {
13
16
  i18n.services.resourceStore.data = initialI18nStore;
@@ -8,7 +8,7 @@ export function useTranslation(ns) {
8
8
  // assert we have the needed i18nInstance
9
9
  var i18nFromProps = props.i18n;
10
10
 
11
- var _ref = getHasUsedI18nextProvider() ? useContext(I18nContext) : {},
11
+ var _ref = getHasUsedI18nextProvider() ? useContext(I18nContext) || {} : {},
12
12
  i18nFromContext = _ref.i18n,
13
13
  defaultNSFromContext = _ref.defaultNS;
14
14
 
@@ -85,7 +85,7 @@ export function useTranslation(ns) {
85
85
  return i18n.store.off(e, boundReset);
86
86
  });
87
87
  };
88
- }, []); // define props to trigger using effect on rerender (none here)
88
+ }, [namespaces.join()]); // re-run effect whenever list of namespaces changes
89
89
 
90
90
  var ret = [t.t, i18n, ready];
91
91
  ret.t = t.t;
@@ -647,7 +647,9 @@
647
647
  key: i
648
648
  }), translationContent));
649
649
  } else {
650
- mem.push(child);
650
+ mem.push(React__default.cloneElement(child, _objectSpread({}, child.props, {
651
+ key: i
652
+ })));
651
653
  }
652
654
  } else if (node.type === 'text') {
653
655
  mem.push(node.content);
@@ -681,7 +683,7 @@
681
683
  tFromProps = _ref.t,
682
684
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
683
685
 
684
- const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
686
+ const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {},
685
687
  i18nFromContext = _ref2.i18n,
686
688
  defaultNSFromContext = _ref2.defaultNS;
687
689
 
@@ -692,13 +694,13 @@
692
694
  return children;
693
695
  }
694
696
 
695
- const t = tFromProps || i18n.t.bind(i18n);
697
+ const t = tFromProps || i18n.t.bind(i18n) || (k => k);
696
698
 
697
699
  const reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react);
698
700
 
699
701
  const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
700
702
 
701
- let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
703
+ let namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
702
704
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
703
705
  const defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
704
706
  const hashTransKey = reactI18nextOptions.hashTransKey;
@@ -726,7 +728,7 @@
726
728
  // assert we have the needed i18nInstance
727
729
  const i18nFromProps = props.i18n;
728
730
 
729
- const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
731
+ const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {},
730
732
  i18nFromContext = _ref.i18n,
731
733
  defaultNSFromContext = _ref.defaultNS;
732
734
 
@@ -793,7 +795,7 @@
793
795
  if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
794
796
  if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
795
797
  };
796
- }, []); // define props to trigger using effect on rerender (none here)
798
+ }, [namespaces.join()]); // re-run effect whenever list of namespaces changes
797
799
 
798
800
  const ret = [t.t, i18n, ready];
799
801
  ret.t = t.t;
@@ -878,7 +880,10 @@
878
880
  const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
879
881
  i18nFromContext = _ref.i18n;
880
882
 
881
- const i18n = i18nFromProps || i18nFromContext || getI18n(); // nextjs / SSR: getting data from next.js or other ssr stack
883
+ const i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request
884
+ // -> do not set initial stuff on server side
885
+
886
+ if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack
882
887
 
883
888
  if (initialI18nStore && !i18n.initializedStoreOnce) {
884
889
  i18n.services.resourceStore.data = initialI18nStore;
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ReactI18next={},e.React)}(this,function(e,t){"use strict";var n="default"in t?t.default:t;function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(t){r(e,t,n[t])})}return e}function o(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var s={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},c=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,l=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,u=Object.create?Object.create(null):{};function p(e,t,n,r,i){var o=t.indexOf("<",r),a=t.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&o>-1&&n+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(f,"")+"</"+t.name+">"}}var d={parse:function(e,t){t||(t={}),t.components||(t.components=u);var n,r=[],i=-1,o=[],a={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="</"+n.name+">")return;f=!1}var d,g="/"!==l.charAt(1),h=0===l.indexOf("\x3c!--"),m=u+l.length,y=e.charAt(m);g&&!h&&(i++,"tag"===(n=function(e){var t,n=0,r=!0,i={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(c,function(o){if("="===o)return r=!0,void n++;r?0===n?((s[o]||"/"===e.charAt(e.length-2))&&(i.voidElement=!0),i.name=o):(i.attrs[t]=o.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(i.attrs[t]=t),t=o),n++,r=!1}),i}(l)).type&&t.components[n.name]&&(n.type="component",f=!0),n.voidElement||f||!y||"<"===y||p(n.children,e,i,m,t.ignoreWhitespace),a[n.tagName]=n,0===i&&r.push(n),(d=o[i-1])&&d.children.push(n),o[i]=n),(h||!g||n.voidElement)&&(h||i--,!f&&"<"!==y&&y&&p(d=-1===i?r:o[i].children,e,i,m,t.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,t.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,t){return e+f("",t)},"")}};let g,h,m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0};const y=n.createContext();function b(){return h}function v(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m=i({},m,e)}function O(){return m}class S{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function j(e){g=e}function w(){return g}const N={type:"3rdParty",init(e){v(e.options.react),j(e)}};function x(e){return t=>new Promise(n=>{const r=E();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function E(){const e=w(),t=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],n={},r={};return e.languages.forEach(n=>{r[n]={},t.forEach(t=>{r[n][t]=e.getResourceBundle(n,t)||{}})}),n.initialI18nStore=r,n.initialLanguage=e.language,n}function $(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t)}}const I={};function k(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&I[t[0]]||("string"==typeof t[0]&&(I[t[0]]=new Date),$(...t))}function P(e,t,n){e.loadNamespaces(t,()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout(()=>{e.off("initialized",t)},0),n()};e.on("initialized",t)}})}function R(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function A(e){return e&&(e.children||e.props&&e.props.children)}function C(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function T(e,t,r,o,a){if(""===t)return[];const s=o.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(s.join("|")).test(t);if(!e&&!c)return[t];const l={};!function e(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(t=>{"string"!=typeof t&&(A(t)?e(C(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))})}(e),t=r.services.interpolator.interpolate(t,i({},l,a),r.language);const u=function e(t,r){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]),r.reduce((r,a,s)=>{const l=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){const u=t[parseInt(a.name,10)]||{},p=n.isValidElement(u);if("string"==typeof u)r.push(u);else if(A(u)){const t=C(u),o=e(t,a.children),c=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>n.isValidElement(e))}(t)&&0===o.length?t:o;u.dummy&&(u.children=c),r.push(n.cloneElement(u,i({},u.props,{key:s}),c))}else if(c&&"object"==typeof u&&u.dummy&&!p){const o=e(t,a.children);r.push(n.cloneElement(u,i({},u.props,{key:s}),o))}else if(isNaN(a.name)&&o.transSupportBasicHtmlNodes)if(a.voidElement)r.push(n.createElement(a.name,{key:`${a.name}-${s}`}));else{const i=e(t,a.children);r.push(n.createElement(a.name,{key:`${a.name}-${s}`},i))}else if("object"!=typeof u||p)1===a.children.length&&l?r.push(n.cloneElement(u,i({},u.props,{key:s}),l)):r.push(u);else{const e=a.children[0]?l:null;e&&r.push(e)}}else"text"===a.type&&r.push(a.content);return r},[])}([{dummy:!0,children:e}],d.parse(`<0>${t}</0>`));return C(u[0])}function z(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=n.i18n,o=b()?t.useContext(y):{},s=o.i18n,c=o.defaultNS,l=r||s||w();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new S),!l){k("You will need pass in an i18next instance by using initReactI18next");const e=[e=>e,{},!0];return e.t=(e=>e),e.i18n={},e.ready=!0,e}const u=i({},O(),l.options.react),p=n.useSuspense,f=void 0===p?u.useSuspense:p;let d=e||c||l.options&&l.options.defaultNS;d="string"==typeof d?[d]:d||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(d);const g=(l.isInitialized||l.initializedStoreOnce)&&d.every(e=>(function(e,t){if(!t.languages||!t.languages.length)return k("i18n.languages were undefined or empty",t.languages),!0;const n=t.languages[0],r=!!t.options&&t.options.fallbackLng,i=t.languages[t.languages.length-1];if("cimode"===n.toLowerCase())return!0;const o=(e,n)=>{const r=t.services.backendConnector.state[`${e}|${n}`];return-1===r||2===r};return!!t.hasResourceBundle(n,e)||!t.services.backendConnector.backend||!(!o(n,e)||r&&!o(i,e))})(e,l));function h(){return{t:l.getFixedT(null,"fallback"===u.nsMode?d:d[0])}}const m=a(t.useState(h()),2),v=m[0],j=m[1];t.useEffect(()=>{let e=!0;const t=u.bindI18n,n=u.bindI18nStore;function r(){e&&j(h())}return g||f||P(l,d,()=>{e&&j(h())}),t&&l&&l.on(t,r),n&&l&&l.store.on(n,r),()=>{e=!1,t&&l&&t.split(" ").forEach(e=>l.off(e,r)),n&&l&&n.split(" ").forEach(e=>l.store.off(e,r))}},[]);const N=[v.t,l,g];if(N.t=v.t,N.i18n=l,N.ready=g,g)return N;if(!g&&!f)return N;throw new Promise(e=>{P(l,d,()=>{j(h()),e()})})}function L(e,n){const r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,i=(b()?t.useContext(y):{}).i18n,o=r||i||w();e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),n&&!o.initializedLanguageOnce&&(o.changeLanguage(n),o.initializedLanguageOnce=!0)}e.Trans=function(e){let r=e.children,a=e.count,s=e.parent,c=e.i18nKey,l=e.tOptions,u=e.values,p=e.defaults,f=e.components,d=e.ns,g=e.i18n,h=e.t,m=o(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]);const v=b()?t.useContext(y):{},S=v.i18n,j=v.defaultNS,N=g||S||w();if(!N)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const x=h||N.t.bind(N),E=i({},O(),N.options&&N.options.react),I=void 0!==s?s:E.defaultTransParent;let P=d||j||N.options&&N.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];const R=p||function e(t,r,o,a){if(!r)return"";"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);const s=a.transKeepBasicHtmlNodesFor||[];return r.forEach((r,o)=>{const c=`${o}`;if("string"==typeof r)t=`${t}${r}`;else if(A(r)){const n=s.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof A(r)?r.type:c;t=r.props&&r.props.i18nIsDynamicList?`${t}<${n}></${n}>`:`${t}<${n}>${e("",C(r),o+1,a)}</${n}>`}else if(n.isValidElement(r))t=s.indexOf(r.type)>-1&&0===Object.keys(r.props).length?`${t}<${r.type}/>`:`${t}<${c}></${c}>`;else if("object"==typeof r){const e=i({},r),n=e.format;delete e.format;const o=Object.keys(e);n&&1===o.length?t=`${t}{{${o[0]}, ${n}}}`:1===o.length?t=`${t}{{${o[0]}}}`:$("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else $("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}}.",r)}),t}("",r,0,E)||E.transEmptyNodeValue,z=E.hashTransKey,L=c||(z?z(R):R),B=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:R,count:a,ns:P}),V=L?x(L,B):R;return I?n.createElement(I,m,T(f||r,V,N,E,B)):T(f||r,V,N,E,B)},e.useTranslation=z,e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function o(o,s){const c=a(z(e,o),3),l=i({},o,{t:c[0],i18n:c[1],tReady:c[2]});return t.withRef&&s&&(l.ref=s),n.createElement(r,l)}return o.displayName=`withI18nextTranslation(${R(r)})`,o.WrappedComponent=r,t.withRef?n.forwardRef(o):o}},e.Translation=function(e){const t=e.ns,n=e.children,r=a(z(t,o(e,["ns","children"])),3),i=r[0],s=r[1],c=r[2];return n(i,{i18n:s,lng:s.language},c)},e.I18nextProvider=function(e){let t=e.i18n,r=e.defaultNS,i=e.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t,defaultNS:r}},i)},e.withSSR=function(){return function(e){function t(t){let r=t.initialI18nStore,a=t.initialLanguage,s=o(t,["initialI18nStore","initialLanguage"]);return L(r,a),n.createElement(e,i({},s))}return t.getInitialProps=x(e),t.displayName=`withI18nextSSR(${R(e)})`,t.WrappedComponent=e,t}},e.useSSR=L,e.I18nContext=y,e.initReactI18next=N,e.setDefaults=v,e.getDefaults=O,e.setI18n=j,e.getI18n=w,e.composeInitialProps=x,e.getInitialProps=E,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ReactI18next={},e.React)}(this,function(e,t){"use strict";var n="default"in t?t.default:t;function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(t){r(e,t,n[t])})}return e}function o(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var s={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},c=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,l=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,u=Object.create?Object.create(null):{};function p(e,t,n,r,i){var o=t.indexOf("<",r),a=t.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&o>-1&&n+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(f,"")+"</"+t.name+">"}}var d={parse:function(e,t){t||(t={}),t.components||(t.components=u);var n,r=[],i=-1,o=[],a={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="</"+n.name+">")return;f=!1}var d,g="/"!==l.charAt(1),h=0===l.indexOf("\x3c!--"),m=u+l.length,y=e.charAt(m);g&&!h&&(i++,"tag"===(n=function(e){var t,n=0,r=!0,i={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(c,function(o){if("="===o)return r=!0,void n++;r?0===n?((s[o]||"/"===e.charAt(e.length-2))&&(i.voidElement=!0),i.name=o):(i.attrs[t]=o.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(i.attrs[t]=t),t=o),n++,r=!1}),i}(l)).type&&t.components[n.name]&&(n.type="component",f=!0),n.voidElement||f||!y||"<"===y||p(n.children,e,i,m,t.ignoreWhitespace),a[n.tagName]=n,0===i&&r.push(n),(d=o[i-1])&&d.children.push(n),o[i]=n),(h||!g||n.voidElement)&&(h||i--,!f&&"<"!==y&&y&&p(d=-1===i?r:o[i].children,e,i,m,t.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,t.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,t){return e+f("",t)},"")}};let g,h,m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0};const y=n.createContext();function b(){return h}function v(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m=i({},m,e)}function O(){return m}class S{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function j(e){g=e}function w(){return g}const E={type:"3rdParty",init(e){v(e.options.react),j(e)}};function N(e){return t=>new Promise(n=>{const r=x();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function x(){const e=w(),t=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],n={},r={};return e.languages.forEach(n=>{r[n]={},t.forEach(t=>{r[n][t]=e.getResourceBundle(n,t)||{}})}),n.initialI18nStore=r,n.initialLanguage=e.language,n}function $(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t)}}const I={};function k(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&I[t[0]]||("string"==typeof t[0]&&(I[t[0]]=new Date),$(...t))}function P(e,t,n){e.loadNamespaces(t,()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout(()=>{e.off("initialized",t)},0),n()};e.on("initialized",t)}})}function R(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function C(e){return e&&(e.children||e.props&&e.props.children)}function A(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function T(e,t,r,o,a){if(""===t)return[];const s=o.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(s.join("|")).test(t);if(!e&&!c)return[t];const l={};!function e(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(t=>{"string"!=typeof t&&(C(t)?e(A(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))})}(e),t=r.services.interpolator.interpolate(t,i({},l,a),r.language);const u=function e(t,r){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]),r.reduce((r,a,s)=>{const l=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){const u=t[parseInt(a.name,10)]||{},p=n.isValidElement(u);if("string"==typeof u)r.push(u);else if(C(u)){const t=A(u),o=e(t,a.children),c=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>n.isValidElement(e))}(t)&&0===o.length?t:o;u.dummy&&(u.children=c),r.push(n.cloneElement(u,i({},u.props,{key:s}),c))}else if(c&&"object"==typeof u&&u.dummy&&!p){const o=e(t,a.children);r.push(n.cloneElement(u,i({},u.props,{key:s}),o))}else if(isNaN(a.name)&&o.transSupportBasicHtmlNodes)if(a.voidElement)r.push(n.createElement(a.name,{key:`${a.name}-${s}`}));else{const i=e(t,a.children);r.push(n.createElement(a.name,{key:`${a.name}-${s}`},i))}else if("object"!=typeof u||p)1===a.children.length&&l?r.push(n.cloneElement(u,i({},u.props,{key:s}),l)):r.push(n.cloneElement(u,i({},u.props,{key:s})));else{const e=a.children[0]?l:null;e&&r.push(e)}}else"text"===a.type&&r.push(a.content);return r},[])}([{dummy:!0,children:e}],d.parse(`<0>${t}</0>`));return A(u[0])}function z(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=n.i18n,o=b()&&t.useContext(y)||{},s=o.i18n,c=o.defaultNS,l=r||s||w();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new S),!l){k("You will need pass in an i18next instance by using initReactI18next");const e=[e=>e,{},!0];return e.t=(e=>e),e.i18n={},e.ready=!0,e}const u=i({},O(),l.options.react),p=n.useSuspense,f=void 0===p?u.useSuspense:p;let d=e||c||l.options&&l.options.defaultNS;d="string"==typeof d?[d]:d||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(d);const g=(l.isInitialized||l.initializedStoreOnce)&&d.every(e=>(function(e,t){if(!t.languages||!t.languages.length)return k("i18n.languages were undefined or empty",t.languages),!0;const n=t.languages[0],r=!!t.options&&t.options.fallbackLng,i=t.languages[t.languages.length-1];if("cimode"===n.toLowerCase())return!0;const o=(e,n)=>{const r=t.services.backendConnector.state[`${e}|${n}`];return-1===r||2===r};return!!t.hasResourceBundle(n,e)||!t.services.backendConnector.backend||!(!o(n,e)||r&&!o(i,e))})(e,l));function h(){return{t:l.getFixedT(null,"fallback"===u.nsMode?d:d[0])}}const m=a(t.useState(h()),2),v=m[0],j=m[1];t.useEffect(()=>{let e=!0;const t=u.bindI18n,n=u.bindI18nStore;function r(){e&&j(h())}return g||f||P(l,d,()=>{e&&j(h())}),t&&l&&l.on(t,r),n&&l&&l.store.on(n,r),()=>{e=!1,t&&l&&t.split(" ").forEach(e=>l.off(e,r)),n&&l&&n.split(" ").forEach(e=>l.store.off(e,r))}},[d.join()]);const E=[v.t,l,g];if(E.t=v.t,E.i18n=l,E.ready=g,g)return E;if(!g&&!f)return E;throw new Promise(e=>{P(l,d,()=>{j(h()),e()})})}function L(e,n){const r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,i=(b()?t.useContext(y):{}).i18n,o=r||i||w();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),n&&!o.initializedLanguageOnce&&(o.changeLanguage(n),o.initializedLanguageOnce=!0))}e.Trans=function(e){let r=e.children,a=e.count,s=e.parent,c=e.i18nKey,l=e.tOptions,u=e.values,p=e.defaults,f=e.components,d=e.ns,g=e.i18n,h=e.t,m=o(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]);const v=b()&&t.useContext(y)||{},S=v.i18n,j=v.defaultNS,E=g||S||w();if(!E)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const N=h||E.t.bind(E)||(e=>e),x=i({},O(),E.options&&E.options.react),I=void 0!==s?s:x.defaultTransParent;let P=d||N.ns||j||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];const R=p||function e(t,r,o,a){if(!r)return"";"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);const s=a.transKeepBasicHtmlNodesFor||[];return r.forEach((r,o)=>{const c=`${o}`;if("string"==typeof r)t=`${t}${r}`;else if(C(r)){const n=s.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof C(r)?r.type:c;t=r.props&&r.props.i18nIsDynamicList?`${t}<${n}></${n}>`:`${t}<${n}>${e("",A(r),o+1,a)}</${n}>`}else if(n.isValidElement(r))t=s.indexOf(r.type)>-1&&0===Object.keys(r.props).length?`${t}<${r.type}/>`:`${t}<${c}></${c}>`;else if("object"==typeof r){const e=i({},r),n=e.format;delete e.format;const o=Object.keys(e);n&&1===o.length?t=`${t}{{${o[0]}, ${n}}}`:1===o.length?t=`${t}{{${o[0]}}}`:$("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else $("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}}.",r)}),t}("",r,0,x)||x.transEmptyNodeValue,z=x.hashTransKey,L=c||(z?z(R):R),B=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:R,count:a,ns:P}),V=L?N(L,B):R;return I?n.createElement(I,m,T(f||r,V,E,x,B)):T(f||r,V,E,x,B)},e.useTranslation=z,e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function o(o,s){const c=a(z(e,o),3),l=i({},o,{t:c[0],i18n:c[1],tReady:c[2]});return t.withRef&&s&&(l.ref=s),n.createElement(r,l)}return o.displayName=`withI18nextTranslation(${R(r)})`,o.WrappedComponent=r,t.withRef?n.forwardRef(o):o}},e.Translation=function(e){const t=e.ns,n=e.children,r=a(z(t,o(e,["ns","children"])),3),i=r[0],s=r[1],c=r[2];return n(i,{i18n:s,lng:s.language},c)},e.I18nextProvider=function(e){let t=e.i18n,r=e.defaultNS,i=e.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t,defaultNS:r}},i)},e.withSSR=function(){return function(e){function t(t){let r=t.initialI18nStore,a=t.initialLanguage,s=o(t,["initialI18nStore","initialLanguage"]);return L(r,a),n.createElement(e,i({},s))}return t.getInitialProps=N(e),t.displayName=`withI18nextSSR(${R(e)})`,t.WrappedComponent=e,t}},e.useSSR=L,e.I18nContext=y,e.initReactI18next=E,e.setDefaults=v,e.getDefaults=O,e.setI18n=j,e.getI18n=w,e.composeInitialProps=N,e.getInitialProps=x,Object.defineProperty(e,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-i18next",
3
- "version": "10.11.0",
3
+ "version": "10.11.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",
package/react-i18next.js CHANGED
@@ -647,7 +647,9 @@
647
647
  key: i
648
648
  }), translationContent));
649
649
  } else {
650
- mem.push(child);
650
+ mem.push(React__default.cloneElement(child, _objectSpread({}, child.props, {
651
+ key: i
652
+ })));
651
653
  }
652
654
  } else if (node.type === 'text') {
653
655
  mem.push(node.content);
@@ -681,7 +683,7 @@
681
683
  tFromProps = _ref.t,
682
684
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
683
685
 
684
- const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
686
+ const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {},
685
687
  i18nFromContext = _ref2.i18n,
686
688
  defaultNSFromContext = _ref2.defaultNS;
687
689
 
@@ -692,13 +694,13 @@
692
694
  return children;
693
695
  }
694
696
 
695
- const t = tFromProps || i18n.t.bind(i18n);
697
+ const t = tFromProps || i18n.t.bind(i18n) || (k => k);
696
698
 
697
699
  const reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react);
698
700
 
699
701
  const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
700
702
 
701
- let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
703
+ let namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
702
704
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
703
705
  const defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
704
706
  const hashTransKey = reactI18nextOptions.hashTransKey;
@@ -726,7 +728,7 @@
726
728
  // assert we have the needed i18nInstance
727
729
  const i18nFromProps = props.i18n;
728
730
 
729
- const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
731
+ const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {},
730
732
  i18nFromContext = _ref.i18n,
731
733
  defaultNSFromContext = _ref.defaultNS;
732
734
 
@@ -793,7 +795,7 @@
793
795
  if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
794
796
  if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
795
797
  };
796
- }, []); // define props to trigger using effect on rerender (none here)
798
+ }, [namespaces.join()]); // re-run effect whenever list of namespaces changes
797
799
 
798
800
  const ret = [t.t, i18n, ready];
799
801
  ret.t = t.t;
@@ -878,7 +880,10 @@
878
880
  const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
879
881
  i18nFromContext = _ref.i18n;
880
882
 
881
- const i18n = i18nFromProps || i18nFromContext || getI18n(); // nextjs / SSR: getting data from next.js or other ssr stack
883
+ const i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request
884
+ // -> do not set initial stuff on server side
885
+
886
+ if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack
882
887
 
883
888
  if (initialI18nStore && !i18n.initializedStoreOnce) {
884
889
  i18n.services.resourceStore.data = initialI18nStore;
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ReactI18next={},e.React)}(this,function(e,t){"use strict";var n="default"in t?t.default:t;function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(t){r(e,t,n[t])})}return e}function o(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var s={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},c=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,l=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,u=Object.create?Object.create(null):{};function p(e,t,n,r,i){var o=t.indexOf("<",r),a=t.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&o>-1&&n+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(f,"")+"</"+t.name+">"}}var d={parse:function(e,t){t||(t={}),t.components||(t.components=u);var n,r=[],i=-1,o=[],a={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="</"+n.name+">")return;f=!1}var d,g="/"!==l.charAt(1),h=0===l.indexOf("\x3c!--"),m=u+l.length,y=e.charAt(m);g&&!h&&(i++,"tag"===(n=function(e){var t,n=0,r=!0,i={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(c,function(o){if("="===o)return r=!0,void n++;r?0===n?((s[o]||"/"===e.charAt(e.length-2))&&(i.voidElement=!0),i.name=o):(i.attrs[t]=o.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(i.attrs[t]=t),t=o),n++,r=!1}),i}(l)).type&&t.components[n.name]&&(n.type="component",f=!0),n.voidElement||f||!y||"<"===y||p(n.children,e,i,m,t.ignoreWhitespace),a[n.tagName]=n,0===i&&r.push(n),(d=o[i-1])&&d.children.push(n),o[i]=n),(h||!g||n.voidElement)&&(h||i--,!f&&"<"!==y&&y&&p(d=-1===i?r:o[i].children,e,i,m,t.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,t.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,t){return e+f("",t)},"")}};let g,h,m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0};const y=n.createContext();function b(){return h}function v(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m=i({},m,e)}function O(){return m}class S{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function j(e){g=e}function w(){return g}const N={type:"3rdParty",init(e){v(e.options.react),j(e)}};function x(e){return t=>new Promise(n=>{const r=E();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function E(){const e=w(),t=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],n={},r={};return e.languages.forEach(n=>{r[n]={},t.forEach(t=>{r[n][t]=e.getResourceBundle(n,t)||{}})}),n.initialI18nStore=r,n.initialLanguage=e.language,n}function $(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t)}}const I={};function k(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&I[t[0]]||("string"==typeof t[0]&&(I[t[0]]=new Date),$(...t))}function P(e,t,n){e.loadNamespaces(t,()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout(()=>{e.off("initialized",t)},0),n()};e.on("initialized",t)}})}function R(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function A(e){return e&&(e.children||e.props&&e.props.children)}function C(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function T(e,t,r,o,a){if(""===t)return[];const s=o.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(s.join("|")).test(t);if(!e&&!c)return[t];const l={};!function e(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(t=>{"string"!=typeof t&&(A(t)?e(C(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))})}(e),t=r.services.interpolator.interpolate(t,i({},l,a),r.language);const u=function e(t,r){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]),r.reduce((r,a,s)=>{const l=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){const u=t[parseInt(a.name,10)]||{},p=n.isValidElement(u);if("string"==typeof u)r.push(u);else if(A(u)){const t=C(u),o=e(t,a.children),c=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>n.isValidElement(e))}(t)&&0===o.length?t:o;u.dummy&&(u.children=c),r.push(n.cloneElement(u,i({},u.props,{key:s}),c))}else if(c&&"object"==typeof u&&u.dummy&&!p){const o=e(t,a.children);r.push(n.cloneElement(u,i({},u.props,{key:s}),o))}else if(isNaN(a.name)&&o.transSupportBasicHtmlNodes)if(a.voidElement)r.push(n.createElement(a.name,{key:`${a.name}-${s}`}));else{const i=e(t,a.children);r.push(n.createElement(a.name,{key:`${a.name}-${s}`},i))}else if("object"!=typeof u||p)1===a.children.length&&l?r.push(n.cloneElement(u,i({},u.props,{key:s}),l)):r.push(u);else{const e=a.children[0]?l:null;e&&r.push(e)}}else"text"===a.type&&r.push(a.content);return r},[])}([{dummy:!0,children:e}],d.parse(`<0>${t}</0>`));return C(u[0])}function z(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=n.i18n,o=b()?t.useContext(y):{},s=o.i18n,c=o.defaultNS,l=r||s||w();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new S),!l){k("You will need pass in an i18next instance by using initReactI18next");const e=[e=>e,{},!0];return e.t=(e=>e),e.i18n={},e.ready=!0,e}const u=i({},O(),l.options.react),p=n.useSuspense,f=void 0===p?u.useSuspense:p;let d=e||c||l.options&&l.options.defaultNS;d="string"==typeof d?[d]:d||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(d);const g=(l.isInitialized||l.initializedStoreOnce)&&d.every(e=>(function(e,t){if(!t.languages||!t.languages.length)return k("i18n.languages were undefined or empty",t.languages),!0;const n=t.languages[0],r=!!t.options&&t.options.fallbackLng,i=t.languages[t.languages.length-1];if("cimode"===n.toLowerCase())return!0;const o=(e,n)=>{const r=t.services.backendConnector.state[`${e}|${n}`];return-1===r||2===r};return!!t.hasResourceBundle(n,e)||!t.services.backendConnector.backend||!(!o(n,e)||r&&!o(i,e))})(e,l));function h(){return{t:l.getFixedT(null,"fallback"===u.nsMode?d:d[0])}}const m=a(t.useState(h()),2),v=m[0],j=m[1];t.useEffect(()=>{let e=!0;const t=u.bindI18n,n=u.bindI18nStore;function r(){e&&j(h())}return g||f||P(l,d,()=>{e&&j(h())}),t&&l&&l.on(t,r),n&&l&&l.store.on(n,r),()=>{e=!1,t&&l&&t.split(" ").forEach(e=>l.off(e,r)),n&&l&&n.split(" ").forEach(e=>l.store.off(e,r))}},[]);const N=[v.t,l,g];if(N.t=v.t,N.i18n=l,N.ready=g,g)return N;if(!g&&!f)return N;throw new Promise(e=>{P(l,d,()=>{j(h()),e()})})}function L(e,n){const r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,i=(b()?t.useContext(y):{}).i18n,o=r||i||w();e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),n&&!o.initializedLanguageOnce&&(o.changeLanguage(n),o.initializedLanguageOnce=!0)}e.Trans=function(e){let r=e.children,a=e.count,s=e.parent,c=e.i18nKey,l=e.tOptions,u=e.values,p=e.defaults,f=e.components,d=e.ns,g=e.i18n,h=e.t,m=o(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]);const v=b()?t.useContext(y):{},S=v.i18n,j=v.defaultNS,N=g||S||w();if(!N)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const x=h||N.t.bind(N),E=i({},O(),N.options&&N.options.react),I=void 0!==s?s:E.defaultTransParent;let P=d||j||N.options&&N.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];const R=p||function e(t,r,o,a){if(!r)return"";"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);const s=a.transKeepBasicHtmlNodesFor||[];return r.forEach((r,o)=>{const c=`${o}`;if("string"==typeof r)t=`${t}${r}`;else if(A(r)){const n=s.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof A(r)?r.type:c;t=r.props&&r.props.i18nIsDynamicList?`${t}<${n}></${n}>`:`${t}<${n}>${e("",C(r),o+1,a)}</${n}>`}else if(n.isValidElement(r))t=s.indexOf(r.type)>-1&&0===Object.keys(r.props).length?`${t}<${r.type}/>`:`${t}<${c}></${c}>`;else if("object"==typeof r){const e=i({},r),n=e.format;delete e.format;const o=Object.keys(e);n&&1===o.length?t=`${t}{{${o[0]}, ${n}}}`:1===o.length?t=`${t}{{${o[0]}}}`:$("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else $("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}}.",r)}),t}("",r,0,E)||E.transEmptyNodeValue,z=E.hashTransKey,L=c||(z?z(R):R),B=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:R,count:a,ns:P}),V=L?x(L,B):R;return I?n.createElement(I,m,T(f||r,V,N,E,B)):T(f||r,V,N,E,B)},e.useTranslation=z,e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function o(o,s){const c=a(z(e,o),3),l=i({},o,{t:c[0],i18n:c[1],tReady:c[2]});return t.withRef&&s&&(l.ref=s),n.createElement(r,l)}return o.displayName=`withI18nextTranslation(${R(r)})`,o.WrappedComponent=r,t.withRef?n.forwardRef(o):o}},e.Translation=function(e){const t=e.ns,n=e.children,r=a(z(t,o(e,["ns","children"])),3),i=r[0],s=r[1],c=r[2];return n(i,{i18n:s,lng:s.language},c)},e.I18nextProvider=function(e){let t=e.i18n,r=e.defaultNS,i=e.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t,defaultNS:r}},i)},e.withSSR=function(){return function(e){function t(t){let r=t.initialI18nStore,a=t.initialLanguage,s=o(t,["initialI18nStore","initialLanguage"]);return L(r,a),n.createElement(e,i({},s))}return t.getInitialProps=x(e),t.displayName=`withI18nextSSR(${R(e)})`,t.WrappedComponent=e,t}},e.useSSR=L,e.I18nContext=y,e.initReactI18next=N,e.setDefaults=v,e.getDefaults=O,e.setI18n=j,e.getI18n=w,e.composeInitialProps=x,e.getInitialProps=E,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ReactI18next={},e.React)}(this,function(e,t){"use strict";var n="default"in t?t.default:t;function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(t){r(e,t,n[t])})}return e}function o(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var s={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},c=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,l=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,u=Object.create?Object.create(null):{};function p(e,t,n,r,i){var o=t.indexOf("<",r),a=t.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&o>-1&&n+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(f,"")+"</"+t.name+">"}}var d={parse:function(e,t){t||(t={}),t.components||(t.components=u);var n,r=[],i=-1,o=[],a={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="</"+n.name+">")return;f=!1}var d,g="/"!==l.charAt(1),h=0===l.indexOf("\x3c!--"),m=u+l.length,y=e.charAt(m);g&&!h&&(i++,"tag"===(n=function(e){var t,n=0,r=!0,i={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(c,function(o){if("="===o)return r=!0,void n++;r?0===n?((s[o]||"/"===e.charAt(e.length-2))&&(i.voidElement=!0),i.name=o):(i.attrs[t]=o.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(i.attrs[t]=t),t=o),n++,r=!1}),i}(l)).type&&t.components[n.name]&&(n.type="component",f=!0),n.voidElement||f||!y||"<"===y||p(n.children,e,i,m,t.ignoreWhitespace),a[n.tagName]=n,0===i&&r.push(n),(d=o[i-1])&&d.children.push(n),o[i]=n),(h||!g||n.voidElement)&&(h||i--,!f&&"<"!==y&&y&&p(d=-1===i?r:o[i].children,e,i,m,t.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,t.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,t){return e+f("",t)},"")}};let g,h,m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0};const y=n.createContext();function b(){return h}function v(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m=i({},m,e)}function O(){return m}class S{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function j(e){g=e}function w(){return g}const E={type:"3rdParty",init(e){v(e.options.react),j(e)}};function N(e){return t=>new Promise(n=>{const r=x();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function x(){const e=w(),t=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],n={},r={};return e.languages.forEach(n=>{r[n]={},t.forEach(t=>{r[n][t]=e.getResourceBundle(n,t)||{}})}),n.initialI18nStore=r,n.initialLanguage=e.language,n}function $(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t)}}const I={};function k(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];"string"==typeof t[0]&&I[t[0]]||("string"==typeof t[0]&&(I[t[0]]=new Date),$(...t))}function P(e,t,n){e.loadNamespaces(t,()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout(()=>{e.off("initialized",t)},0),n()};e.on("initialized",t)}})}function R(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function C(e){return e&&(e.children||e.props&&e.props.children)}function A(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function T(e,t,r,o,a){if(""===t)return[];const s=o.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(s.join("|")).test(t);if(!e&&!c)return[t];const l={};!function e(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(t=>{"string"!=typeof t&&(C(t)?e(A(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))})}(e),t=r.services.interpolator.interpolate(t,i({},l,a),r.language);const u=function e(t,r){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]),r.reduce((r,a,s)=>{const l=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){const u=t[parseInt(a.name,10)]||{},p=n.isValidElement(u);if("string"==typeof u)r.push(u);else if(C(u)){const t=A(u),o=e(t,a.children),c=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>n.isValidElement(e))}(t)&&0===o.length?t:o;u.dummy&&(u.children=c),r.push(n.cloneElement(u,i({},u.props,{key:s}),c))}else if(c&&"object"==typeof u&&u.dummy&&!p){const o=e(t,a.children);r.push(n.cloneElement(u,i({},u.props,{key:s}),o))}else if(isNaN(a.name)&&o.transSupportBasicHtmlNodes)if(a.voidElement)r.push(n.createElement(a.name,{key:`${a.name}-${s}`}));else{const i=e(t,a.children);r.push(n.createElement(a.name,{key:`${a.name}-${s}`},i))}else if("object"!=typeof u||p)1===a.children.length&&l?r.push(n.cloneElement(u,i({},u.props,{key:s}),l)):r.push(n.cloneElement(u,i({},u.props,{key:s})));else{const e=a.children[0]?l:null;e&&r.push(e)}}else"text"===a.type&&r.push(a.content);return r},[])}([{dummy:!0,children:e}],d.parse(`<0>${t}</0>`));return A(u[0])}function z(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=n.i18n,o=b()&&t.useContext(y)||{},s=o.i18n,c=o.defaultNS,l=r||s||w();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new S),!l){k("You will need pass in an i18next instance by using initReactI18next");const e=[e=>e,{},!0];return e.t=(e=>e),e.i18n={},e.ready=!0,e}const u=i({},O(),l.options.react),p=n.useSuspense,f=void 0===p?u.useSuspense:p;let d=e||c||l.options&&l.options.defaultNS;d="string"==typeof d?[d]:d||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(d);const g=(l.isInitialized||l.initializedStoreOnce)&&d.every(e=>(function(e,t){if(!t.languages||!t.languages.length)return k("i18n.languages were undefined or empty",t.languages),!0;const n=t.languages[0],r=!!t.options&&t.options.fallbackLng,i=t.languages[t.languages.length-1];if("cimode"===n.toLowerCase())return!0;const o=(e,n)=>{const r=t.services.backendConnector.state[`${e}|${n}`];return-1===r||2===r};return!!t.hasResourceBundle(n,e)||!t.services.backendConnector.backend||!(!o(n,e)||r&&!o(i,e))})(e,l));function h(){return{t:l.getFixedT(null,"fallback"===u.nsMode?d:d[0])}}const m=a(t.useState(h()),2),v=m[0],j=m[1];t.useEffect(()=>{let e=!0;const t=u.bindI18n,n=u.bindI18nStore;function r(){e&&j(h())}return g||f||P(l,d,()=>{e&&j(h())}),t&&l&&l.on(t,r),n&&l&&l.store.on(n,r),()=>{e=!1,t&&l&&t.split(" ").forEach(e=>l.off(e,r)),n&&l&&n.split(" ").forEach(e=>l.store.off(e,r))}},[d.join()]);const E=[v.t,l,g];if(E.t=v.t,E.i18n=l,E.ready=g,g)return E;if(!g&&!f)return E;throw new Promise(e=>{P(l,d,()=>{j(h()),e()})})}function L(e,n){const r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,i=(b()?t.useContext(y):{}).i18n,o=r||i||w();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),n&&!o.initializedLanguageOnce&&(o.changeLanguage(n),o.initializedLanguageOnce=!0))}e.Trans=function(e){let r=e.children,a=e.count,s=e.parent,c=e.i18nKey,l=e.tOptions,u=e.values,p=e.defaults,f=e.components,d=e.ns,g=e.i18n,h=e.t,m=o(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]);const v=b()&&t.useContext(y)||{},S=v.i18n,j=v.defaultNS,E=g||S||w();if(!E)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const N=h||E.t.bind(E)||(e=>e),x=i({},O(),E.options&&E.options.react),I=void 0!==s?s:x.defaultTransParent;let P=d||N.ns||j||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];const R=p||function e(t,r,o,a){if(!r)return"";"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);const s=a.transKeepBasicHtmlNodesFor||[];return r.forEach((r,o)=>{const c=`${o}`;if("string"==typeof r)t=`${t}${r}`;else if(C(r)){const n=s.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof C(r)?r.type:c;t=r.props&&r.props.i18nIsDynamicList?`${t}<${n}></${n}>`:`${t}<${n}>${e("",A(r),o+1,a)}</${n}>`}else if(n.isValidElement(r))t=s.indexOf(r.type)>-1&&0===Object.keys(r.props).length?`${t}<${r.type}/>`:`${t}<${c}></${c}>`;else if("object"==typeof r){const e=i({},r),n=e.format;delete e.format;const o=Object.keys(e);n&&1===o.length?t=`${t}{{${o[0]}, ${n}}}`:1===o.length?t=`${t}{{${o[0]}}}`:$("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else $("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}}.",r)}),t}("",r,0,x)||x.transEmptyNodeValue,z=x.hashTransKey,L=c||(z?z(R):R),B=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:R,count:a,ns:P}),V=L?N(L,B):R;return I?n.createElement(I,m,T(f||r,V,E,x,B)):T(f||r,V,E,x,B)},e.useTranslation=z,e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function o(o,s){const c=a(z(e,o),3),l=i({},o,{t:c[0],i18n:c[1],tReady:c[2]});return t.withRef&&s&&(l.ref=s),n.createElement(r,l)}return o.displayName=`withI18nextTranslation(${R(r)})`,o.WrappedComponent=r,t.withRef?n.forwardRef(o):o}},e.Translation=function(e){const t=e.ns,n=e.children,r=a(z(t,o(e,["ns","children"])),3),i=r[0],s=r[1],c=r[2];return n(i,{i18n:s,lng:s.language},c)},e.I18nextProvider=function(e){let t=e.i18n,r=e.defaultNS,i=e.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t,defaultNS:r}},i)},e.withSSR=function(){return function(e){function t(t){let r=t.initialI18nStore,a=t.initialLanguage,s=o(t,["initialI18nStore","initialLanguage"]);return L(r,a),n.createElement(e,i({},s))}return t.getInitialProps=N(e),t.displayName=`withI18nextSSR(${R(e)})`,t.WrappedComponent=e,t}},e.useSSR=L,e.I18nContext=y,e.initReactI18next=E,e.setDefaults=v,e.getDefaults=O,e.setI18n=j,e.getI18n=w,e.composeInitialProps=N,e.getInitialProps=x,Object.defineProperty(e,"__esModule",{value:!0})});
package/src/.DS_Store ADDED
Binary file
package/src/Trans.js CHANGED
@@ -169,7 +169,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
169
169
  // with this in component could be components={[<span class='make-beautiful'/>]} and in translation - 'some text <0>some highlighted message</0>'
170
170
  mem.push(React.cloneElement(child, { ...child.props, key: i }, translationContent));
171
171
  } else {
172
- mem.push(child);
172
+ mem.push(React.cloneElement(child, { ...child.props, key: i }));
173
173
  }
174
174
  } else if (node.type === 'text') {
175
175
  mem.push(node.content);
@@ -200,7 +200,7 @@ export function Trans({
200
200
  ...additionalProps
201
201
  }) {
202
202
  const { i18n: i18nFromContext, defaultNS: defaultNSFromContext } = getHasUsedI18nextProvider()
203
- ? useContext(I18nContext)
203
+ ? useContext(I18nContext) || {}
204
204
  : {};
205
205
  const i18n = i18nFromProps || i18nFromContext || getI18n();
206
206
  if (!i18n) {
@@ -208,13 +208,13 @@ export function Trans({
208
208
  return children;
209
209
  }
210
210
 
211
- const t = tFromProps || i18n.t.bind(i18n);
211
+ const t = tFromProps || i18n.t.bind(i18n) || (k => k);
212
212
 
213
213
  const reactI18nextOptions = { ...getDefaults(), ...(i18n.options && i18n.options.react) };
214
214
  const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
215
215
 
216
216
  // prepare having a namespace
217
- let namespaces = ns || defaultNSFromContext || (i18n.options && i18n.options.defaultNS);
217
+ let namespaces = ns || t.ns || defaultNSFromContext || (i18n.options && i18n.options.defaultNS);
218
218
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
219
219
 
220
220
  const defaultValue =
package/src/useSSR.js CHANGED
@@ -6,6 +6,10 @@ export function useSSR(initialI18nStore, initialLanguage, props = {}) {
6
6
  const { i18n: i18nFromContext } = getHasUsedI18nextProvider() ? useContext(I18nContext) : {};
7
7
  const i18n = i18nFromProps || i18nFromContext || getI18n();
8
8
 
9
+ // opt out if is a cloned instance, eg. created by i18next-express-middleware on request
10
+ // -> do not set initial stuff on server side
11
+ if (i18n.options && i18n.options.isClone) return;
12
+
9
13
  // nextjs / SSR: getting data from next.js or other ssr stack
10
14
  if (initialI18nStore && !i18n.initializedStoreOnce) {
11
15
  i18n.services.resourceStore.data = initialI18nStore;
@@ -12,7 +12,7 @@ export function useTranslation(ns, props = {}) {
12
12
  // assert we have the needed i18nInstance
13
13
  const { i18n: i18nFromProps } = props;
14
14
  const { i18n: i18nFromContext, defaultNS: defaultNSFromContext } = getHasUsedI18nextProvider()
15
- ? useContext(I18nContext)
15
+ ? useContext(I18nContext) || {}
16
16
  : {};
17
17
  const i18n = i18nFromProps || i18nFromContext || getI18n();
18
18
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
@@ -74,7 +74,7 @@ export function useTranslation(ns, props = {}) {
74
74
  if (bindI18nStore && i18n)
75
75
  bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
76
76
  };
77
- }, []); // define props to trigger using effect on rerender (none here)
77
+ }, [namespaces.join()]); // re-run effect whenever list of namespaces changes
78
78
 
79
79
  const ret = [t.t, i18n, ready];
80
80
  ret.t = t.t;