react-i18next 13.1.1 → 13.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/amd/react-i18next.js +4 -4
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/TransWithoutContext.js +4 -4
- package/dist/es/TransWithoutContext.js +4 -4
- package/dist/es/package.json +1 -1
- package/dist/umd/react-i18next.js +4 -4
- package/dist/umd/react-i18next.min.js +1 -1
- package/package.json +1 -1
- package/react-i18next.js +4 -4
- package/react-i18next.min.js +1 -1
- package/src/TransWithoutContext.js +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -271,7 +271,7 @@ define(['exports', 'react'], (function (exports, React) { 'use strict';
|
|
|
271
271
|
function getChildren(node) {
|
|
272
272
|
if (!node) return [];
|
|
273
273
|
const children = node.props ? node.props.children : node.children;
|
|
274
|
-
return node.props
|
|
274
|
+
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children;
|
|
275
275
|
}
|
|
276
276
|
function hasValidReactChildren(children) {
|
|
277
277
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
@@ -353,7 +353,7 @@ define(['exports', 'react'], (function (exports, React) { 'use strict';
|
|
|
353
353
|
function renderInner(child, node, rootReactNode) {
|
|
354
354
|
const childs = getChildren(child);
|
|
355
355
|
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
356
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props
|
|
356
|
+
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren;
|
|
357
357
|
}
|
|
358
358
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
359
359
|
if (child.dummy) {
|
|
@@ -383,8 +383,8 @@ define(['exports', 'react'], (function (exports, React) { 'use strict';
|
|
|
383
383
|
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
384
384
|
if (node.type === 'tag') {
|
|
385
385
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
386
|
-
if (rootReactNode.length === 1) tmp
|
|
387
|
-
tmp
|
|
386
|
+
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
387
|
+
if (!tmp) tmp = {};
|
|
388
388
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
389
389
|
props: node.attrs
|
|
390
390
|
}, tmp) : tmp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
define(["exports","react"],(function(e,n){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},t.apply(this,arguments)}function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i=s({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}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function o(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(i[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var s=e.indexOf("--\x3e");return{type:"comment",comment:-1!==s?e.slice(4,s):""}}for(var o=new RegExp(r),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 a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,c=/^\s*$/,l=Object.create(null);function u(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(u,"")+"</"+n.name+">";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var p={parse:function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],r=-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(a,(function(a,l){if(u){if(a!=="</"+t.name+">")return;u=!1}var p,d="/"!==a.charAt(1),f=a.startsWith("\x3c!--"),g=l+a.length,h=e.charAt(g);if(f){var m=o(a);return r<0?(s.push(m),s):((p=i[r]).children.push(m),s)}if(d&&(r++,"tag"===(t=o(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===r&&s.push(t),(p=i[r-1])&&p.children.push(t),i[r]=t),(!d||t.voidElement)&&(r>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(r--,t=-1===r?s:i[r]),!u&&"<"!==h&&h)){p=-1===r?s:i[r].children;var y=e.indexOf("<",g),v=e.slice(g,-1===y?void 0:y);c.test(v)&&(v=" "),(y>-1&&r+p.length>=0||" "!==v)&&p.push({type:"text",content:v})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+u("",n)}),"")}};function d(){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 f={};function g(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&f[n[0]]||("string"==typeof n[0]&&(f[n[0]]=new Date),d(...n))}const h=(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,h(e,t))}function y(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,h(e,s))}function v(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,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},N=e=>x[e];let E,O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(b,N)};function $(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}}function w(){return O}function I(e){E=e}function S(){return E}function k(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function j(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props?.i18nIsDynamicList?C(n):n}function C(e){return Array.isArray(e)?e:[e]}function R(e,t){if(!e)return"";let s="";const i=C(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=R(a,t);s+=`<${i}>${e}</${i}>`}else s+=`<${i}></${i}>`}else if(null===e)d("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 d("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else d("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 L(e,s,i,r,o,a){if(""===s)return[];const c=r.transKeepBasicHtmlNodesFor||[],l=s&&new RegExp(c.map((e=>`<${e}`)).join("|")).test(s);if(!e&&!l&&!a)return[s];const u={};!function e(t){C(t).forEach((t=>{"string"!=typeof t&&(k(t)?e(j(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(u,t))}))}(e);const d=p.parse(`<0>${s}</0>`),f={...u,...o};function g(e,t,s){const i=j(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?.i18nIsDynamicList?i:r}function h(e,s,i,r,o){e.dummy?(e.children=s,i.push(n.cloneElement(e,{key:r},o?void 0:s))):i.push(...n.Children.map([e],(e=>{const i={...e.props};return delete i.i18nIsDynamicList,n.createElement(e.type,t({},i,{key:r,ref:e.ref},o?{}:{children:s}))})))}function m(t,s,o){const u=C(t);return C(s).reduce(((t,s,p)=>{const d=s.children&&s.children[0]&&s.children[0].content&&i.services.interpolator.interpolate(s.children[0].content,f,i.language);if("tag"===s.type){let a=u[parseInt(s.name,10)];1===o.length&&(a||=o[0][s.name]),a||={};const y=0!==Object.keys(s.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:s.attrs},a):a,v=n.isValidElement(y),b=v&&k(s,!0)&&!s.voidElement,x=l&&"object"==typeof y&&y.dummy&&!v,N="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,s.name);if("string"==typeof y){const e=i.services.interpolator.interpolate(y,f,i.language);t.push(e)}else if(k(y)||b){h(y,g(y,s,o),t,p)}else if(x){h(y,m(u,s.children,o),t,p)}else if(Number.isNaN(parseFloat(s.name)))if(N){h(y,g(y,s,o),t,p,s.voidElement)}else if(r.transSupportBasicHtmlNodes&&c.indexOf(s.name)>-1)if(s.voidElement)t.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const e=m(u,s.children,o);t.push(n.createElement(s.name,{key:`${s.name}-${p}`},e))}else if(s.voidElement)t.push(`<${s.name} />`);else{const e=m(u,s.children,o);t.push(`<${s.name}>${e}</${s.name}>`)}else if("object"!=typeof y||v)h(y,d,t,p,1!==s.children.length||!d);else{const e=s.children[0]?d:null;e&&t.push(e)}}else if("text"===s.type){const e=r.transWrapTextNodes,o=a?r.unescape(i.services.interpolator.interpolate(s.content,f,i.language)):i.services.interpolator.interpolate(s.content,f,i.language);e?t.push(n.createElement(e,{key:`${s.name}-${p}`},o)):t.push(o)}return t}),[])}return j(m([{dummy:!0,children:e||[]}],d,C(e||[]))[0])}function T(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:h,...m}=e;const y=d||S();if(!y)return g("You will need to pass in an i18next instance by using i18nextReactModule"),t;const v=f||y.t.bind(y)||(e=>e);o&&(a.context=o);const b={...w(),...y.options&&y.options.react};let x=p||v.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const N=l||R(t,b)||b.transEmptyNodeValue||r,{hashTransKey:E}=b,O=r||(E?E(N):N),$=c?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},I={...a,count:s,...c,...$,defaultValue:N,ns:x},k=L(u||t,O?v(O,I):N,y,b,I,h),j=void 0!==i?i:b.defaultTransParent;return j?n.createElement(j,m,k):k}const P={type:"3rdParty",init(e){$(e.options.react),I(e)}},z=n.createContext();class A{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function B(e){return n=>new Promise((t=>{const s=U();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function U(){const e=S(),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 V=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:r}=n.useContext(z)||{},o=s||i||S();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new A),!o){g("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&&g("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...w(),...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):(g("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a)));function d(){return o.getFixedT(t.lng||null,"fallback"===a.nsMode?u:u[0],l)}const[f,h]=n.useState(d);let v=u.join();t.lng&&(v=`${t.lng}${v}`);const b=V(v),x=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){x.current&&h(d)}return x.current=!0,p||c||(t.lng?y(o,t.lng,u,(()=>{x.current&&h(d)})):m(o,u,(()=>{x.current&&h(d)}))),p&&b&&b!==v&&x.current&&h(d),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{x.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,v]);const N=n.useRef(!0);n.useEffect((()=>{x.current&&!N.current&&h(d),N.current=!1}),[o,l]);const E=[f,o,p];if(E.t=f,E.i18n=o,E.ready=p,p)return E;if(!p&&!c)return E;throw new Promise((e=>{t.lng?y(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(z)||{},o=i||r||S();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=z,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(z.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,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(z)||{},v=d||m||S(),b=f||v&&v.t.bind(v);return T({children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a,values:c,defaults:l,components:u,ns:p||b&&b.ns||y||v&&v.options&&v.options.defaultNS,i18n:v,t:f,shouldUnescape:g,...h})},e.TransWithoutContext=T,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,r,o]=F(n,s);return t(i,{i18n:r,lng:r.language},o)},e.composeInitialProps=B,e.date=()=>"",e.getDefaults=w,e.getI18n=S,e.getInitialProps=U,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=$,e.setI18n=I,e.time=()=>"",e.useSSR=K,e.useTranslation=F,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=B(e),t.displayName=`withI18nextSSR(${v(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]=F(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(${v(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(){return t=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},t.apply(this,arguments)}function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r=s({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 o(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(r[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var s=e.indexOf("--\x3e");return{type:"comment",comment:-1!==s?e.slice(4,s):""}}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 a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,c=/^\s*$/,l=Object.create(null);function u(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(u,"")+"</"+n.name+">";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var p={parse:function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],i=-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(a,(function(a,l){if(u){if(a!=="</"+t.name+">")return;u=!1}var p,d="/"!==a.charAt(1),f=a.startsWith("\x3c!--"),g=l+a.length,h=e.charAt(g);if(f){var m=o(a);return i<0?(s.push(m),s):((p=r[i]).children.push(m),s)}if(d&&(i++,"tag"===(t=o(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===i&&s.push(t),(p=r[i-1])&&p.children.push(t),r[i]=t),(!d||t.voidElement)&&(i>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(i--,t=-1===i?s:r[i]),!u&&"<"!==h&&h)){p=-1===i?s:r[i].children;var y=e.indexOf("<",g),v=e.slice(g,-1===y?void 0:y);c.test(v)&&(v=" "),(y>-1&&i+p.length>=0||" "!==v)&&p.push({type:"text",content:v})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+u("",n)}),"")}};function d(){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 f={};function g(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&f[n[0]]||("string"==typeof n[0]&&(f[n[0]]=new Date),d(...n))}const h=(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,h(e,t))}function y(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,h(e,s))}function v(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,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},N=e=>x[e];let E,O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(b,N)};function $(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}}function w(){return O}function I(e){E=e}function S(){return E}function k(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function j(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?C(n):n}function C(e){return Array.isArray(e)?e:[e]}function R(e,t){if(!e)return"";let s="";const r=C(e),i=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return r.forEach(((e,r)=>{if("string"==typeof e)s+=`${e}`;else if(n.isValidElement(e)){const n=Object.keys(e.props).length,o=i.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+=`<${r}></${r}>`;else if(o&&1===n&&"string"==typeof a)s+=`<${e.type}>${a}</${e.type}>`;else{const e=R(a,t);s+=`<${r}>${e}</${r}>`}else s+=`<${r}></${r}>`}else if(null===e)d("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"==typeof e){const{format:n,...t}=e,r=Object.keys(t);if(1===r.length){const e=n?`${r[0]}, ${n}`:r[0];s+=`{{${e}}}`}else d("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else d("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 L(e,s,r,i,o,a){if(""===s)return[];const c=i.transKeepBasicHtmlNodesFor||[],l=s&&new RegExp(c.map((e=>`<${e}`)).join("|")).test(s);if(!e&&!l&&!a)return[s];const u={};!function e(t){C(t).forEach((t=>{"string"!=typeof t&&(k(t)?e(j(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(u,t))}))}(e);const d=p.parse(`<0>${s}</0>`),f={...u,...o};function g(e,t,s){const r=j(e),i=m(r,t.children,s);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((e=>n.isValidElement(e)))}(r)&&0===i.length||e.props&&e.props.i18nIsDynamicList?r:i}function h(e,s,r,i,o){e.dummy?(e.children=s,r.push(n.cloneElement(e,{key:i},o?void 0:s))):r.push(...n.Children.map([e],(e=>{const r={...e.props};return delete r.i18nIsDynamicList,n.createElement(e.type,t({},r,{key:i,ref:e.ref},o?{}:{children:s}))})))}function m(t,s,o){const u=C(t);return C(s).reduce(((t,s,p)=>{const d=s.children&&s.children[0]&&s.children[0].content&&r.services.interpolator.interpolate(s.children[0].content,f,r.language);if("tag"===s.type){let a=u[parseInt(s.name,10)];1!==o.length||a||(a=o[0][s.name]),a||(a={});const y=0!==Object.keys(s.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:s.attrs},a):a,v=n.isValidElement(y),b=v&&k(s,!0)&&!s.voidElement,x=l&&"object"==typeof y&&y.dummy&&!v,N="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,s.name);if("string"==typeof y){const e=r.services.interpolator.interpolate(y,f,r.language);t.push(e)}else if(k(y)||b){h(y,g(y,s,o),t,p)}else if(x){h(y,m(u,s.children,o),t,p)}else if(Number.isNaN(parseFloat(s.name)))if(N){h(y,g(y,s,o),t,p,s.voidElement)}else if(i.transSupportBasicHtmlNodes&&c.indexOf(s.name)>-1)if(s.voidElement)t.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const e=m(u,s.children,o);t.push(n.createElement(s.name,{key:`${s.name}-${p}`},e))}else if(s.voidElement)t.push(`<${s.name} />`);else{const e=m(u,s.children,o);t.push(`<${s.name}>${e}</${s.name}>`)}else if("object"!=typeof y||v)h(y,d,t,p,1!==s.children.length||!d);else{const e=s.children[0]?d:null;e&&t.push(e)}}else if("text"===s.type){const e=i.transWrapTextNodes,o=a?i.unescape(r.services.interpolator.interpolate(s.content,f,r.language)):r.services.interpolator.interpolate(s.content,f,r.language);e?t.push(n.createElement(e,{key:`${s.name}-${p}`},o)):t.push(o)}return t}),[])}return j(m([{dummy:!0,children:e||[]}],d,C(e||[]))[0])}function T(e){let{children:t,count:s,parent:r,i18nKey:i,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:d,t:f,shouldUnescape:h,...m}=e;const y=d||S();if(!y)return g("You will need to pass in an i18next instance by using i18nextReactModule"),t;const v=f||y.t.bind(y)||(e=>e);o&&(a.context=o);const b={...w(),...y.options&&y.options.react};let x=p||v.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const N=l||R(t,b)||b.transEmptyNodeValue||i,{hashTransKey:E}=b,O=i||(E?E(N):N),$=c?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},I={...a,count:s,...c,...$,defaultValue:N,ns:x},k=L(u||t,O?v(O,I):N,y,b,I,h),j=void 0!==r?r:b.defaultTransParent;return j?n.createElement(j,m,k):k}const P={type:"3rdParty",init(e){$(e.options.react),I(e)}},z=n.createContext();class A{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function B(e){return n=>new Promise((t=>{const s=U();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function U(){const e=S(),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 V=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:r,defaultNS:i}=n.useContext(z)||{},o=s||r||S();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new A),!o){g("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&&g("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...w(),...o.options.react,...t},{useSuspense:c,keyPrefix:l}=a;let u=e||i||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],r=!!n.options&&n.options.fallbackLng,i=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)||r&&!o(i,e)))}(e,n,t):(g("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a)));function d(){return o.getFixedT(t.lng||null,"fallback"===a.nsMode?u:u[0],l)}const[f,h]=n.useState(d);let v=u.join();t.lng&&(v=`${t.lng}${v}`);const b=V(v),x=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){x.current&&h(d)}return x.current=!0,p||c||(t.lng?y(o,t.lng,u,(()=>{x.current&&h(d)})):m(o,u,(()=>{x.current&&h(d)}))),p&&b&&b!==v&&x.current&&h(d),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{x.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,v]);const N=n.useRef(!0);n.useEffect((()=>{x.current&&!N.current&&h(d),N.current=!1}),[o,l]);const E=[f,o,p];if(E.t=f,E.i18n=o,E.ready=p,p)return E;if(!p&&!c)return E;throw new Promise((e=>{t.lng?y(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:r}=s,{i18n:i}=n.useContext(z)||{},o=r||i||S();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=z,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:r}=e;const i=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(z.Provider,{value:i},r)},e.Trans=function(e){let{children:t,count:s,parent:r,i18nKey:i,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(z)||{},v=d||m||S(),b=f||v&&v.t.bind(v);return T({children:t,count:s,parent:r,i18nKey:i,context:o,tOptions:a,values:c,defaults:l,components:u,ns:p||b&&b.ns||y||v&&v.options&&v.options.defaultNS,i18n:v,t:f,shouldUnescape:g,...h})},e.TransWithoutContext=T,e.Translation=function(e){const{ns:n,children:t,...s}=e,[r,i,o]=F(n,s);return t(r,{i18n:i,lng:i.language},o)},e.composeInitialProps=B,e.date=()=>"",e.getDefaults=w,e.getI18n=S,e.getInitialProps=U,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=$,e.setI18n=I,e.time=()=>"",e.useSSR=K,e.useTranslation=F,e.withSSR=function(){return function(e){function t(t){let{initialI18nStore:s,initialLanguage:r,...i}=t;return K(s,r),n.createElement(e,{...i})}return t.getInitialProps=B(e),t.displayName=`withI18nextSSR(${v(e)})`,t.WrappedComponent=e,t}},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function r(r){let{forwardedRef:i,...o}=r;const[a,c,l]=F(e,{...o,keyPrefix:t.keyPrefix}),u={...o,t:a,i18n:c,tReady:l};return t.withRef&&i?u.ref=i:!t.withRef&&i&&(u.forwardedRef=i),n.createElement(s,u)}r.displayName=`withI18nextTranslation(${v(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}}));
|
|
@@ -23,7 +23,7 @@ function hasChildren(node, checkLength) {
|
|
|
23
23
|
function getChildren(node) {
|
|
24
24
|
if (!node) return [];
|
|
25
25
|
const children = node.props ? node.props.children : node.children;
|
|
26
|
-
return node.props
|
|
26
|
+
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children;
|
|
27
27
|
}
|
|
28
28
|
function hasValidReactChildren(children) {
|
|
29
29
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
@@ -105,7 +105,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
105
105
|
function renderInner(child, node, rootReactNode) {
|
|
106
106
|
const childs = getChildren(child);
|
|
107
107
|
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
108
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props
|
|
108
|
+
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren;
|
|
109
109
|
}
|
|
110
110
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
111
111
|
if (child.dummy) {
|
|
@@ -135,8 +135,8 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
135
135
|
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
136
136
|
if (node.type === 'tag') {
|
|
137
137
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
138
|
-
if (rootReactNode.length === 1) tmp
|
|
139
|
-
tmp
|
|
138
|
+
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
139
|
+
if (!tmp) tmp = {};
|
|
140
140
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
141
141
|
props: node.attrs
|
|
142
142
|
}, tmp) : tmp;
|
|
@@ -13,7 +13,7 @@ function hasChildren(node, checkLength) {
|
|
|
13
13
|
function getChildren(node) {
|
|
14
14
|
if (!node) return [];
|
|
15
15
|
const children = node.props ? node.props.children : node.children;
|
|
16
|
-
return node.props
|
|
16
|
+
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children;
|
|
17
17
|
}
|
|
18
18
|
function hasValidReactChildren(children) {
|
|
19
19
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
@@ -95,7 +95,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
95
95
|
function renderInner(child, node, rootReactNode) {
|
|
96
96
|
const childs = getChildren(child);
|
|
97
97
|
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
98
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props
|
|
98
|
+
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren;
|
|
99
99
|
}
|
|
100
100
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
101
101
|
if (child.dummy) {
|
|
@@ -125,8 +125,8 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
125
125
|
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
126
126
|
if (node.type === 'tag') {
|
|
127
127
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
128
|
-
if (rootReactNode.length === 1) tmp
|
|
129
|
-
tmp
|
|
128
|
+
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
129
|
+
if (!tmp) tmp = {};
|
|
130
130
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
131
131
|
props: node.attrs
|
|
132
132
|
}, tmp) : tmp;
|
package/dist/es/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"13.1.
|
|
1
|
+
{"type":"module","version":"13.1.2"}
|
|
@@ -275,7 +275,7 @@
|
|
|
275
275
|
function getChildren(node) {
|
|
276
276
|
if (!node) return [];
|
|
277
277
|
const children = node.props ? node.props.children : node.children;
|
|
278
|
-
return node.props
|
|
278
|
+
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children;
|
|
279
279
|
}
|
|
280
280
|
function hasValidReactChildren(children) {
|
|
281
281
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
@@ -357,7 +357,7 @@
|
|
|
357
357
|
function renderInner(child, node, rootReactNode) {
|
|
358
358
|
const childs = getChildren(child);
|
|
359
359
|
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
360
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props
|
|
360
|
+
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren;
|
|
361
361
|
}
|
|
362
362
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
363
363
|
if (child.dummy) {
|
|
@@ -387,8 +387,8 @@
|
|
|
387
387
|
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
388
388
|
if (node.type === 'tag') {
|
|
389
389
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
390
|
-
if (rootReactNode.length === 1) tmp
|
|
391
|
-
tmp
|
|
390
|
+
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
391
|
+
if (!tmp) tmp = {};
|
|
392
392
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
393
393
|
props: node.attrs
|
|
394
394
|
}, tmp) : tmp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},t.apply(this,arguments)}function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i=s({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}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function o(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(i[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var s=e.indexOf("--\x3e");return{type:"comment",comment:-1!==s?e.slice(4,s):""}}for(var o=new RegExp(r),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 a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,c=/^\s*$/,l=Object.create(null);function u(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(u,"")+"</"+n.name+">";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var p={parse:function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],r=-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(a,(function(a,l){if(u){if(a!=="</"+t.name+">")return;u=!1}var p,d="/"!==a.charAt(1),f=a.startsWith("\x3c!--"),g=l+a.length,h=e.charAt(g);if(f){var m=o(a);return r<0?(s.push(m),s):((p=i[r]).children.push(m),s)}if(d&&(r++,"tag"===(t=o(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===r&&s.push(t),(p=i[r-1])&&p.children.push(t),i[r]=t),(!d||t.voidElement)&&(r>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(r--,t=-1===r?s:i[r]),!u&&"<"!==h&&h)){p=-1===r?s:i[r].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);c.test(b)&&(b=" "),(y>-1&&r+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+u("",n)}),"")}};function d(){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 f={};function g(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&f[n[0]]||("string"==typeof n[0]&&(f[n[0]]=new Date),d(...n))}const h=(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,h(e,t))}function y(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,h(e,s))}function b(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}const v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},N=e=>x[e];let E,O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,N)};function $(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}}function w(){return O}function I(e){E=e}function S(){return E}function j(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function k(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props?.i18nIsDynamicList?R(n):n}function R(e){return Array.isArray(e)?e:[e]}function C(e,t){if(!e)return"";let s="";const i=R(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)d("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 d("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else d("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 T(e,s,i,r,o,a){if(""===s)return[];const c=r.transKeepBasicHtmlNodesFor||[],l=s&&new RegExp(c.map((e=>`<${e}`)).join("|")).test(s);if(!e&&!l&&!a)return[s];const u={};!function e(t){R(t).forEach((t=>{"string"!=typeof t&&(j(t)?e(k(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(u,t))}))}(e);const d=p.parse(`<0>${s}</0>`),f={...u,...o};function g(e,t,s){const i=k(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?.i18nIsDynamicList?i:r}function h(e,s,i,r,o){e.dummy?(e.children=s,i.push(n.cloneElement(e,{key:r},o?void 0:s))):i.push(...n.Children.map([e],(e=>{const i={...e.props};return delete i.i18nIsDynamicList,n.createElement(e.type,t({},i,{key:r,ref:e.ref},o?{}:{children:s}))})))}function m(t,s,o){const u=R(t);return R(s).reduce(((t,s,p)=>{const d=s.children&&s.children[0]&&s.children[0].content&&i.services.interpolator.interpolate(s.children[0].content,f,i.language);if("tag"===s.type){let a=u[parseInt(s.name,10)];1===o.length&&(a||=o[0][s.name]),a||={};const y=0!==Object.keys(s.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:s.attrs},a):a,b=n.isValidElement(y),v=b&&j(s,!0)&&!s.voidElement,x=l&&"object"==typeof y&&y.dummy&&!b,N="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,s.name);if("string"==typeof y){const e=i.services.interpolator.interpolate(y,f,i.language);t.push(e)}else if(j(y)||v){h(y,g(y,s,o),t,p)}else if(x){h(y,m(u,s.children,o),t,p)}else if(Number.isNaN(parseFloat(s.name)))if(N){h(y,g(y,s,o),t,p,s.voidElement)}else if(r.transSupportBasicHtmlNodes&&c.indexOf(s.name)>-1)if(s.voidElement)t.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const e=m(u,s.children,o);t.push(n.createElement(s.name,{key:`${s.name}-${p}`},e))}else if(s.voidElement)t.push(`<${s.name} />`);else{const e=m(u,s.children,o);t.push(`<${s.name}>${e}</${s.name}>`)}else if("object"!=typeof y||b)h(y,d,t,p,1!==s.children.length||!d);else{const e=s.children[0]?d:null;e&&t.push(e)}}else if("text"===s.type){const e=r.transWrapTextNodes,o=a?r.unescape(i.services.interpolator.interpolate(s.content,f,i.language)):i.services.interpolator.interpolate(s.content,f,i.language);e?t.push(n.createElement(e,{key:`${s.name}-${p}`},o)):t.push(o)}return t}),[])}return k(m([{dummy:!0,children:e||[]}],d,R(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:f,shouldUnescape:h,...m}=e;const y=d||S();if(!y)return g("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=f||y.t.bind(y)||(e=>e);o&&(a.context=o);const v={...w(),...y.options&&y.options.react};let x=p||b.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const N=l||C(t,v)||v.transEmptyNodeValue||r,{hashTransKey:E}=v,O=r||(E?E(N):N),$=c?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},I={...a,count:s,...c,...$,defaultValue:N,ns:x},j=T(u||t,O?b(O,I):N,y,v,I,h),k=void 0!==i?i:v.defaultTransParent;return k?n.createElement(k,m,j):j}const P={type:"3rdParty",init(e){$(e.options.react),I(e)}},z=n.createContext();class A{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function B(e){return n=>new Promise((t=>{const s=U();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function U(){const e=S(),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 V=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:r}=n.useContext(z)||{},o=s||i||S();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new A),!o){g("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&&g("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...w(),...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):(g("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a)));function d(){return o.getFixedT(t.lng||null,"fallback"===a.nsMode?u:u[0],l)}const[f,h]=n.useState(d);let b=u.join();t.lng&&(b=`${t.lng}${b}`);const v=V(b),x=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){x.current&&h(d)}return x.current=!0,p||c||(t.lng?y(o,t.lng,u,(()=>{x.current&&h(d)})):m(o,u,(()=>{x.current&&h(d)}))),p&&v&&v!==b&&x.current&&h(d),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{x.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,b]);const N=n.useRef(!0);n.useEffect((()=>{x.current&&!N.current&&h(d),N.current=!1}),[o,l]);const E=[f,o,p];if(E.t=f,E.i18n=o,E.ready=p,p)return E;if(!p&&!c)return E;throw new Promise((e=>{t.lng?y(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(z)||{},o=i||r||S();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=z,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(z.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,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(z)||{},b=d||m||S(),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,...h})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,r,o]=F(n,s);return t(i,{i18n:r,lng:r.language},o)},e.composeInitialProps=B,e.date=()=>"",e.getDefaults=w,e.getI18n=S,e.getInitialProps=U,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=$,e.setI18n=I,e.time=()=>"",e.useSSR=K,e.useTranslation=F,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=B(e),t.displayName=`withI18nextSSR(${b(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]=F(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(${b(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}}));
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},t.apply(this,arguments)}function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i=s({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}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function o(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(i[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var s=e.indexOf("--\x3e");return{type:"comment",comment:-1!==s?e.slice(4,s):""}}for(var o=new RegExp(r),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 a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,c=/^\s*$/,l=Object.create(null);function u(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(u,"")+"</"+n.name+">";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var p={parse:function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],r=-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(a,(function(a,l){if(u){if(a!=="</"+t.name+">")return;u=!1}var p,d="/"!==a.charAt(1),f=a.startsWith("\x3c!--"),g=l+a.length,h=e.charAt(g);if(f){var m=o(a);return r<0?(s.push(m),s):((p=i[r]).children.push(m),s)}if(d&&(r++,"tag"===(t=o(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===r&&s.push(t),(p=i[r-1])&&p.children.push(t),i[r]=t),(!d||t.voidElement)&&(r>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(r--,t=-1===r?s:i[r]),!u&&"<"!==h&&h)){p=-1===r?s:i[r].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);c.test(b)&&(b=" "),(y>-1&&r+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+u("",n)}),"")}};function d(){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 f={};function g(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&f[n[0]]||("string"==typeof n[0]&&(f[n[0]]=new Date),d(...n))}const h=(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,h(e,t))}function y(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,h(e,s))}function b(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}const v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},N=e=>x[e];let E,O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,N)};function $(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}}function w(){return O}function I(e){E=e}function S(){return E}function j(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function k(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?R(n):n}function R(e){return Array.isArray(e)?e:[e]}function C(e,t){if(!e)return"";let s="";const i=R(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)d("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 d("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else d("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 T(e,s,i,r,o,a){if(""===s)return[];const c=r.transKeepBasicHtmlNodesFor||[],l=s&&new RegExp(c.map((e=>`<${e}`)).join("|")).test(s);if(!e&&!l&&!a)return[s];const u={};!function e(t){R(t).forEach((t=>{"string"!=typeof t&&(j(t)?e(k(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(u,t))}))}(e);const d=p.parse(`<0>${s}</0>`),f={...u,...o};function g(e,t,s){const i=k(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 h(e,s,i,r,o){e.dummy?(e.children=s,i.push(n.cloneElement(e,{key:r},o?void 0:s))):i.push(...n.Children.map([e],(e=>{const i={...e.props};return delete i.i18nIsDynamicList,n.createElement(e.type,t({},i,{key:r,ref:e.ref},o?{}:{children:s}))})))}function m(t,s,o){const u=R(t);return R(s).reduce(((t,s,p)=>{const d=s.children&&s.children[0]&&s.children[0].content&&i.services.interpolator.interpolate(s.children[0].content,f,i.language);if("tag"===s.type){let a=u[parseInt(s.name,10)];1!==o.length||a||(a=o[0][s.name]),a||(a={});const y=0!==Object.keys(s.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:s.attrs},a):a,b=n.isValidElement(y),v=b&&j(s,!0)&&!s.voidElement,x=l&&"object"==typeof y&&y.dummy&&!b,N="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,s.name);if("string"==typeof y){const e=i.services.interpolator.interpolate(y,f,i.language);t.push(e)}else if(j(y)||v){h(y,g(y,s,o),t,p)}else if(x){h(y,m(u,s.children,o),t,p)}else if(Number.isNaN(parseFloat(s.name)))if(N){h(y,g(y,s,o),t,p,s.voidElement)}else if(r.transSupportBasicHtmlNodes&&c.indexOf(s.name)>-1)if(s.voidElement)t.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const e=m(u,s.children,o);t.push(n.createElement(s.name,{key:`${s.name}-${p}`},e))}else if(s.voidElement)t.push(`<${s.name} />`);else{const e=m(u,s.children,o);t.push(`<${s.name}>${e}</${s.name}>`)}else if("object"!=typeof y||b)h(y,d,t,p,1!==s.children.length||!d);else{const e=s.children[0]?d:null;e&&t.push(e)}}else if("text"===s.type){const e=r.transWrapTextNodes,o=a?r.unescape(i.services.interpolator.interpolate(s.content,f,i.language)):i.services.interpolator.interpolate(s.content,f,i.language);e?t.push(n.createElement(e,{key:`${s.name}-${p}`},o)):t.push(o)}return t}),[])}return k(m([{dummy:!0,children:e||[]}],d,R(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:f,shouldUnescape:h,...m}=e;const y=d||S();if(!y)return g("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=f||y.t.bind(y)||(e=>e);o&&(a.context=o);const v={...w(),...y.options&&y.options.react};let x=p||b.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const N=l||C(t,v)||v.transEmptyNodeValue||r,{hashTransKey:E}=v,O=r||(E?E(N):N),$=c?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},I={...a,count:s,...c,...$,defaultValue:N,ns:x},j=T(u||t,O?b(O,I):N,y,v,I,h),k=void 0!==i?i:v.defaultTransParent;return k?n.createElement(k,m,j):j}const P={type:"3rdParty",init(e){$(e.options.react),I(e)}},z=n.createContext();class A{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function B(e){return n=>new Promise((t=>{const s=U();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function U(){const e=S(),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 V=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:r}=n.useContext(z)||{},o=s||i||S();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new A),!o){g("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&&g("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...w(),...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):(g("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a)));function d(){return o.getFixedT(t.lng||null,"fallback"===a.nsMode?u:u[0],l)}const[f,h]=n.useState(d);let b=u.join();t.lng&&(b=`${t.lng}${b}`);const v=V(b),x=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){x.current&&h(d)}return x.current=!0,p||c||(t.lng?y(o,t.lng,u,(()=>{x.current&&h(d)})):m(o,u,(()=>{x.current&&h(d)}))),p&&v&&v!==b&&x.current&&h(d),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{x.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,b]);const N=n.useRef(!0);n.useEffect((()=>{x.current&&!N.current&&h(d),N.current=!1}),[o,l]);const E=[f,o,p];if(E.t=f,E.i18n=o,E.ready=p,p)return E;if(!p&&!c)return E;throw new Promise((e=>{t.lng?y(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(z)||{},o=i||r||S();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=z,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(z.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,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(z)||{},b=d||m||S(),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,...h})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,r,o]=F(n,s);return t(i,{i18n:r,lng:r.language},o)},e.composeInitialProps=B,e.date=()=>"",e.getDefaults=w,e.getI18n=S,e.getInitialProps=U,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=$,e.setI18n=I,e.time=()=>"",e.useSSR=K,e.useTranslation=F,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=B(e),t.displayName=`withI18nextSSR(${b(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]=F(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(${b(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}}));
|
package/package.json
CHANGED
package/react-i18next.js
CHANGED
|
@@ -275,7 +275,7 @@
|
|
|
275
275
|
function getChildren(node) {
|
|
276
276
|
if (!node) return [];
|
|
277
277
|
const children = node.props ? node.props.children : node.children;
|
|
278
|
-
return node.props
|
|
278
|
+
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children;
|
|
279
279
|
}
|
|
280
280
|
function hasValidReactChildren(children) {
|
|
281
281
|
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
@@ -357,7 +357,7 @@
|
|
|
357
357
|
function renderInner(child, node, rootReactNode) {
|
|
358
358
|
const childs = getChildren(child);
|
|
359
359
|
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
360
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props
|
|
360
|
+
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren;
|
|
361
361
|
}
|
|
362
362
|
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
363
363
|
if (child.dummy) {
|
|
@@ -387,8 +387,8 @@
|
|
|
387
387
|
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
388
388
|
if (node.type === 'tag') {
|
|
389
389
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
390
|
-
if (rootReactNode.length === 1) tmp
|
|
391
|
-
tmp
|
|
390
|
+
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
391
|
+
if (!tmp) tmp = {};
|
|
392
392
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
393
393
|
props: node.attrs
|
|
394
394
|
}, tmp) : tmp;
|
package/react-i18next.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},t.apply(this,arguments)}function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i=s({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}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function o(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(i[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var s=e.indexOf("--\x3e");return{type:"comment",comment:-1!==s?e.slice(4,s):""}}for(var o=new RegExp(r),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 a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,c=/^\s*$/,l=Object.create(null);function u(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(u,"")+"</"+n.name+">";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var p={parse:function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],r=-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(a,(function(a,l){if(u){if(a!=="</"+t.name+">")return;u=!1}var p,d="/"!==a.charAt(1),f=a.startsWith("\x3c!--"),g=l+a.length,h=e.charAt(g);if(f){var m=o(a);return r<0?(s.push(m),s):((p=i[r]).children.push(m),s)}if(d&&(r++,"tag"===(t=o(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===r&&s.push(t),(p=i[r-1])&&p.children.push(t),i[r]=t),(!d||t.voidElement)&&(r>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(r--,t=-1===r?s:i[r]),!u&&"<"!==h&&h)){p=-1===r?s:i[r].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);c.test(b)&&(b=" "),(y>-1&&r+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+u("",n)}),"")}};function d(){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 f={};function g(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&f[n[0]]||("string"==typeof n[0]&&(f[n[0]]=new Date),d(...n))}const h=(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,h(e,t))}function y(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,h(e,s))}function b(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}const v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},N=e=>x[e];let E,O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,N)};function $(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}}function w(){return O}function I(e){E=e}function S(){return E}function j(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function k(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props?.i18nIsDynamicList?R(n):n}function R(e){return Array.isArray(e)?e:[e]}function C(e,t){if(!e)return"";let s="";const i=R(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)d("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 d("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else d("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 T(e,s,i,r,o,a){if(""===s)return[];const c=r.transKeepBasicHtmlNodesFor||[],l=s&&new RegExp(c.map((e=>`<${e}`)).join("|")).test(s);if(!e&&!l&&!a)return[s];const u={};!function e(t){R(t).forEach((t=>{"string"!=typeof t&&(j(t)?e(k(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(u,t))}))}(e);const d=p.parse(`<0>${s}</0>`),f={...u,...o};function g(e,t,s){const i=k(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?.i18nIsDynamicList?i:r}function h(e,s,i,r,o){e.dummy?(e.children=s,i.push(n.cloneElement(e,{key:r},o?void 0:s))):i.push(...n.Children.map([e],(e=>{const i={...e.props};return delete i.i18nIsDynamicList,n.createElement(e.type,t({},i,{key:r,ref:e.ref},o?{}:{children:s}))})))}function m(t,s,o){const u=R(t);return R(s).reduce(((t,s,p)=>{const d=s.children&&s.children[0]&&s.children[0].content&&i.services.interpolator.interpolate(s.children[0].content,f,i.language);if("tag"===s.type){let a=u[parseInt(s.name,10)];1===o.length&&(a||=o[0][s.name]),a||={};const y=0!==Object.keys(s.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:s.attrs},a):a,b=n.isValidElement(y),v=b&&j(s,!0)&&!s.voidElement,x=l&&"object"==typeof y&&y.dummy&&!b,N="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,s.name);if("string"==typeof y){const e=i.services.interpolator.interpolate(y,f,i.language);t.push(e)}else if(j(y)||v){h(y,g(y,s,o),t,p)}else if(x){h(y,m(u,s.children,o),t,p)}else if(Number.isNaN(parseFloat(s.name)))if(N){h(y,g(y,s,o),t,p,s.voidElement)}else if(r.transSupportBasicHtmlNodes&&c.indexOf(s.name)>-1)if(s.voidElement)t.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const e=m(u,s.children,o);t.push(n.createElement(s.name,{key:`${s.name}-${p}`},e))}else if(s.voidElement)t.push(`<${s.name} />`);else{const e=m(u,s.children,o);t.push(`<${s.name}>${e}</${s.name}>`)}else if("object"!=typeof y||b)h(y,d,t,p,1!==s.children.length||!d);else{const e=s.children[0]?d:null;e&&t.push(e)}}else if("text"===s.type){const e=r.transWrapTextNodes,o=a?r.unescape(i.services.interpolator.interpolate(s.content,f,i.language)):i.services.interpolator.interpolate(s.content,f,i.language);e?t.push(n.createElement(e,{key:`${s.name}-${p}`},o)):t.push(o)}return t}),[])}return k(m([{dummy:!0,children:e||[]}],d,R(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:f,shouldUnescape:h,...m}=e;const y=d||S();if(!y)return g("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=f||y.t.bind(y)||(e=>e);o&&(a.context=o);const v={...w(),...y.options&&y.options.react};let x=p||b.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const N=l||C(t,v)||v.transEmptyNodeValue||r,{hashTransKey:E}=v,O=r||(E?E(N):N),$=c?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},I={...a,count:s,...c,...$,defaultValue:N,ns:x},j=T(u||t,O?b(O,I):N,y,v,I,h),k=void 0!==i?i:v.defaultTransParent;return k?n.createElement(k,m,j):j}const P={type:"3rdParty",init(e){$(e.options.react),I(e)}},z=n.createContext();class A{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function B(e){return n=>new Promise((t=>{const s=U();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function U(){const e=S(),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 V=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:r}=n.useContext(z)||{},o=s||i||S();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new A),!o){g("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&&g("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...w(),...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):(g("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a)));function d(){return o.getFixedT(t.lng||null,"fallback"===a.nsMode?u:u[0],l)}const[f,h]=n.useState(d);let b=u.join();t.lng&&(b=`${t.lng}${b}`);const v=V(b),x=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){x.current&&h(d)}return x.current=!0,p||c||(t.lng?y(o,t.lng,u,(()=>{x.current&&h(d)})):m(o,u,(()=>{x.current&&h(d)}))),p&&v&&v!==b&&x.current&&h(d),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{x.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,b]);const N=n.useRef(!0);n.useEffect((()=>{x.current&&!N.current&&h(d),N.current=!1}),[o,l]);const E=[f,o,p];if(E.t=f,E.i18n=o,E.ready=p,p)return E;if(!p&&!c)return E;throw new Promise((e=>{t.lng?y(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(z)||{},o=i||r||S();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=z,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(z.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,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(z)||{},b=d||m||S(),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,...h})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,r,o]=F(n,s);return t(i,{i18n:r,lng:r.language},o)},e.composeInitialProps=B,e.date=()=>"",e.getDefaults=w,e.getI18n=S,e.getInitialProps=U,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=$,e.setI18n=I,e.time=()=>"",e.useSSR=K,e.useTranslation=F,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=B(e),t.displayName=`withI18nextSSR(${b(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]=F(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(${b(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}}));
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},t.apply(this,arguments)}function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i=s({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}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function o(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(i[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var s=e.indexOf("--\x3e");return{type:"comment",comment:-1!==s?e.slice(4,s):""}}for(var o=new RegExp(r),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 a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,c=/^\s*$/,l=Object.create(null);function u(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(u,"")+"</"+n.name+">";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var p={parse:function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],r=-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(a,(function(a,l){if(u){if(a!=="</"+t.name+">")return;u=!1}var p,d="/"!==a.charAt(1),f=a.startsWith("\x3c!--"),g=l+a.length,h=e.charAt(g);if(f){var m=o(a);return r<0?(s.push(m),s):((p=i[r]).children.push(m),s)}if(d&&(r++,"tag"===(t=o(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===r&&s.push(t),(p=i[r-1])&&p.children.push(t),i[r]=t),(!d||t.voidElement)&&(r>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(r--,t=-1===r?s:i[r]),!u&&"<"!==h&&h)){p=-1===r?s:i[r].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);c.test(b)&&(b=" "),(y>-1&&r+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+u("",n)}),"")}};function d(){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 f={};function g(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&f[n[0]]||("string"==typeof n[0]&&(f[n[0]]=new Date),d(...n))}const h=(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,h(e,t))}function y(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,h(e,s))}function b(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}const v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},N=e=>x[e];let E,O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,N)};function $(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}}function w(){return O}function I(e){E=e}function S(){return E}function j(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function k(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?R(n):n}function R(e){return Array.isArray(e)?e:[e]}function C(e,t){if(!e)return"";let s="";const i=R(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)d("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 d("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else d("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 T(e,s,i,r,o,a){if(""===s)return[];const c=r.transKeepBasicHtmlNodesFor||[],l=s&&new RegExp(c.map((e=>`<${e}`)).join("|")).test(s);if(!e&&!l&&!a)return[s];const u={};!function e(t){R(t).forEach((t=>{"string"!=typeof t&&(j(t)?e(k(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(u,t))}))}(e);const d=p.parse(`<0>${s}</0>`),f={...u,...o};function g(e,t,s){const i=k(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 h(e,s,i,r,o){e.dummy?(e.children=s,i.push(n.cloneElement(e,{key:r},o?void 0:s))):i.push(...n.Children.map([e],(e=>{const i={...e.props};return delete i.i18nIsDynamicList,n.createElement(e.type,t({},i,{key:r,ref:e.ref},o?{}:{children:s}))})))}function m(t,s,o){const u=R(t);return R(s).reduce(((t,s,p)=>{const d=s.children&&s.children[0]&&s.children[0].content&&i.services.interpolator.interpolate(s.children[0].content,f,i.language);if("tag"===s.type){let a=u[parseInt(s.name,10)];1!==o.length||a||(a=o[0][s.name]),a||(a={});const y=0!==Object.keys(s.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:s.attrs},a):a,b=n.isValidElement(y),v=b&&j(s,!0)&&!s.voidElement,x=l&&"object"==typeof y&&y.dummy&&!b,N="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,s.name);if("string"==typeof y){const e=i.services.interpolator.interpolate(y,f,i.language);t.push(e)}else if(j(y)||v){h(y,g(y,s,o),t,p)}else if(x){h(y,m(u,s.children,o),t,p)}else if(Number.isNaN(parseFloat(s.name)))if(N){h(y,g(y,s,o),t,p,s.voidElement)}else if(r.transSupportBasicHtmlNodes&&c.indexOf(s.name)>-1)if(s.voidElement)t.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const e=m(u,s.children,o);t.push(n.createElement(s.name,{key:`${s.name}-${p}`},e))}else if(s.voidElement)t.push(`<${s.name} />`);else{const e=m(u,s.children,o);t.push(`<${s.name}>${e}</${s.name}>`)}else if("object"!=typeof y||b)h(y,d,t,p,1!==s.children.length||!d);else{const e=s.children[0]?d:null;e&&t.push(e)}}else if("text"===s.type){const e=r.transWrapTextNodes,o=a?r.unescape(i.services.interpolator.interpolate(s.content,f,i.language)):i.services.interpolator.interpolate(s.content,f,i.language);e?t.push(n.createElement(e,{key:`${s.name}-${p}`},o)):t.push(o)}return t}),[])}return k(m([{dummy:!0,children:e||[]}],d,R(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:f,shouldUnescape:h,...m}=e;const y=d||S();if(!y)return g("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=f||y.t.bind(y)||(e=>e);o&&(a.context=o);const v={...w(),...y.options&&y.options.react};let x=p||b.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const N=l||C(t,v)||v.transEmptyNodeValue||r,{hashTransKey:E}=v,O=r||(E?E(N):N),$=c?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},I={...a,count:s,...c,...$,defaultValue:N,ns:x},j=T(u||t,O?b(O,I):N,y,v,I,h),k=void 0!==i?i:v.defaultTransParent;return k?n.createElement(k,m,j):j}const P={type:"3rdParty",init(e){$(e.options.react),I(e)}},z=n.createContext();class A{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function B(e){return n=>new Promise((t=>{const s=U();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function U(){const e=S(),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 V=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:r}=n.useContext(z)||{},o=s||i||S();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new A),!o){g("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&&g("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...w(),...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):(g("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a)));function d(){return o.getFixedT(t.lng||null,"fallback"===a.nsMode?u:u[0],l)}const[f,h]=n.useState(d);let b=u.join();t.lng&&(b=`${t.lng}${b}`);const v=V(b),x=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){x.current&&h(d)}return x.current=!0,p||c||(t.lng?y(o,t.lng,u,(()=>{x.current&&h(d)})):m(o,u,(()=>{x.current&&h(d)}))),p&&v&&v!==b&&x.current&&h(d),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{x.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,b]);const N=n.useRef(!0);n.useEffect((()=>{x.current&&!N.current&&h(d),N.current=!1}),[o,l]);const E=[f,o,p];if(E.t=f,E.i18n=o,E.ready=p,p)return E;if(!p&&!c)return E;throw new Promise((e=>{t.lng?y(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(z)||{},o=i||r||S();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=z,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(z.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,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(z)||{},b=d||m||S(),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,...h})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,r,o]=F(n,s);return t(i,{i18n:r,lng:r.language},o)},e.composeInitialProps=B,e.date=()=>"",e.getDefaults=w,e.getI18n=S,e.getInitialProps=U,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=$,e.setI18n=I,e.time=()=>"",e.useSSR=K,e.useTranslation=F,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=B(e),t.displayName=`withI18nextSSR(${b(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]=F(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(${b(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}}));
|
|
@@ -14,7 +14,7 @@ function hasChildren(node, checkLength) {
|
|
|
14
14
|
function getChildren(node) {
|
|
15
15
|
if (!node) return [];
|
|
16
16
|
const children = node.props ? node.props.children : node.children;
|
|
17
|
-
return node.props
|
|
17
|
+
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function hasValidReactChildren(children) {
|
|
@@ -142,7 +142,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
142
142
|
// `mappedChildren` will always be empty if using the `i18nIsDynamicList` prop,
|
|
143
143
|
// but the children might not necessarily be react components
|
|
144
144
|
return (hasValidReactChildren(childs) && mappedChildren.length === 0) ||
|
|
145
|
-
child.props
|
|
145
|
+
(child.props && child.props.i18nIsDynamicList)
|
|
146
146
|
? childs
|
|
147
147
|
: mappedChildren;
|
|
148
148
|
}
|
|
@@ -181,10 +181,10 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
181
181
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
182
182
|
|
|
183
183
|
// trans components is an object
|
|
184
|
-
if (rootReactNode.length === 1) tmp
|
|
184
|
+
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
185
185
|
|
|
186
186
|
// neither
|
|
187
|
-
tmp
|
|
187
|
+
if (!tmp) tmp = {};
|
|
188
188
|
|
|
189
189
|
const child =
|
|
190
190
|
Object.keys(node.attrs).length !== 0 ? mergeProps({ props: node.attrs }, tmp) : tmp;
|