react-i18next 14.1.2 → 15.0.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +0 -2
  3. package/dist/amd/react-i18next.js +134 -176
  4. package/dist/amd/react-i18next.min.js +1 -1
  5. package/dist/commonjs/Trans.js +2 -2
  6. package/dist/commonjs/TransWithoutContext.js +53 -55
  7. package/dist/commonjs/Translation.js +6 -5
  8. package/dist/commonjs/context.js +17 -25
  9. package/dist/commonjs/defaults.js +6 -7
  10. package/dist/commonjs/i18nInstance.js +6 -7
  11. package/dist/commonjs/useSSR.js +5 -4
  12. package/dist/commonjs/useTranslation.js +17 -20
  13. package/dist/commonjs/utils.js +28 -45
  14. package/dist/commonjs/withSSR.js +19 -20
  15. package/dist/commonjs/withTranslation.js +4 -3
  16. package/dist/es/I18nextProvider.js +5 -6
  17. package/dist/es/Trans.js +18 -19
  18. package/dist/es/TransWithoutContext.js +68 -72
  19. package/dist/es/Translation.js +6 -7
  20. package/dist/es/context.js +13 -22
  21. package/dist/es/defaults.js +3 -6
  22. package/dist/es/i18nInstance.js +3 -5
  23. package/dist/es/package.json +1 -1
  24. package/dist/es/useSSR.js +3 -4
  25. package/dist/es/useTranslation.js +16 -21
  26. package/dist/es/utils.js +19 -46
  27. package/dist/es/withSSR.js +16 -19
  28. package/dist/es/withTranslation.js +28 -32
  29. package/dist/umd/react-i18next.js +134 -176
  30. package/dist/umd/react-i18next.min.js +1 -1
  31. package/icu.macro.d.ts +5 -5
  32. package/index.d.ts +2 -2
  33. package/package.json +23 -30
  34. package/react-i18next.js +134 -176
  35. package/react-i18next.min.js +1 -1
  36. package/src/Trans.js +2 -3
  37. package/src/TransWithoutContext.js +56 -62
  38. package/src/Translation.js +2 -3
  39. package/src/context.js +13 -36
  40. package/src/defaults.js +3 -5
  41. package/src/i18nInstance.js +3 -5
  42. package/src/useSSR.js +3 -3
  43. package/src/useTranslation.js +25 -24
  44. package/src/utils.js +26 -76
  45. package/src/withSSR.js +2 -3
  46. package/src/withTranslation.js +2 -3
  47. package/vitest.workspace.typescript.mts +11 -0
@@ -1 +1 @@
1
- define(["exports","react"],(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),i=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function r(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var o=new RegExp(i),a=null;null!==(a=o.exec(e));)if(a[0].trim())if(a[1]){var c=a[1].trim(),l=[c,""];c.indexOf("=")>-1&&(l=c.split("=")),n.attrs[l[0]]=l[1],o.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var o=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,a=/^\s*$/,c=Object.create(null);function l(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(l,"")+"</"+n.name+">";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var u={parse:function(e,n){n||(n={}),n.components||(n.components=c);var t,s=[],i=[],l=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(o,(function(o,c){if(u){if(o!=="</"+t.name+">")return;u=!1}var p,d="/"!==o.charAt(1),f=o.startsWith("\x3c!--"),g=c+o.length,m=e.charAt(g);if(f){var h=r(o);return l<0?(s.push(h),s):((p=i[l]).children.push(h),s)}if(d&&(l++,"tag"===(t=r(o)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!m||"<"===m||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===l&&s.push(t),(p=i[l-1])&&p.children.push(t),i[l]=t),(!d||t.voidElement)&&(l>-1&&(t.voidElement||t.name===o.slice(2,-1))&&(l--,t=-1===l?s:i[l]),!u&&"<"!==m&&m)){p=-1===l?s:i[l].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);a.test(b)&&(b=" "),(y>-1&&l+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+l("",n)}),"")}};function p(){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 d={};function f(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&d[n[0]]||("string"==typeof n[0]&&(d[n[0]]=new Date),p(...n))}const g=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}};function m(e,n,t){e.loadNamespaces(n,g(e,t))}function h(e,n,t,s){"string"==typeof t&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,g(e,s))}function y(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}const b=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,v={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},x=e=>v[e];let E,N={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(b,x)};function O(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N={...N,...e}}function $(){return N}function w(e){E=e}function k(){return E}function I(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function S(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?j(n):n}function j(e){return Array.isArray(e)?e:[e]}function C(e,t){if(!e)return"";let s="";const i=j(e),r=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return i.forEach(((e,i)=>{if("string"==typeof e)s+=`${e}`;else if(n.isValidElement(e)){const n=Object.keys(e.props).length,o=r.indexOf(e.type)>-1,a=e.props.children;if(!a&&o&&0===n)s+=`<${e.type}/>`;else if(a||o&&0===n)if(e.props.i18nIsDynamicList)s+=`<${i}></${i}>`;else if(o&&1===n&&"string"==typeof a)s+=`<${e.type}>${a}</${e.type}>`;else{const e=C(a,t);s+=`<${i}>${e}</${i}>`}else s+=`<${i}></${i}>`}else if(null===e)p("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"==typeof e){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];s+=`{{${e}}}`}else p("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else p("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}}.",e)})),s}function R(e,t,s,i,r,o){if(""===t)return[];const a=i.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(a.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!c&&!o)return[t];const l={};!function e(t){j(t).forEach((t=>{"string"!=typeof t&&(I(t)?e(S(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))}))}(e);const p=u.parse(`<0>${t}</0>`),d={...l,...r};function f(e,t,s){const i=S(e),r=m(i,t.children,s);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((e=>n.isValidElement(e)))}(i)&&0===r.length||e.props&&e.props.i18nIsDynamicList?i:r}function g(e,t,s,i,r){e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:i},r?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:i,ref:e.ref},r?null:t)})))}function m(t,r,l){const u=j(t);return j(r).reduce(((t,r,p)=>{const h=r.children&&r.children[0]&&r.children[0].content&&s.services.interpolator.interpolate(r.children[0].content,d,s.language);if("tag"===r.type){let o=u[parseInt(r.name,10)];1!==l.length||o||(o=l[0][r.name]),o||(o={});const y=0!==Object.keys(r.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:r.attrs},o):o,b=n.isValidElement(y),v=b&&I(r,!0)&&!r.voidElement,x=c&&"object"==typeof y&&y.dummy&&!b,E="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,r.name);if("string"==typeof y){const e=s.services.interpolator.interpolate(y,d,s.language);t.push(e)}else if(I(y)||v){g(y,f(y,r,l),t,p)}else if(x){g(y,m(u,r.children,l),t,p)}else if(Number.isNaN(parseFloat(r.name)))if(E){g(y,f(y,r,l),t,p,r.voidElement)}else if(i.transSupportBasicHtmlNodes&&a.indexOf(r.name)>-1)if(r.voidElement)t.push(n.createElement(r.name,{key:`${r.name}-${p}`}));else{const e=m(u,r.children,l);t.push(n.createElement(r.name,{key:`${r.name}-${p}`},e))}else if(r.voidElement)t.push(`<${r.name} />`);else{const e=m(u,r.children,l);t.push(`<${r.name}>${e}</${r.name}>`)}else if("object"!=typeof y||b)g(y,h,t,p,1!==r.children.length||!h);else{const e=r.children[0]?h:null;e&&t.push(e)}}else if("text"===r.type){const e=i.transWrapTextNodes,a=o?i.unescape(s.services.interpolator.interpolate(r.content,d,s.language)):s.services.interpolator.interpolate(r.content,d,s.language);e?t.push(n.createElement(e,{key:`${r.name}-${p}`},a)):t.push(a)}return t}),[])}return S(m([{dummy:!0,children:e||[]}],p,j(e||[]))[0])}function L(e){let{children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:d,t:g,shouldUnescape:m,...h}=e;const y=d||k();if(!y)return f("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=g||y.t.bind(y)||(e=>e),v={...$(),...y.options&&y.options.react};let x=p||b.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const E=C(t,v),N=l||E||v.transEmptyNodeValue||r,{hashTransKey:O}=v,w=r||(O?O(E||N):E||N);y.options&&y.options.interpolation&&y.options.interpolation.defaultVariables&&(c=c&&Object.keys(c).length>0?{...c,...y.options.interpolation.defaultVariables}:{...y.options.interpolation.defaultVariables});const I=c||void 0!==s||!t?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},S={...a,context:o||a.context,count:s,...c,...I,defaultValue:N,ns:x},j=w?b(w,S):N;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||j.indexOf(`${e}/>`)<0&&j.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const L=R(u||t,j,y,v,S,m),T=void 0!==i?i:v.defaultTransParent;return T?n.createElement(T,h,L):L}const T={type:"3rdParty",init(e){O(e.options.react),w(e)}},P=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function z(e){return n=>new Promise((t=>{const s=A();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function A(){const e=k(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t}const B=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e,n,t,s){return e.getFixedT(n,t,s)}function U(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:r}=n.useContext(P)||{},o=s||i||k();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new V),!o){f("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>"string"==typeof n?n:n&&"object"==typeof n&&"string"==typeof n.defaultValue?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}o.options.react&&void 0!==o.options.react.wait&&f("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...$(),...o.options.react,...t},{useSuspense:c,keyPrefix:l}=a;let u=e||r||o.options&&o.options.defaultNS;u="string"==typeof u?[u]:u||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(u);const p=(o.isInitialized||o.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?void 0!==n.options.ignoreJSONStructure?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=n.languages[0],i=!!n.options&&n.options.fallbackLng,r=n.languages[n.languages.length-1];if("cimode"===s.toLowerCase())return!0;const o=(e,t)=>{const s=n.services.backendConnector.state[`${e}|${t}`];return-1===s||2===s};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e)||!n.hasResourceBundle(s,e)&&n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages)&&(!o(s,e)||i&&!o(r,e)))}(e,n,t):(f("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a))),d=function(e,t,s,i){return n.useCallback(F(e,t,s,i),[e,t,s,i])}(o,t.lng||null,"fallback"===a.nsMode?u:u[0],l),g=()=>d,y=()=>F(o,t.lng||null,"fallback"===a.nsMode?u:u[0],l),[b,v]=n.useState(g);let x=u.join();t.lng&&(x=`${t.lng}${x}`);const E=B(x),N=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){N.current&&v(y)}return N.current=!0,p||c||(t.lng?h(o,t.lng,u,(()=>{N.current&&v(y)})):m(o,u,(()=>{N.current&&v(y)}))),p&&E&&E!==x&&N.current&&v(y),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{N.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,x]),n.useEffect((()=>{N.current&&p&&v(g)}),[o,l,p]);const O=[b,o,p];if(O.t=b,O.i18n=o,O.ready=p,p)return O;if(!p&&!c)return O;throw new Promise((e=>{t.lng?h(o,t.lng,u,(()=>e())):m(o,u,(()=>e()))}))}function K(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:i}=s,{i18n:r}=n.useContext(P)||{},o=i||r||k();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=P,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:i}=e;const r=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(P.Provider,{value:r},i)},e.Trans=function(e){let{children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...m}=e;const{i18n:h,defaultNS:y}=n.useContext(P)||{},b=d||h||k(),v=f||b&&b.t.bind(b);return L({children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a,values:c,defaults:l,components:u,ns:p||v&&v.ns||y||b&&b.options&&b.options.defaultNS,i18n:b,t:f,shouldUnescape:g,...m})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,r,o]=U(n,s);return t(i,{i18n:r,lng:r.language},o)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=k,e.getInitialProps=A,e.initReactI18next=T,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=K,e.useTranslation=U,e.withSSR=function(){return function(e){function t(t){let{initialI18nStore:s,initialLanguage:i,...r}=t;return K(s,i),n.createElement(e,{...r})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${y(e)})`,t.WrappedComponent=e,t}},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function i(i){let{forwardedRef:r,...o}=i;const[a,c,l]=U(e,{...o,keyPrefix:t.keyPrefix}),u={...o,t:a,i18n:c,tReady:l};return t.withRef&&r?u.ref=r:!t.withRef&&r&&(u.forwardedRef=r),n.createElement(s,u)}i.displayName=`withI18nextTranslation(${y(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}}));
1
+ define(["exports","react"],(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),a=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function i(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var i=e.indexOf("--\x3e");return{type:"comment",comment:-1!==i?e.slice(4,i):""}}for(var r=new RegExp(a),o=null;null!==(o=r.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],r.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],a=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(r,(function(r,l){if(u){if(r!=="</"+t.name+">")return;u=!1}var p,d="/"!==r.charAt(1),f=r.startsWith("\x3c!--"),h=l+r.length,m=e.charAt(h);if(f){var g=i(r);return c<0?(s.push(g),s):((p=a[c]).children.push(g),s)}if(d&&(c++,"tag"===(t=i(r)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!m||"<"===m||t.children.push({type:"text",content:e.slice(h,e.indexOf("<",h))}),0===c&&s.push(t),(p=a[c-1])&&p.children.push(t),a[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===r.slice(2,-1))&&(c--,t=-1===c?s:a[c]),!u&&"<"!==m&&m)){p=-1===c?s:a[c].children;var y=e.indexOf("<",h),v=e.slice(h,-1===y?void 0:y);o.test(v)&&(v=" "),(y>-1&&c+p.length>=0||" "!==v)&&p.push({type:"text",content:v})}})),s};const u=function(){if(console?.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}},p={},d=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&p[n[0]]||(y(n[0])&&(p[n[0]]=new Date),u(...n))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},h=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},m=(e,n,t,s)=>{y(t)&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},g=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,v=e=>"object"==typeof e&&null!==e,x=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},E=e=>b[e];let O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(x,E)};const N=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}},$=()=>O;let w;const I=e=>{w=e},k=()=>w,S=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},j=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],C=(e,t)=>{if(!e)return"";let s="";const a=R(e),i=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach(((e,a)=>{if(y(e))s+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:r}=e,o=Object.keys(n).length,l=i.indexOf(r)>-1,c=n.children;if(c||!l||o)if(!c&&(!l||o)||n.i18nIsDynamicList)s+=`<${a}></${a}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}</${r}>`;else{const e=C(c,t);s+=`<${a}>${e}</${a}>`}else s+=`<${r}/>`}else if(null===e)u("Trans: the passed in value is invalid - seems you passed in a null child.");else if(v(e)){const{format:n,...t}=e,a=Object.keys(t);if(1===a.length){const e=n?`${a[0]}, ${n}`:a[0];s+=`{{${e}}}`}else u("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else u("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}}.",e)})),s},T=(e,t,s,a,i,r)=>{if(""===t)return[];const o=a.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!r)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(S(e)?p(j(e)):v(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...i},h=(e,t,s)=>{const a=j(e),i=g(a,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(a)&&0===i.length||e.props?.i18nIsDynamicList?a:i},m=(e,t,s,a,i)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:a},i?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:a,ref:e.ref},i?null:t)})))},g=(t,i,c)=>{const u=R(t);return R(i).reduce(((t,i,p)=>{const d=i.children?.[0]?.content&&s.services.interpolator.interpolate(i.children[0].content,f,s.language);if("tag"===i.type){let r=u[parseInt(i.name,10)];1!==c.length||r||(r=c[0][i.name]),r||(r={});const x=0!==Object.keys(i.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:i.attrs},r):r,b=n.isValidElement(x),E=b&&S(i,!0)&&!i.voidElement,O=l&&v(x)&&x.dummy&&!b,N=v(e)&&Object.hasOwnProperty.call(e,i.name);if(y(x)){const e=s.services.interpolator.interpolate(x,f,s.language);t.push(e)}else if(S(x)||E){const e=h(x,i,c);m(x,e,t,p)}else if(O){const e=g(u,i.children,c);m(x,e,t,p)}else if(Number.isNaN(parseFloat(i.name)))if(N){const e=h(x,i,c);m(x,e,t,p,i.voidElement)}else if(a.transSupportBasicHtmlNodes&&o.indexOf(i.name)>-1)if(i.voidElement)t.push(n.createElement(i.name,{key:`${i.name}-${p}`}));else{const e=g(u,i.children,c);t.push(n.createElement(i.name,{key:`${i.name}-${p}`},e))}else if(i.voidElement)t.push(`<${i.name} />`);else{const e=g(u,i.children,c);t.push(`<${i.name}>${e}</${i.name}>`)}else if(v(x)&&!b){const e=i.children[0]?d:null;e&&t.push(e)}else m(x,d,t,p,1!==i.children.length||!d)}else if("text"===i.type){const e=a.transWrapTextNodes,o=r?a.unescape(s.services.interpolator.interpolate(i.content,f,s.language)):s.services.interpolator.interpolate(i.content,f,s.language);e?t.push(n.createElement(e,{key:`${i.name}-${p}`},o)):t.push(o)}return t}),[])},x=g([{dummy:!0,children:e||[]}],d,R(e||[]));return j(x[0])};function P(e){let{children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:h,shouldUnescape:m,...g}=e;const v=f||k();if(!v)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const x=h||v.t.bind(v)||(e=>e),b={...$(),...v.options?.react};let E=p||x.ns||v.options?.defaultNS;E=y(E)?[E]:E||["translation"];const O=C(t,b),N=c||O||b.transEmptyNodeValue||i,{hashTransKey:w}=b,I=i||(w?w(O||N):O||N);v.options?.interpolation?.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...v.options.interpolation.defaultVariables}:{...v.options.interpolation.defaultVariables});const S=l||void 0!==s||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},j={...o,context:r||o.context,count:s,...l,...S,defaultValue:N,ns:E},R=I?x(I,j):N;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||R.indexOf(`${e}/>`)<0&&R.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const P=T(u||t,R,v,b,j,m),L=a??b.defaultTransParent;return L?n.createElement(L,g,P):P}const L={type:"3rdParty",init(e){N(e.options.react),I(e)}},A=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]??=!0}))}getUsedNamespaces=()=>Object.keys(this.usedNamespaces)}const z=e=>async n=>({...await(e.getInitialProps?.(n))??{},...F()}),F=()=>{const e=k(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),B=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:a,defaultNS:i}=n.useContext(A)||{},r=s||a||k();if(r&&!r.reportNamespaces&&(r.reportNamespaces=new V),!r){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:v(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}r.options.react?.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...$(),...r.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||i||r.options?.defaultNS;u=y(u)?[u]:u||["translation"],r.reportNamespaces.addUsedNamespaces?.(u);const p=(r.isInitialized||r.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,r,o))),f=((e,t,s,a)=>n.useCallback(U(e,t,s,a),[e,t,s,a]))(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),g=()=>f,x=()=>U(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,E]=n.useState(g);let O=u.join();t.lng&&(O=`${t.lng}${O}`);const N=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(O),w=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;w.current=!0,p||l||(t.lng?m(r,t.lng,u,(()=>{w.current&&E(x)})):h(r,u,(()=>{w.current&&E(x)}))),p&&N&&N!==O&&w.current&&E(x);const s=()=>{w.current&&E(x)};return e&&r?.on(e,s),n&&r?.store.on(n,s),()=>{w.current=!1,r&&e?.split(" ").forEach((e=>r.off(e,s))),n&&r&&n.split(" ").forEach((e=>r.store.off(e,s)))}}),[r,O]),n.useEffect((()=>{w.current&&p&&E(g)}),[r,c,p]);const I=[b,r,p];if(I.t=b,I.i18n=r,I.ready=p,p)return I;if(!p&&!l)return I;throw new Promise((e=>{t.lng?m(r,t.lng,u,(()=>e())):h(r,u,(()=>e()))}))};const D=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:a}=s,{i18n:i}=n.useContext(A)||{},r=a||i||k();r.options?.isClone||(e&&!r.initializedStoreOnce&&(r.services.resourceStore.data=e,r.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),r.options.ns),r.initializedStoreOnce=!0,r.isInitialized=!0),t&&!r.initializedLanguageOnce&&(r.changeLanguage(t),r.initializedLanguageOnce=!0))};e.I18nContext=A,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:a}=e;const i=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(A.Provider,{value:i},a)},e.Trans=function(e){let{children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:h,...m}=e;const{i18n:g,defaultNS:y}=n.useContext(A)||{},v=d||g||k(),x=f||v?.t.bind(v);return P({children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o,values:l,defaults:c,components:u,ns:p||x?.ns||y||v?.options?.defaultNS,i18n:v,t:f,shouldUnescape:h,...m})},e.TransWithoutContext=P,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[a,i,r]=B(n,s);return t(a,{i18n:i,lng:i.language},r)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=k,e.getInitialProps=F,e.initReactI18next=L,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=N,e.setI18n=I,e.time=()=>"",e.useSSR=D,e.useTranslation=B,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:a,...i}=t;return D(s,a),n.createElement(e,{...i})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${g(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function a(a){let{forwardedRef:i,...r}=a;const[o,l,c]=B(e,{...r,keyPrefix:t.keyPrefix}),u={...r,t:o,i18n:l,tReady:c};return t.withRef&&i?u.ref=i:!t.withRef&&i&&(u.forwardedRef=i),n.createElement(s,u)}a.displayName=`withI18nextTranslation(${g(s)})`,a.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(a,Object.assign({},e,{forwardedRef:t})))):a}}}));
@@ -35,7 +35,7 @@ function Trans(_ref) {
35
35
  defaultNS: defaultNSFromContext
36
36
  } = (0, _react.useContext)(_context.I18nContext) || {};
37
37
  const i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)();
38
- const t = tFromProps || i18n && i18n.t.bind(i18n);
38
+ const t = tFromProps || i18n?.t.bind(i18n);
39
39
  return (0, _TransWithoutContext.Trans)({
40
40
  children,
41
41
  count,
@@ -46,7 +46,7 @@ function Trans(_ref) {
46
46
  values,
47
47
  defaults,
48
48
  components,
49
- ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
49
+ ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS,
50
50
  i18n,
51
51
  t: tFromProps,
52
52
  shouldUnescape,
@@ -5,64 +5,61 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.Trans = Trans;
8
- exports.nodesToString = nodesToString;
8
+ exports.nodesToString = void 0;
9
9
  var _react = require("react");
10
10
  var _htmlParseStringify = _interopRequireDefault(require("html-parse-stringify"));
11
11
  var _utils = require("./utils.js");
12
12
  var _defaults = require("./defaults.js");
13
13
  var _i18nInstance = require("./i18nInstance.js");
14
- function hasChildren(node, checkLength) {
14
+ const hasChildren = (node, checkLength) => {
15
15
  if (!node) return false;
16
- const base = node.props ? node.props.children : node.children;
16
+ const base = node.props?.children ?? node.children;
17
17
  if (checkLength) return base.length > 0;
18
18
  return !!base;
19
- }
20
- function getChildren(node) {
19
+ };
20
+ const getChildren = node => {
21
21
  if (!node) return [];
22
- const children = node.props ? node.props.children : node.children;
23
- return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children;
24
- }
25
- function hasValidReactChildren(children) {
26
- if (Object.prototype.toString.call(children) !== '[object Array]') return false;
27
- return children.every(child => (0, _react.isValidElement)(child));
28
- }
29
- function getAsArray(data) {
30
- return Array.isArray(data) ? data : [data];
31
- }
32
- function mergeProps(source, target) {
22
+ const children = node.props?.children ?? node.children;
23
+ return node.props?.i18nIsDynamicList ? getAsArray(children) : children;
24
+ };
25
+ const hasValidReactChildren = children => Array.isArray(children) && children.every(_react.isValidElement);
26
+ const getAsArray = data => Array.isArray(data) ? data : [data];
27
+ const mergeProps = (source, target) => {
33
28
  const newTarget = {
34
29
  ...target
35
30
  };
36
31
  newTarget.props = Object.assign(source.props, target.props);
37
32
  return newTarget;
38
- }
39
- function nodesToString(children, i18nOptions) {
33
+ };
34
+ const nodesToString = (children, i18nOptions) => {
40
35
  if (!children) return '';
41
36
  let stringNode = '';
42
37
  const childrenArray = getAsArray(children);
43
- const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
38
+ const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : [];
44
39
  childrenArray.forEach((child, childIndex) => {
45
- if (typeof child === 'string') {
40
+ if ((0, _utils.isString)(child)) {
46
41
  stringNode += `${child}`;
47
42
  } else if ((0, _react.isValidElement)(child)) {
48
- const childPropsCount = Object.keys(child.props).length;
49
- const shouldKeepChild = keepArray.indexOf(child.type) > -1;
50
- const childChildren = child.props.children;
51
- if (!childChildren && shouldKeepChild && childPropsCount === 0) {
52
- stringNode += `<${child.type}/>`;
53
- } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
54
- stringNode += `<${childIndex}></${childIndex}>`;
55
- } else if (child.props.i18nIsDynamicList) {
43
+ const {
44
+ props,
45
+ type
46
+ } = child;
47
+ const childPropsCount = Object.keys(props).length;
48
+ const shouldKeepChild = keepArray.indexOf(type) > -1;
49
+ const childChildren = props.children;
50
+ if (!childChildren && shouldKeepChild && !childPropsCount) {
51
+ stringNode += `<${type}/>`;
52
+ } else if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
56
53
  stringNode += `<${childIndex}></${childIndex}>`;
57
- } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
58
- stringNode += `<${child.type}>${childChildren}</${child.type}>`;
54
+ } else if (shouldKeepChild && childPropsCount === 1 && (0, _utils.isString)(childChildren)) {
55
+ stringNode += `<${type}>${childChildren}</${type}>`;
59
56
  } else {
60
57
  const content = nodesToString(childChildren, i18nOptions);
61
58
  stringNode += `<${childIndex}>${content}</${childIndex}>`;
62
59
  }
63
60
  } else if (child === null) {
64
61
  (0, _utils.warn)(`Trans: the passed in value is invalid - seems you passed in a null child.`);
65
- } else if (typeof child === 'object') {
62
+ } else if ((0, _utils.isObject)(child)) {
66
63
  const {
67
64
  format,
68
65
  ...clone
@@ -79,32 +76,33 @@ function nodesToString(children, i18nOptions) {
79
76
  }
80
77
  });
81
78
  return stringNode;
82
- }
83
- function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
79
+ };
80
+ exports.nodesToString = nodesToString;
81
+ const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
84
82
  if (targetString === '') return [];
85
83
  const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
86
84
  const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
87
85
  if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
88
86
  const data = {};
89
- function getData(childs) {
87
+ const getData = childs => {
90
88
  const childrenArray = getAsArray(childs);
91
89
  childrenArray.forEach(child => {
92
- if (typeof child === 'string') return;
93
- if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !(0, _react.isValidElement)(child)) Object.assign(data, child);
90
+ if ((0, _utils.isString)(child)) return;
91
+ if (hasChildren(child)) getData(getChildren(child));else if ((0, _utils.isObject)(child) && !(0, _react.isValidElement)(child)) Object.assign(data, child);
94
92
  });
95
- }
93
+ };
96
94
  getData(children);
97
95
  const ast = _htmlParseStringify.default.parse(`<0>${targetString}</0>`);
98
96
  const opts = {
99
97
  ...data,
100
98
  ...combinedTOpts
101
99
  };
102
- function renderInner(child, node, rootReactNode) {
100
+ const renderInner = (child, node, rootReactNode) => {
103
101
  const childs = getChildren(child);
104
102
  const mappedChildren = mapAST(childs, node.children, rootReactNode);
105
- return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren;
106
- }
107
- function pushTranslatedJSX(child, inner, mem, i, isVoid) {
103
+ return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren;
104
+ };
105
+ const pushTranslatedJSX = (child, inner, mem, i, isVoid) => {
108
106
  if (child.dummy) {
109
107
  child.children = inner;
110
108
  mem.push((0, _react.cloneElement)(child, {
@@ -123,12 +121,12 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
123
121
  }, isVoid ? null : inner);
124
122
  }));
125
123
  }
126
- }
127
- function mapAST(reactNode, astNode, rootReactNode) {
124
+ };
125
+ const mapAST = (reactNode, astNode, rootReactNode) => {
128
126
  const reactNodes = getAsArray(reactNode);
129
127
  const astNodes = getAsArray(astNode);
130
128
  return astNodes.reduce((mem, node, i) => {
131
- const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
129
+ const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
132
130
  if (node.type === 'tag') {
133
131
  let tmp = reactNodes[parseInt(node.name, 10)];
134
132
  if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
@@ -138,9 +136,9 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
138
136
  }, tmp) : tmp;
139
137
  const isElement = (0, _react.isValidElement)(child);
140
138
  const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
141
- const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
142
- const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
143
- if (typeof child === 'string') {
139
+ const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && (0, _utils.isObject)(child) && child.dummy && !isElement;
140
+ const isKnownComponent = (0, _utils.isObject)(children) && Object.hasOwnProperty.call(children, node.name);
141
+ if ((0, _utils.isString)(child)) {
144
142
  const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
145
143
  mem.push(value);
146
144
  } else if (hasChildren(child) || isValidTranslationWithChildren) {
@@ -170,7 +168,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
170
168
  const inner = mapAST(reactNodes, node.children, rootReactNode);
171
169
  mem.push(`<${node.name}>${inner}</${node.name}>`);
172
170
  }
173
- } else if (typeof child === 'object' && !isElement) {
171
+ } else if ((0, _utils.isObject)(child) && !isElement) {
174
172
  const content = node.children[0] ? translationContent : null;
175
173
  if (content) mem.push(content);
176
174
  } else {
@@ -189,13 +187,13 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
189
187
  }
190
188
  return mem;
191
189
  }, []);
192
- }
190
+ };
193
191
  const result = mapAST([{
194
192
  dummy: true,
195
193
  children: children || []
196
194
  }], ast, getAsArray(children || []));
197
195
  return getChildren(result[0]);
198
- }
196
+ };
199
197
  function Trans(_ref) {
200
198
  let {
201
199
  children,
@@ -221,17 +219,17 @@ function Trans(_ref) {
221
219
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
222
220
  const reactI18nextOptions = {
223
221
  ...(0, _defaults.getDefaults)(),
224
- ...(i18n.options && i18n.options.react)
222
+ ...i18n.options?.react
225
223
  };
226
- let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
227
- namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
224
+ let namespaces = ns || t.ns || i18n.options?.defaultNS;
225
+ namespaces = (0, _utils.isString)(namespaces) ? [namespaces] : namespaces || ['translation'];
228
226
  const nodeAsString = nodesToString(children, reactI18nextOptions);
229
227
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
230
228
  const {
231
229
  hashTransKey
232
230
  } = reactI18nextOptions;
233
231
  const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue);
234
- if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) {
232
+ if (i18n.options?.interpolation?.defaultVariables) {
235
233
  values = values && Object.keys(values).length > 0 ? {
236
234
  ...values,
237
235
  ...i18n.options.interpolation.defaultVariables
@@ -267,6 +265,6 @@ function Trans(_ref) {
267
265
  });
268
266
  }
269
267
  const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
270
- const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
268
+ const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
271
269
  return useAsParent ? (0, _react.createElement)(useAsParent, additionalProps, content) : content;
272
270
  }
@@ -3,17 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Translation = Translation;
6
+ exports.Translation = void 0;
7
7
  var _useTranslation = require("./useTranslation.js");
8
- function Translation(props) {
9
- const {
8
+ const Translation = _ref => {
9
+ let {
10
10
  ns,
11
11
  children,
12
12
  ...options
13
- } = props;
13
+ } = _ref;
14
14
  const [t, i18n, ready] = (0, _useTranslation.useTranslation)(ns, options);
15
15
  return children(t, {
16
16
  i18n,
17
17
  lng: i18n.language
18
18
  }, ready);
19
- }
19
+ };
20
+ exports.Translation = Translation;
@@ -3,8 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ReportNamespaces = exports.I18nContext = void 0;
7
- exports.composeInitialProps = composeInitialProps;
6
+ exports.composeInitialProps = exports.ReportNamespaces = exports.I18nContext = void 0;
8
7
  Object.defineProperty(exports, "getDefaults", {
9
8
  enumerable: true,
10
9
  get: function () {
@@ -17,7 +16,7 @@ Object.defineProperty(exports, "getI18n", {
17
16
  return _i18nInstance.getI18n;
18
17
  }
19
18
  });
20
- exports.getInitialProps = getInitialProps;
19
+ exports.getInitialProps = void 0;
21
20
  Object.defineProperty(exports, "initReactI18next", {
22
21
  enumerable: true,
23
22
  get: function () {
@@ -47,32 +46,24 @@ class ReportNamespaces {
47
46
  }
48
47
  addUsedNamespaces(namespaces) {
49
48
  namespaces.forEach(ns => {
50
- if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
49
+ this.usedNamespaces[ns] ??= true;
51
50
  });
52
51
  }
53
- getUsedNamespaces() {
54
- return Object.keys(this.usedNamespaces);
55
- }
52
+ getUsedNamespaces = () => Object.keys(this.usedNamespaces);
56
53
  }
57
54
  exports.ReportNamespaces = ReportNamespaces;
58
- function composeInitialProps(ForComponent) {
59
- return ctx => new Promise(resolve => {
60
- const i18nInitialProps = getInitialProps();
61
- if (ForComponent.getInitialProps) {
62
- ForComponent.getInitialProps(ctx).then(componentsInitialProps => {
63
- resolve({
64
- ...componentsInitialProps,
65
- ...i18nInitialProps
66
- });
67
- });
68
- } else {
69
- resolve(i18nInitialProps);
70
- }
71
- });
72
- }
73
- function getInitialProps() {
55
+ const composeInitialProps = ForComponent => async ctx => {
56
+ const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {};
57
+ const i18nInitialProps = getInitialProps();
58
+ return {
59
+ ...componentsInitialProps,
60
+ ...i18nInitialProps
61
+ };
62
+ };
63
+ exports.composeInitialProps = composeInitialProps;
64
+ const getInitialProps = () => {
74
65
  const i18n = (0, _i18nInstance.getI18n)();
75
- const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
66
+ const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? [];
76
67
  const ret = {};
77
68
  const initialI18nStore = {};
78
69
  i18n.languages.forEach(l => {
@@ -84,4 +75,5 @@ function getInitialProps() {
84
75
  ret.initialI18nStore = initialI18nStore;
85
76
  ret.initialLanguage = i18n.language;
86
77
  return ret;
87
- }
78
+ };
79
+ exports.getInitialProps = getInitialProps;
@@ -3,8 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getDefaults = getDefaults;
7
- exports.setDefaults = setDefaults;
6
+ exports.setDefaults = exports.getDefaults = void 0;
8
7
  var _unescape = require("./unescape.js");
9
8
  let defaultOptions = {
10
9
  bindI18n: 'languageChanged',
@@ -16,13 +15,13 @@ let defaultOptions = {
16
15
  useSuspense: true,
17
16
  unescape: _unescape.unescape
18
17
  };
19
- function setDefaults() {
18
+ const setDefaults = function () {
20
19
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
21
20
  defaultOptions = {
22
21
  ...defaultOptions,
23
22
  ...options
24
23
  };
25
- }
26
- function getDefaults() {
27
- return defaultOptions;
28
- }
24
+ };
25
+ exports.setDefaults = setDefaults;
26
+ const getDefaults = () => defaultOptions;
27
+ exports.getDefaults = getDefaults;
@@ -3,12 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getI18n = getI18n;
7
- exports.setI18n = setI18n;
6
+ exports.setI18n = exports.getI18n = void 0;
8
7
  let i18nInstance;
9
- function setI18n(instance) {
8
+ const setI18n = instance => {
10
9
  i18nInstance = instance;
11
- }
12
- function getI18n() {
13
- return i18nInstance;
14
- }
10
+ };
11
+ exports.setI18n = setI18n;
12
+ const getI18n = () => i18nInstance;
13
+ exports.getI18n = getI18n;
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useSSR = useSSR;
6
+ exports.useSSR = void 0;
7
7
  var _react = require("react");
8
8
  var _context = require("./context.js");
9
- function useSSR(initialI18nStore, initialLanguage) {
9
+ const useSSR = function (initialI18nStore, initialLanguage) {
10
10
  let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11
11
  const {
12
12
  i18n: i18nFromProps
@@ -15,7 +15,7 @@ function useSSR(initialI18nStore, initialLanguage) {
15
15
  i18n: i18nFromContext
16
16
  } = (0, _react.useContext)(_context.I18nContext) || {};
17
17
  const i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)();
18
- if (i18n.options && i18n.options.isClone) return;
18
+ if (i18n.options?.isClone) return;
19
19
  if (initialI18nStore && !i18n.initializedStoreOnce) {
20
20
  i18n.services.resourceStore.data = initialI18nStore;
21
21
  i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
@@ -31,4 +31,5 @@ function useSSR(initialI18nStore, initialLanguage) {
31
31
  i18n.changeLanguage(initialLanguage);
32
32
  i18n.initializedLanguageOnce = true;
33
33
  }
34
- }
34
+ };
35
+ exports.useSSR = useSSR;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useTranslation = useTranslation;
6
+ exports.useTranslation = void 0;
7
7
  var _react = require("react");
8
8
  var _context = require("./context.js");
9
9
  var _utils = require("./utils.js");
@@ -14,13 +14,9 @@ const usePrevious = (value, ignore) => {
14
14
  }, [value, ignore]);
15
15
  return ref.current;
16
16
  };
17
- function alwaysNewT(i18n, language, namespace, keyPrefix) {
18
- return i18n.getFixedT(language, namespace, keyPrefix);
19
- }
20
- function useMemoizedT(i18n, language, namespace, keyPrefix) {
21
- return (0, _react.useCallback)(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
22
- }
23
- function useTranslation(ns) {
17
+ const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
18
+ const useMemoizedT = (i18n, language, namespace, keyPrefix) => (0, _react.useCallback)(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
19
+ const useTranslation = function (ns) {
24
20
  let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25
21
  const {
26
22
  i18n: i18nFromProps
@@ -34,8 +30,8 @@ function useTranslation(ns) {
34
30
  if (!i18n) {
35
31
  (0, _utils.warnOnce)('You will need to pass in an i18next instance by using initReactI18next');
36
32
  const notReadyT = (k, optsOrDefaultValue) => {
37
- if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
38
- if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
33
+ if ((0, _utils.isString)(optsOrDefaultValue)) return optsOrDefaultValue;
34
+ if ((0, _utils.isObject)(optsOrDefaultValue) && (0, _utils.isString)(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
39
35
  return Array.isArray(k) ? k[k.length - 1] : k;
40
36
  };
41
37
  const retNotReady = [notReadyT, {}, false];
@@ -44,7 +40,7 @@ function useTranslation(ns) {
44
40
  retNotReady.ready = false;
45
41
  return retNotReady;
46
42
  }
47
- if (i18n.options.react && i18n.options.react.wait !== undefined) (0, _utils.warnOnce)('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
43
+ if (i18n.options.react?.wait) (0, _utils.warnOnce)('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
48
44
  const i18nOptions = {
49
45
  ...(0, _context.getDefaults)(),
50
46
  ...i18n.options.react,
@@ -54,9 +50,9 @@ function useTranslation(ns) {
54
50
  useSuspense,
55
51
  keyPrefix
56
52
  } = i18nOptions;
57
- let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
58
- namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
59
- if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
53
+ let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS;
54
+ namespaces = (0, _utils.isString)(namespaces) ? [namespaces] : namespaces || ['translation'];
55
+ i18n.reportNamespaces.addUsedNamespaces?.(namespaces);
60
56
  const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => (0, _utils.hasLoadedNamespace)(n, i18n, i18nOptions));
61
57
  const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
62
58
  const getT = () => memoGetT;
@@ -86,14 +82,14 @@ function useTranslation(ns) {
86
82
  if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
87
83
  setT(getNewT);
88
84
  }
89
- function boundReset() {
85
+ const boundReset = () => {
90
86
  if (isMounted.current) setT(getNewT);
91
- }
92
- if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
93
- if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
87
+ };
88
+ if (bindI18n) i18n?.on(bindI18n, boundReset);
89
+ if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset);
94
90
  return () => {
95
91
  isMounted.current = false;
96
- if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
92
+ if (i18n) bindI18n?.split(' ').forEach(e => i18n.off(e, boundReset));
97
93
  if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
98
94
  };
99
95
  }, [i18n, joinedNS]);
@@ -115,4 +111,5 @@ function useTranslation(ns) {
115
111
  (0, _utils.loadNamespaces)(i18n, namespaces, () => resolve());
116
112
  }
117
113
  });
118
- }
114
+ };
115
+ exports.useTranslation = useTranslation;