react-i18next 10.10.0 → 10.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 10.11.0
2
+
3
+ - Restore support passing the defaultNS via I18nextProvider prop [860](https://github.com/i18next/react-i18next/pull/860)
4
+
1
5
  ### 10.10.0
2
6
 
3
7
  - HOC: expose wrapped component as WrappedComponent property [853](https://github.com/i18next/react-i18next/pull/853)
@@ -678,7 +678,8 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
678
678
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
679
679
 
680
680
  const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
681
- i18nFromContext = _ref2.i18n;
681
+ i18nFromContext = _ref2.i18n,
682
+ defaultNSFromContext = _ref2.defaultNS;
682
683
 
683
684
  const i18n = i18nFromProps || i18nFromContext || getI18n();
684
685
 
@@ -691,7 +692,10 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
691
692
 
692
693
  const reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react);
693
694
 
694
- const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
695
+ const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
696
+
697
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
698
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
695
699
  const defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
696
700
  const hashTransKey = reactI18nextOptions.hashTransKey;
697
701
  const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
@@ -705,7 +709,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
705
709
  const combinedTOpts = _objectSpread({}, tOptions, values, interpolationOverride, {
706
710
  defaultValue,
707
711
  count,
708
- ns
712
+ ns: namespaces
709
713
  });
710
714
 
711
715
  const translation = key ? t(key, combinedTOpts) : defaultValue;
@@ -719,7 +723,8 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
719
723
  const i18nFromProps = props.i18n;
720
724
 
721
725
  const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
722
- i18nFromContext = _ref.i18n;
726
+ i18nFromContext = _ref.i18n,
727
+ defaultNSFromContext = _ref.defaultNS;
723
728
 
724
729
  const i18n = i18nFromProps || i18nFromContext || getI18n();
725
730
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
@@ -740,7 +745,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
740
745
  const _props$useSuspense = props.useSuspense,
741
746
  useSuspense = _props$useSuspense === void 0 ? i18nOptions.useSuspense : _props$useSuspense; // prepare having a namespace
742
747
 
743
- let namespaces = ns || i18n.options && i18n.options.defaultNS;
748
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
744
749
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; // report namespaces as used
745
750
 
746
751
  if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); // are we ready? yes if all namespaces in first language are loaded already (either with data or empty object on failed load)
@@ -851,11 +856,13 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
851
856
 
852
857
  function I18nextProvider(_ref) {
853
858
  let i18n = _ref.i18n,
859
+ defaultNS = _ref.defaultNS,
854
860
  children = _ref.children;
855
861
  usedI18nextProvider(true);
856
862
  return React__default.createElement(I18nContext.Provider, {
857
863
  value: {
858
- i18n
864
+ i18n,
865
+ defaultNS
859
866
  }
860
867
  }, children);
861
868
  }
@@ -1 +1 @@
1
- define(["exports","react"],function(e,n){"use strict";var t="default"in n?n.default:n;function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{},i=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.forEach(function(n){r(e,n,t[n])})}return e}function o(e,n){if(null==e)return{};var t,r,i=function(e,n){if(null==e)return{};var t,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t=o[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)t=o[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}function a(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(t.push(a.value),!n||t.length!==n);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return t}(e,n)||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,n,t,r,i){var o=n.indexOf("<",r),a=n.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&o>-1&&t+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(f,"")+"</"+n.name+">"}}var d={parse:function(e,n){n||(n={}),n.components||(n.components=u);var t,r=[],i=-1,o=[],a={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="</"+t.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"===(t=function(e){var n,t=0,r=!0,i={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(c,function(o){if("="===o)return r=!0,void t++;r?0===t?((s[o]||"/"===e.charAt(e.length-2))&&(i.voidElement=!0),i.name=o):(i.attrs[n]=o.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(i.attrs[n]=n),n=o),t++,r=!1}),i}(l)).type&&n.components[t.name]&&(t.type="component",f=!0),t.voidElement||f||!y||"<"===y||p(t.children,e,i,m,n.ignoreWhitespace),a[t.tagName]=t,0===i&&r.push(t),(d=o[i-1])&&d.children.push(t),o[i]=t),(h||!g||t.voidElement)&&(h||i--,!f&&"<"!==y&&y&&p(d=-1===i?r:o[i].children,e,i,m,n.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,n){return e+f("",n)},"")}};let g,h,m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0};const y=t.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 j{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function w(e){g=e}function E(){return g}const S={type:"3rdParty",init(e){v(e.options.react),w(e)}};function $(e){return n=>new Promise(t=>{const r=x();e.getInitialProps?e.getInitialProps(n).then(e=>{t(i({},e,r))}):t(r)})}function x(){const e=E(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},r={};return e.languages.forEach(t=>{r[t]={},n.forEach(n=>{r[t][n]=e.getResourceBundle(t,n)||{}})}),t.initialI18nStore=r,t.initialLanguage=e.language,t}function N(){if(console&&console.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}}const I={};function k(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&I[n[0]]||("string"==typeof n[0]&&(I[n[0]]=new Date),N(...n))}function P(e,n,t){e.loadNamespaces(n,()=>{if(e.isInitialized)t();else{const n=()=>{setTimeout(()=>{e.off("initialized",n)},0),t()};e.on("initialized",n)}})}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,n,r,o,a){if(""===n)return[];const s=o.transKeepBasicHtmlNodesFor||[],c=n&&new RegExp(s.join("|")).test(n);if(!e&&!c)return[n];const l={};!function e(n){"[object Array]"!==Object.prototype.toString.call(n)&&(n=[n]),n.forEach(n=>{"string"!=typeof n&&(A(n)?e(C(n)):"object"!=typeof n||t.isValidElement(n)||Object.assign(l,n))})}(e),n=r.services.interpolator.interpolate(n,i({},l,a),r.language);const u=function e(n,r){return"[object Array]"!==Object.prototype.toString.call(n)&&(n=[n]),"[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=n[parseInt(a.name,10)]||{},p=t.isValidElement(u);if("string"==typeof u)r.push(u);else if(A(u)){const n=C(u),o=e(n,a.children),c=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>t.isValidElement(e))}(n)&&0===o.length?n:o;u.dummy&&(u.children=c),r.push(t.cloneElement(u,i({},u.props,{key:s}),c))}else if(c&&"object"==typeof u&&u.dummy&&!p){const o=e(n,a.children);r.push(t.cloneElement(u,i({},u.props,{key:s}),o))}else if(isNaN(a.name)&&o.transSupportBasicHtmlNodes)if(a.voidElement)r.push(t.createElement(a.name,{key:`${a.name}-${s}`}));else{const i=e(n,a.children);r.push(t.createElement(a.name,{key:`${a.name}-${s}`},i))}else if("object"!=typeof u||p)1===a.children.length&&l?r.push(t.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>${n}</0>`));return C(u[0])}function z(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=t.i18n,o=(b()?n.useContext(y):{}).i18n,s=r||o||E();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new j),!s){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 c=i({},O(),s.options.react),l=t.useSuspense,u=void 0===l?c.useSuspense:l;let p=e||s.options&&s.options.defaultNS;p="string"==typeof p?[p]:p||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(p);const f=(s.isInitialized||s.initializedStoreOnce)&&p.every(e=>(function(e,n){if(!n.languages||!n.languages.length)return k("i18n.languages were undefined or empty",n.languages),!0;const t=n.languages[0],r=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===t.toLowerCase())return!0;const o=(e,t)=>{const r=n.services.backendConnector.state[`${e}|${t}`];return-1===r||2===r};return!!n.hasResourceBundle(t,e)||!n.services.backendConnector.backend||!(!o(t,e)||r&&!o(i,e))})(e,s));function d(){return{t:s.getFixedT(null,"fallback"===c.nsMode?p:p[0])}}const g=a(n.useState(d()),2),h=g[0],m=g[1];n.useEffect(()=>{let e=!0;const n=c.bindI18n,t=c.bindI18nStore;function r(){e&&m(d())}return f||u||P(s,p,()=>{e&&m(d())}),n&&s&&s.on(n,r),t&&s&&s.store.on(t,r),()=>{e=!1,n&&s&&n.split(" ").forEach(e=>s.off(e,r)),t&&s&&t.split(" ").forEach(e=>s.store.off(e,r))}},[]);const v=[h.t,s,f];if(v.t=h.t,v.i18n=s,v.ready=f,f)return v;if(!f&&!u)return v;throw new Promise(e=>{P(s,p,()=>{m(d()),e()})})}function L(e,t){const r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,i=(b()?n.useContext(y):{}).i18n,o=r||i||E();e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),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()?n.useContext(y):{}).i18n,j=g||v||E();if(!j)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const w=h||j.t.bind(j),S=i({},O(),j.options&&j.options.react),$=void 0!==s?s:S.defaultTransParent,x=p||function e(n,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)n=`${n}${r}`;else if(A(r)){const t=s.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof A(r)?r.type:c;n=r.props&&r.props.i18nIsDynamicList?`${n}<${t}></${t}>`:`${n}<${t}>${e("",C(r),o+1,a)}</${t}>`}else if(t.isValidElement(r))n=s.indexOf(r.type)>-1&&0===Object.keys(r.props).length?`${n}<${r.type}/>`:`${n}<${c}></${c}>`;else if("object"==typeof r){const e=i({},r),t=e.format;delete e.format;const o=Object.keys(e);t&&1===o.length?n=`${n}{{${o[0]}, ${t}}}`:1===o.length?n=`${n}{{${o[0]}}}`:N("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else N("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)}),n}("",r,0,S)||S.transEmptyNodeValue,I=S.hashTransKey,P=c||(I?I(x):x),R=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:x,count:a,ns:d}),z=P?w(P,R):x;return $?t.createElement($,m,T(f||r,z,j,S,R)):T(f||r,z,j,S,R)},e.useTranslation=z,e.withTranslation=function(e){let n=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 n.withRef&&s&&(l.ref=s),t.createElement(r,l)}return o.displayName=`withI18nextTranslation(${R(r)})`,o.WrappedComponent=r,n.withRef?t.forwardRef(o):o}},e.Translation=function(e){const n=e.ns,t=e.children,r=a(z(n,o(e,["ns","children"])),3),i=r[0],s=r[1],c=r[2];return t(i,{i18n:s,lng:s.language},c)},e.I18nextProvider=function(e){let n=e.i18n,r=e.children;return h=!0,t.createElement(y.Provider,{value:{i18n:n}},r)},e.withSSR=function(){return function(e){function n(n){let r=n.initialI18nStore,a=n.initialLanguage,s=o(n,["initialI18nStore","initialLanguage"]);return L(r,a),t.createElement(e,i({},s))}return n.getInitialProps=$(e),n.displayName=`withI18nextSSR(${R(e)})`,n.WrappedComponent=e,n}},e.useSSR=L,e.I18nContext=y,e.initReactI18next=S,e.setDefaults=v,e.getDefaults=O,e.setI18n=w,e.getI18n=E,e.composeInitialProps=$,e.getInitialProps=x,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 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})});
@@ -13,11 +13,13 @@ var _context = require("./context");
13
13
 
14
14
  function I18nextProvider(_ref) {
15
15
  var i18n = _ref.i18n,
16
+ defaultNS = _ref.defaultNS,
16
17
  children = _ref.children;
17
18
  (0, _context.usedI18nextProvider)(true);
18
19
  return _react.default.createElement(_context.I18nContext.Provider, {
19
20
  value: {
20
- i18n: i18n
21
+ i18n: i18n,
22
+ defaultNS: defaultNS
21
23
  }
22
24
  }, children);
23
25
  }
@@ -209,7 +209,8 @@ function Trans(_ref) {
209
209
  additionalProps = (0, _objectWithoutProperties2.default)(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
210
210
 
211
211
  var _ref2 = (0, _context.getHasUsedI18nextProvider)() ? (0, _react.useContext)(_context.I18nContext) : {},
212
- i18nFromContext = _ref2.i18n;
212
+ i18nFromContext = _ref2.i18n,
213
+ defaultNSFromContext = _ref2.defaultNS;
213
214
 
214
215
  var i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)();
215
216
 
@@ -220,7 +221,10 @@ function Trans(_ref) {
220
221
 
221
222
  var t = tFromProps || i18n.t.bind(i18n);
222
223
  var reactI18nextOptions = (0, _objectSpread2.default)({}, (0, _context.getDefaults)(), i18n.options && i18n.options.react);
223
- var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
224
+ var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
225
+
226
+ var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
227
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
224
228
  var defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
225
229
  var hashTransKey = reactI18nextOptions.hashTransKey;
226
230
  var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
@@ -233,7 +237,7 @@ function Trans(_ref) {
233
237
  var combinedTOpts = (0, _objectSpread2.default)({}, tOptions, values, interpolationOverride, {
234
238
  defaultValue: defaultValue,
235
239
  count: count,
236
- ns: ns
240
+ ns: namespaces
237
241
  });
238
242
  var translation = key ? t(key, combinedTOpts) : defaultValue;
239
243
  if (!useAsParent) return renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts);
@@ -23,7 +23,8 @@ function useTranslation(ns) {
23
23
  var i18nFromProps = props.i18n;
24
24
 
25
25
  var _ref = (0, _context.getHasUsedI18nextProvider)() ? (0, _react.useContext)(_context.I18nContext) : {},
26
- i18nFromContext = _ref.i18n;
26
+ i18nFromContext = _ref.i18n,
27
+ defaultNSFromContext = _ref.defaultNS;
27
28
 
28
29
  var i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)();
29
30
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new _context.ReportNamespaces();
@@ -47,7 +48,7 @@ function useTranslation(ns) {
47
48
  var _props$useSuspense = props.useSuspense,
48
49
  useSuspense = _props$useSuspense === void 0 ? i18nOptions.useSuspense : _props$useSuspense; // prepare having a namespace
49
50
 
50
- var namespaces = ns || i18n.options && i18n.options.defaultNS;
51
+ var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
51
52
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; // report namespaces as used
52
53
 
53
54
  if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); // are we ready? yes if all namespaces in first language are loaded already (either with data or empty object on failed load)
@@ -2,11 +2,13 @@ import React from 'react';
2
2
  import { I18nContext, usedI18nextProvider } from './context';
3
3
  export function I18nextProvider(_ref) {
4
4
  var i18n = _ref.i18n,
5
+ defaultNS = _ref.defaultNS,
5
6
  children = _ref.children;
6
7
  usedI18nextProvider(true);
7
8
  return React.createElement(I18nContext.Provider, {
8
9
  value: {
9
- i18n: i18n
10
+ i18n: i18n,
11
+ defaultNS: defaultNS
10
12
  }
11
13
  }, children);
12
14
  }
package/dist/es/Trans.js CHANGED
@@ -191,7 +191,8 @@ export function Trans(_ref) {
191
191
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
192
192
 
193
193
  var _ref2 = getHasUsedI18nextProvider() ? useContext(I18nContext) : {},
194
- i18nFromContext = _ref2.i18n;
194
+ i18nFromContext = _ref2.i18n,
195
+ defaultNSFromContext = _ref2.defaultNS;
195
196
 
196
197
  var i18n = i18nFromProps || i18nFromContext || getI18n();
197
198
 
@@ -204,7 +205,10 @@ export function Trans(_ref) {
204
205
 
205
206
  var reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react);
206
207
 
207
- var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
208
+ var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
209
+
210
+ var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
211
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
208
212
  var defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
209
213
  var hashTransKey = reactI18nextOptions.hashTransKey;
210
214
  var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
@@ -218,7 +222,7 @@ export function Trans(_ref) {
218
222
  var combinedTOpts = _objectSpread({}, tOptions, values, interpolationOverride, {
219
223
  defaultValue: defaultValue,
220
224
  count: count,
221
- ns: ns
225
+ ns: namespaces
222
226
  });
223
227
 
224
228
  var translation = key ? t(key, combinedTOpts) : defaultValue;
@@ -9,7 +9,8 @@ export function useTranslation(ns) {
9
9
  var i18nFromProps = props.i18n;
10
10
 
11
11
  var _ref = getHasUsedI18nextProvider() ? useContext(I18nContext) : {},
12
- i18nFromContext = _ref.i18n;
12
+ i18nFromContext = _ref.i18n,
13
+ defaultNSFromContext = _ref.defaultNS;
13
14
 
14
15
  var i18n = i18nFromProps || i18nFromContext || getI18n();
15
16
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
@@ -34,7 +35,7 @@ export function useTranslation(ns) {
34
35
  var _props$useSuspense = props.useSuspense,
35
36
  useSuspense = _props$useSuspense === void 0 ? i18nOptions.useSuspense : _props$useSuspense; // prepare having a namespace
36
37
 
37
- var namespaces = ns || i18n.options && i18n.options.defaultNS;
38
+ var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
38
39
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; // report namespaces as used
39
40
 
40
41
  if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); // are we ready? yes if all namespaces in first language are loaded already (either with data or empty object on failed load)
@@ -682,7 +682,8 @@
682
682
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
683
683
 
684
684
  const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
685
- i18nFromContext = _ref2.i18n;
685
+ i18nFromContext = _ref2.i18n,
686
+ defaultNSFromContext = _ref2.defaultNS;
686
687
 
687
688
  const i18n = i18nFromProps || i18nFromContext || getI18n();
688
689
 
@@ -695,7 +696,10 @@
695
696
 
696
697
  const reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react);
697
698
 
698
- const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
699
+ const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
700
+
701
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
702
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
699
703
  const defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
700
704
  const hashTransKey = reactI18nextOptions.hashTransKey;
701
705
  const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
@@ -709,7 +713,7 @@
709
713
  const combinedTOpts = _objectSpread({}, tOptions, values, interpolationOverride, {
710
714
  defaultValue,
711
715
  count,
712
- ns
716
+ ns: namespaces
713
717
  });
714
718
 
715
719
  const translation = key ? t(key, combinedTOpts) : defaultValue;
@@ -723,7 +727,8 @@
723
727
  const i18nFromProps = props.i18n;
724
728
 
725
729
  const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
726
- i18nFromContext = _ref.i18n;
730
+ i18nFromContext = _ref.i18n,
731
+ defaultNSFromContext = _ref.defaultNS;
727
732
 
728
733
  const i18n = i18nFromProps || i18nFromContext || getI18n();
729
734
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
@@ -744,7 +749,7 @@
744
749
  const _props$useSuspense = props.useSuspense,
745
750
  useSuspense = _props$useSuspense === void 0 ? i18nOptions.useSuspense : _props$useSuspense; // prepare having a namespace
746
751
 
747
- let namespaces = ns || i18n.options && i18n.options.defaultNS;
752
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
748
753
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; // report namespaces as used
749
754
 
750
755
  if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); // are we ready? yes if all namespaces in first language are loaded already (either with data or empty object on failed load)
@@ -855,11 +860,13 @@
855
860
 
856
861
  function I18nextProvider(_ref) {
857
862
  let i18n = _ref.i18n,
863
+ defaultNS = _ref.defaultNS,
858
864
  children = _ref.children;
859
865
  usedI18nextProvider(true);
860
866
  return React__default.createElement(I18nContext.Provider, {
861
867
  value: {
862
- i18n
868
+ i18n,
869
+ defaultNS
863
870
  }
864
871
  }, children);
865
872
  }
@@ -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 j{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function w(e){g=e}function x(){return g}const E={type:"3rdParty",init(e){v(e.options.react),w(e)}};function S(e){return t=>new Promise(n=>{const r=$();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function $(){const e=x(),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 N(){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),N(...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):{}).i18n,s=r||o||x();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new j),!s){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 c=i({},O(),s.options.react),l=n.useSuspense,u=void 0===l?c.useSuspense:l;let p=e||s.options&&s.options.defaultNS;p="string"==typeof p?[p]:p||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(p);const f=(s.isInitialized||s.initializedStoreOnce)&&p.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,s));function d(){return{t:s.getFixedT(null,"fallback"===c.nsMode?p:p[0])}}const g=a(t.useState(d()),2),h=g[0],m=g[1];t.useEffect(()=>{let e=!0;const t=c.bindI18n,n=c.bindI18nStore;function r(){e&&m(d())}return f||u||P(s,p,()=>{e&&m(d())}),t&&s&&s.on(t,r),n&&s&&s.store.on(n,r),()=>{e=!1,t&&s&&t.split(" ").forEach(e=>s.off(e,r)),n&&s&&n.split(" ").forEach(e=>s.store.off(e,r))}},[]);const v=[h.t,s,f];if(v.t=h.t,v.i18n=s,v.ready=f,f)return v;if(!f&&!u)return v;throw new Promise(e=>{P(s,p,()=>{m(d()),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||x();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):{}).i18n,j=g||v||x();if(!j)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const w=h||j.t.bind(j),E=i({},O(),j.options&&j.options.react),S=void 0!==s?s:E.defaultTransParent,$=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]}}}`:N("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else N("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,I=E.hashTransKey,P=c||(I?I($):$),R=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:$,count:a,ns:d}),z=P?w(P,R):$;return S?n.createElement(S,m,T(f||r,z,j,E,R)):T(f||r,z,j,E,R)},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.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t}},r)},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=S(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=w,e.getI18n=x,e.composeInitialProps=S,e.getInitialProps=$,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 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})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-i18next",
3
- "version": "10.10.0",
3
+ "version": "10.11.0",
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
@@ -682,7 +682,8 @@
682
682
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
683
683
 
684
684
  const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
685
- i18nFromContext = _ref2.i18n;
685
+ i18nFromContext = _ref2.i18n,
686
+ defaultNSFromContext = _ref2.defaultNS;
686
687
 
687
688
  const i18n = i18nFromProps || i18nFromContext || getI18n();
688
689
 
@@ -695,7 +696,10 @@
695
696
 
696
697
  const reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react);
697
698
 
698
- const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
699
+ const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
700
+
701
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
702
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
699
703
  const defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
700
704
  const hashTransKey = reactI18nextOptions.hashTransKey;
701
705
  const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
@@ -709,7 +713,7 @@
709
713
  const combinedTOpts = _objectSpread({}, tOptions, values, interpolationOverride, {
710
714
  defaultValue,
711
715
  count,
712
- ns
716
+ ns: namespaces
713
717
  });
714
718
 
715
719
  const translation = key ? t(key, combinedTOpts) : defaultValue;
@@ -723,7 +727,8 @@
723
727
  const i18nFromProps = props.i18n;
724
728
 
725
729
  const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {},
726
- i18nFromContext = _ref.i18n;
730
+ i18nFromContext = _ref.i18n,
731
+ defaultNSFromContext = _ref.defaultNS;
727
732
 
728
733
  const i18n = i18nFromProps || i18nFromContext || getI18n();
729
734
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
@@ -744,7 +749,7 @@
744
749
  const _props$useSuspense = props.useSuspense,
745
750
  useSuspense = _props$useSuspense === void 0 ? i18nOptions.useSuspense : _props$useSuspense; // prepare having a namespace
746
751
 
747
- let namespaces = ns || i18n.options && i18n.options.defaultNS;
752
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
748
753
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; // report namespaces as used
749
754
 
750
755
  if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); // are we ready? yes if all namespaces in first language are loaded already (either with data or empty object on failed load)
@@ -855,11 +860,13 @@
855
860
 
856
861
  function I18nextProvider(_ref) {
857
862
  let i18n = _ref.i18n,
863
+ defaultNS = _ref.defaultNS,
858
864
  children = _ref.children;
859
865
  usedI18nextProvider(true);
860
866
  return React__default.createElement(I18nContext.Provider, {
861
867
  value: {
862
- i18n
868
+ i18n,
869
+ defaultNS
863
870
  }
864
871
  }, children);
865
872
  }
@@ -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 j{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function w(e){g=e}function x(){return g}const E={type:"3rdParty",init(e){v(e.options.react),w(e)}};function S(e){return t=>new Promise(n=>{const r=$();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function $(){const e=x(),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 N(){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),N(...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):{}).i18n,s=r||o||x();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new j),!s){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 c=i({},O(),s.options.react),l=n.useSuspense,u=void 0===l?c.useSuspense:l;let p=e||s.options&&s.options.defaultNS;p="string"==typeof p?[p]:p||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(p);const f=(s.isInitialized||s.initializedStoreOnce)&&p.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,s));function d(){return{t:s.getFixedT(null,"fallback"===c.nsMode?p:p[0])}}const g=a(t.useState(d()),2),h=g[0],m=g[1];t.useEffect(()=>{let e=!0;const t=c.bindI18n,n=c.bindI18nStore;function r(){e&&m(d())}return f||u||P(s,p,()=>{e&&m(d())}),t&&s&&s.on(t,r),n&&s&&s.store.on(n,r),()=>{e=!1,t&&s&&t.split(" ").forEach(e=>s.off(e,r)),n&&s&&n.split(" ").forEach(e=>s.store.off(e,r))}},[]);const v=[h.t,s,f];if(v.t=h.t,v.i18n=s,v.ready=f,f)return v;if(!f&&!u)return v;throw new Promise(e=>{P(s,p,()=>{m(d()),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||x();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):{}).i18n,j=g||v||x();if(!j)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const w=h||j.t.bind(j),E=i({},O(),j.options&&j.options.react),S=void 0!==s?s:E.defaultTransParent,$=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]}}}`:N("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else N("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,I=E.hashTransKey,P=c||(I?I($):$),R=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:$,count:a,ns:d}),z=P?w(P,R):$;return S?n.createElement(S,m,T(f||r,z,j,E,R)):T(f||r,z,j,E,R)},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.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t}},r)},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=S(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=w,e.getI18n=x,e.composeInitialProps=S,e.getInitialProps=$,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 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,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { I18nContext, usedI18nextProvider } from './context';
3
3
 
4
- export function I18nextProvider({ i18n, children }) {
4
+ export function I18nextProvider({ i18n, defaultNS, children }) {
5
5
  usedI18nextProvider(true);
6
6
 
7
7
  return React.createElement(
@@ -9,6 +9,7 @@ export function I18nextProvider({ i18n, children }) {
9
9
  {
10
10
  value: {
11
11
  i18n,
12
+ defaultNS,
12
13
  },
13
14
  },
14
15
  children,
package/src/Trans.js CHANGED
@@ -199,7 +199,9 @@ export function Trans({
199
199
  t: tFromProps,
200
200
  ...additionalProps
201
201
  }) {
202
- const { i18n: i18nFromContext } = getHasUsedI18nextProvider() ? useContext(I18nContext) : {};
202
+ const { i18n: i18nFromContext, defaultNS: defaultNSFromContext } = getHasUsedI18nextProvider()
203
+ ? useContext(I18nContext)
204
+ : {};
203
205
  const i18n = i18nFromProps || i18nFromContext || getI18n();
204
206
  if (!i18n) {
205
207
  warnOnce('You will need pass in an i18next instance by using i18nextReactModule');
@@ -211,6 +213,10 @@ export function Trans({
211
213
  const reactI18nextOptions = { ...getDefaults(), ...(i18n.options && i18n.options.react) };
212
214
  const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
213
215
 
216
+ // prepare having a namespace
217
+ let namespaces = ns || defaultNSFromContext || (i18n.options && i18n.options.defaultNS);
218
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
219
+
214
220
  const defaultValue =
215
221
  defaults ||
216
222
  nodesToString('', children, 0, reactI18nextOptions) ||
@@ -224,7 +230,7 @@ export function Trans({
224
230
  ...interpolationOverride,
225
231
  defaultValue,
226
232
  count,
227
- ns,
233
+ ns: namespaces,
228
234
  };
229
235
  const translation = key ? t(key, combinedTOpts) : defaultValue;
230
236
 
@@ -11,7 +11,9 @@ import { warnOnce, loadNamespaces, hasLoadedNamespace } from './utils';
11
11
  export function useTranslation(ns, props = {}) {
12
12
  // assert we have the needed i18nInstance
13
13
  const { i18n: i18nFromProps } = props;
14
- const { i18n: i18nFromContext } = getHasUsedI18nextProvider() ? useContext(I18nContext) : {};
14
+ const { i18n: i18nFromContext, defaultNS: defaultNSFromContext } = getHasUsedI18nextProvider()
15
+ ? useContext(I18nContext)
16
+ : {};
15
17
  const i18n = i18nFromProps || i18nFromContext || getI18n();
16
18
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
17
19
  if (!i18n) {
@@ -26,7 +28,7 @@ export function useTranslation(ns, props = {}) {
26
28
  const { useSuspense = i18nOptions.useSuspense } = props;
27
29
 
28
30
  // prepare having a namespace
29
- let namespaces = ns || (i18n.options && i18n.options.defaultNS);
31
+ let namespaces = ns || defaultNSFromContext || (i18n.options && i18n.options.defaultNS);
30
32
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
31
33
 
32
34
  // report namespaces as used