react-i18next 15.5.3 → 15.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/amd/react-i18next.js +22 -10
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/TransWithoutContext.js +17 -5
- package/dist/es/TransWithoutContext.js +17 -5
- package/dist/es/package.json +1 -1
- package/dist/umd/react-i18next.js +22 -10
- package/dist/umd/react-i18next.min.js +1 -1
- package/package.json +28 -28
- package/react-i18next.js +22 -10
- package/react-i18next.min.js +1 -1
- package/src/TransWithoutContext.js +32 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
### 15.6.0
|
|
2
|
+
|
|
3
|
+
fix: passing components as object should still allow for indexed matching of children [1854](https://github.com/i18next/react-i18next/pull/1854)
|
|
4
|
+
|
|
1
5
|
### 15.5.3
|
|
2
6
|
|
|
3
7
|
chore: update `@babel/runtime` [1851](https://github.com/i18next/react-i18next/pull/1851)
|
|
@@ -28,12 +28,12 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
28
28
|
var r = {
|
|
29
29
|
type: "tag",
|
|
30
30
|
name: "",
|
|
31
|
-
voidElement:
|
|
31
|
+
voidElement: false,
|
|
32
32
|
attrs: {},
|
|
33
33
|
children: []
|
|
34
34
|
},
|
|
35
35
|
i = n.match(/<\/?([^\s]+?)[/\s>]/);
|
|
36
|
-
if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement =
|
|
36
|
+
if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = true), r.name.startsWith("!--"))) {
|
|
37
37
|
var s = n.indexOf("--\x3e");
|
|
38
38
|
return {
|
|
39
39
|
type: "comment",
|
|
@@ -71,7 +71,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
71
71
|
c = [],
|
|
72
72
|
o = [],
|
|
73
73
|
l = -1,
|
|
74
|
-
m =
|
|
74
|
+
m = false;
|
|
75
75
|
if (0 !== e.indexOf("<")) {
|
|
76
76
|
var u = e.indexOf("<");
|
|
77
77
|
c.push({
|
|
@@ -82,7 +82,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
82
82
|
return e.replace(r, function (r, s) {
|
|
83
83
|
if (m) {
|
|
84
84
|
if (r !== "</" + a.name + ">") return;
|
|
85
|
-
m =
|
|
85
|
+
m = false;
|
|
86
86
|
}
|
|
87
87
|
var u,
|
|
88
88
|
f = "/" !== r.charAt(1),
|
|
@@ -93,7 +93,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
93
93
|
var v = n(r);
|
|
94
94
|
return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
|
|
95
95
|
}
|
|
96
|
-
if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m =
|
|
96
|
+
if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m = true), a.voidElement || m || !d || "<" === d || a.children.push({
|
|
97
97
|
type: "text",
|
|
98
98
|
content: e.slice(p, e.indexOf("<", p))
|
|
99
99
|
}), 0 === l && c.push(a), (u = o[l - 1]) && u.children.push(a), o[l] = a), (!f || a.voidElement) && (l > -1 && (a.voidElement || a.name === r.slice(2, -1)) && (l--, a = -1 === l ? c : o[l]), !m && "<" !== d && d)) {
|
|
@@ -311,12 +311,12 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
311
311
|
});
|
|
312
312
|
return stringNode;
|
|
313
313
|
};
|
|
314
|
-
const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
314
|
+
const renderNodes = (children, knownComponentsMap, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
315
315
|
if (targetString === '') return [];
|
|
316
316
|
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
317
317
|
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
|
|
318
|
-
if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
319
|
-
const data = {};
|
|
318
|
+
if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
319
|
+
const data = knownComponentsMap ?? {};
|
|
320
320
|
const getData = childs => {
|
|
321
321
|
const childrenArray = getAsArray(childs);
|
|
322
322
|
childrenArray.forEach(child => {
|
|
@@ -362,6 +362,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
362
362
|
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
363
363
|
if (node.type === 'tag') {
|
|
364
364
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
365
|
+
if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
|
|
365
366
|
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
366
367
|
if (!tmp) tmp = {};
|
|
367
368
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
@@ -370,7 +371,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
370
371
|
const isElement = react.isValidElement(child);
|
|
371
372
|
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
372
373
|
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
|
|
373
|
-
const isKnownComponent = isObject(
|
|
374
|
+
const isKnownComponent = isObject(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
|
|
374
375
|
if (isString(child)) {
|
|
375
376
|
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
376
377
|
mem.push(value);
|
|
@@ -465,6 +466,11 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
465
466
|
});
|
|
466
467
|
return null;
|
|
467
468
|
};
|
|
469
|
+
const isComponentsMap = object => {
|
|
470
|
+
if (!isObject(object)) return false;
|
|
471
|
+
if (Array.isArray(object)) return false;
|
|
472
|
+
return Object.keys(object).reduce((acc, key) => acc && Number.isNaN(Number.parseFloat(key)), true);
|
|
473
|
+
};
|
|
468
474
|
function Trans$1({
|
|
469
475
|
children,
|
|
470
476
|
count,
|
|
@@ -527,7 +533,13 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
|
527
533
|
};
|
|
528
534
|
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
529
535
|
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
530
|
-
|
|
536
|
+
let indexedChildren = generatedComponents || children;
|
|
537
|
+
let componentsMap = null;
|
|
538
|
+
if (isComponentsMap(generatedComponents)) {
|
|
539
|
+
componentsMap = generatedComponents;
|
|
540
|
+
indexedChildren = children;
|
|
541
|
+
}
|
|
542
|
+
const content = renderNodes(indexedChildren, componentsMap, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
531
543
|
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
|
|
532
544
|
return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
|
|
533
545
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
define(["exports","react"],(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==g&&g)){p=-1===c?s:r[c].children;var y=e.indexOf("<",m),N=e.slice(m,-1===y?void 0:y);o.test(N)&&(N=" "),(y>-1&&c+p.length>=0||" "!==N)&&p.push({type:"text",content:N})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,N=e=>"object"==typeof e&&null!==e,x=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,v={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},E=e=>v[e];let b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(x,E)};const O=(e={})=>{b={...b,...e}},I=()=>b;let S;const w=e=>{S=e},$=()=>S,k=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},T=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?A(n):n},A=e=>Array.isArray(e)?e:[e],R=(e,t,s,r)=>{if(!e)return"";let a="";const i=A(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=R(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(N(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i)=>{if(""===t)return[];const o=r.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!i)return[t];const u={},p=e=>{A(e).forEach((e=>{y(e)||(k(e)?p(T(e)):N(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},m=(e,t,s)=>{const r=T(e),a=h(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},g=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.props.ref??e.ref},a?null:t)})))},h=(t,a,c)=>{const u=A(t);return A(a).reduce(((t,a,p)=>{const d=a.children?.[0]?.content&&s.services.interpolator.interpolate(a.children[0].content,f,s.language);if("tag"===a.type){let i=u[parseInt(a.name,10)];1!==c.length||i||(i=c[0][a.name]),i||(i={});const x=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},i):i,v=n.isValidElement(x),E=v&&k(a,!0)&&!a.voidElement,b=l&&N(x)&&x.dummy&&!v,O=N(e)&&Object.hasOwnProperty.call(e,a.name);if(y(x)){const e=s.services.interpolator.interpolate(x,f,s.language);t.push(e)}else if(k(x)||E){const e=m(x,a,c);g(x,e,t,p)}else if(b){const e=h(u,a.children,c);g(x,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(O){const e=m(x,a,c);g(x,e,t,p,a.voidElement)}else if(r.transSupportBasicHtmlNodes&&o.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=h(u,a.children,c);t.push(n.createElement(a.name,{key:`${a.name}-${p}`},e))}else if(a.voidElement)t.push(`<${a.name} />`);else{const e=h(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(N(x)&&!v){const e=a.children[0]?d:null;e&&t.push(e)}else g(x,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=r.transWrapTextNodes,o=i?r.unescape(s.services.interpolator.interpolate(a.content,f,s.language)):s.services.interpolator.interpolate(a.content,f,s.language);e?t.push(n.createElement(e,{key:`${a.name}-${p}`},o)):t.push(o)}return t}),[])},x=h([{dummy:!0,children:e||[]}],d,A(e||[]));return T(x[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):N(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null;function P({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:f,shouldUnescape:m,...g}){const h=p||$();if(!h)return d(h,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:r}),e;const N=f||h.t.bind(h)||(e=>e),x={...I(),...h.options?.react};let v=u||N.ns||h.options?.defaultNS;v=y(v)?[v]:v||["translation"];const E=R(e,x,h,r),b=l||E||x.transEmptyNodeValue||r,{hashTransKey:O}=x,S=r||(O?O(E||b):E||b);h.options?.interpolation?.defaultVariables&&(o=o&&Object.keys(o).length>0?{...o,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const w=o||void 0!==t&&!h.options?.interpolation?.alwaysFormat||!e?i.interpolation:{interpolation:{...i.interpolation,prefix:"#$?",suffix:"?$#"}},k={...i,context:a||i.context,count:t,...o,...w,defaultValue:b,ns:v},T=S?N(S,k):b,A=L(c,T,h,r),C=j(A||e,T,h,x,k,m),P=s??x.defaultTransParent;return P?n.createElement(P,g,C):C}const V={type:"3rdParty",init(e){O(e.options.react),w(e)}},_=n.createContext();class D{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const K=e=>async n=>({...await(e.getInitialProps?.(n))??{},...z()}),z=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),F=(e,t={})=>{const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(_)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new D),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:N(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>((e,n,t={})=>n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0))(e,i,o))),f=((e,t,s,r)=>n.useCallback(U(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,x=()=>U(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[v,E]=n.useState(h);let b=u.join();t.lng&&(b=`${t.lng}${b}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(b),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{S.current&&E(x)})):m(i,u,(()=>{S.current&&E(x)}))),p&&O&&O!==b&&S.current&&E(x);const s=()=>{S.current&&E(x)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,b]),n.useEffect((()=>{S.current&&p&&E(h)}),[i,c,p]);const w=[v,i,p];if(w.t=v,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const B=(e,t,s={})=>{const{i18n:r}=s,{i18n:a}=n.useContext(_)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=_,e.I18nextProvider=function({i18n:e,defaultNS:t,children:s}){const r=n.useMemo((()=>({i18n:e,defaultNS:t})),[e,t]);return n.createElement(_.Provider,{value:r},s)},e.Trans=function({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:d,shouldUnescape:f,...m}){const{i18n:g,defaultNS:h}=n.useContext(_)||{},y=p||g||$(),N=d||y?.t.bind(y);return P({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i,values:o,defaults:l,components:c,ns:u||N?.ns||h||y?.options?.defaultNS,i18n:y,t:d,shouldUnescape:f,...m})},e.TransWithoutContext=P,e.Translation=({ns:e,children:n,...t})=>{const[s,r,a]=F(e,t);return n(s,{i18n:r,lng:r.language},a)},e.composeInitialProps=K,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=z,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=B,e.useTranslation=F,e.withSSR=()=>function(e){function t({initialI18nStore:t,initialLanguage:s,...r}){return B(t,s),n.createElement(e,{...r})}return t.getInitialProps=K(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=(e,t={})=>function(s){function r({forwardedRef:r,...a}){const[i,o,l]=F(e,{...a,keyPrefix:t.keyPrefix}),c={...a,t:i,i18n:o,tReady:l};return t.withRef&&r?c.ref=r:!t.withRef&&r&&(c.forwardedRef=r),n.createElement(s,c)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}));
|
|
1
|
+
define(["exports","react"],(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==g&&g)){p=-1===c?s:r[c].children;var y=e.indexOf("<",m),N=e.slice(m,-1===y?void 0:y);o.test(N)&&(N=" "),(y>-1&&c+p.length>=0||" "!==N)&&p.push({type:"text",content:N})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,N=e=>"object"==typeof e&&null!==e,x=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},v=e=>b[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(x,v)};const O=(e={})=>{E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,k=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},T=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?A(n):n},A=e=>Array.isArray(e)?e:[e],R=(e,t,s,r)=>{if(!e)return"";let a="";const i=A(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=R(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(N(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i,o)=>{if(""===s)return[];const l=a.transKeepBasicHtmlNodesFor||[],u=s&&new RegExp(l.map((e=>`<${e}`)).join("|")).test(s);if(!(e||t||u||o))return[s];const p=t??{},d=e=>{A(e).forEach((e=>{y(e)||(k(e)?d(T(e)):N(e)&&!n.isValidElement(e)&&Object.assign(p,e))}))};d(e);const f=c(`<0>${s}</0>`),m={...p,...i},g=(e,t,s)=>{const r=T(e),a=x(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},h=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.props.ref??e.ref},a?null:t)})))},x=(e,s,i)=>{const c=A(e);return A(s).reduce(((e,s,p)=>{const d=s.children?.[0]?.content&&r.services.interpolator.interpolate(s.children[0].content,m,r.language);if("tag"===s.type){let o=c[parseInt(s.name,10)];!o&&t&&(o=t[s.name]),1!==i.length||o||(o=i[0][s.name]),o||(o={});const f=0!==Object.keys(s.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:s.attrs},o):o,b=n.isValidElement(f),v=b&&k(s,!0)&&!s.voidElement,E=u&&N(f)&&f.dummy&&!b,O=N(t)&&Object.hasOwnProperty.call(t,s.name);if(y(f)){const n=r.services.interpolator.interpolate(f,m,r.language);e.push(n)}else if(k(f)||v){const n=g(f,s,i);h(f,n,e,p)}else if(E){const n=x(c,s.children,i);h(f,n,e,p)}else if(Number.isNaN(parseFloat(s.name)))if(O){const n=g(f,s,i);h(f,n,e,p,s.voidElement)}else if(a.transSupportBasicHtmlNodes&&l.indexOf(s.name)>-1)if(s.voidElement)e.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const t=x(c,s.children,i);e.push(n.createElement(s.name,{key:`${s.name}-${p}`},t))}else if(s.voidElement)e.push(`<${s.name} />`);else{const n=x(c,s.children,i);e.push(`<${s.name}>${n}</${s.name}>`)}else if(N(f)&&!b){const n=s.children[0]?d:null;n&&e.push(n)}else h(f,d,e,p,1!==s.children.length||!d)}else if("text"===s.type){const t=a.transWrapTextNodes,i=o?a.unescape(r.services.interpolator.interpolate(s.content,m,r.language)):r.services.interpolator.interpolate(s.content,m,r.language);t?e.push(n.createElement(t,{key:`${s.name}-${p}`},i)):e.push(i)}return e}),[])},b=x([{dummy:!0,children:e||[]}],f,A(e||[]));return T(b[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):N(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null,P=e=>!!N(e)&&(!Array.isArray(e)&&Object.keys(e).reduce(((e,n)=>e&&Number.isNaN(Number.parseFloat(n))),!0));function V({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:f,shouldUnescape:m,...g}){const h=p||$();if(!h)return d(h,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:r}),e;const N=f||h.t.bind(h)||(e=>e),x={...I(),...h.options?.react};let b=u||N.ns||h.options?.defaultNS;b=y(b)?[b]:b||["translation"];const v=R(e,x,h,r),E=l||v||x.transEmptyNodeValue||r,{hashTransKey:O}=x,S=r||(O?O(v||E):v||E);h.options?.interpolation?.defaultVariables&&(o=o&&Object.keys(o).length>0?{...o,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const w=o||void 0!==t&&!h.options?.interpolation?.alwaysFormat||!e?i.interpolation:{interpolation:{...i.interpolation,prefix:"#$?",suffix:"?$#"}},k={...i,context:a||i.context,count:t,...o,...w,defaultValue:E,ns:b},T=S?N(S,k):E,A=L(c,T,h,r);let C=A||e,V=null;P(A)&&(V=A,C=e);const _=j(C,V,T,h,x,k,m),D=s??x.defaultTransParent;return D?n.createElement(D,g,_):_}const _={type:"3rdParty",init(e){O(e.options.react),w(e)}},D=n.createContext();class K{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const z=e=>async n=>({...await(e.getInitialProps?.(n))??{},...U()}),U=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const F=(e,n,t,s)=>e.getFixedT(n,t,s),B=(e,t={})=>{const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(D)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new K),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:N(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>((e,n,t={})=>n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0))(e,i,o))),f=((e,t,s,r)=>n.useCallback(F(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,x=()=>F(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,v]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{S.current&&v(x)})):m(i,u,(()=>{S.current&&v(x)}))),p&&O&&O!==E&&S.current&&v(x);const s=()=>{S.current&&v(x)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,E]),n.useEffect((()=>{S.current&&p&&v(h)}),[i,c,p]);const w=[b,i,p];if(w.t=b,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const W=(e,t,s={})=>{const{i18n:r}=s,{i18n:a}=n.useContext(D)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=D,e.I18nextProvider=function({i18n:e,defaultNS:t,children:s}){const r=n.useMemo((()=>({i18n:e,defaultNS:t})),[e,t]);return n.createElement(D.Provider,{value:r},s)},e.Trans=function({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:d,shouldUnescape:f,...m}){const{i18n:g,defaultNS:h}=n.useContext(D)||{},y=p||g||$(),N=d||y?.t.bind(y);return V({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i,values:o,defaults:l,components:c,ns:u||N?.ns||h||y?.options?.defaultNS,i18n:y,t:d,shouldUnescape:f,...m})},e.TransWithoutContext=V,e.Translation=({ns:e,children:n,...t})=>{const[s,r,a]=B(e,t);return n(s,{i18n:r,lng:r.language},a)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=U,e.initReactI18next=_,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=W,e.useTranslation=B,e.withSSR=()=>function(e){function t({initialI18nStore:t,initialLanguage:s,...r}){return W(t,s),n.createElement(e,{...r})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=(e,t={})=>function(s){function r({forwardedRef:r,...a}){const[i,o,l]=B(e,{...a,keyPrefix:t.keyPrefix}),c={...a,t:i,i18n:o,tReady:l};return t.withRef&&r?c.ref=r:!t.withRef&&r&&(c.forwardedRef=r),n.createElement(s,c)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}));
|
|
@@ -96,12 +96,12 @@ const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
|
|
|
96
96
|
return stringNode;
|
|
97
97
|
};
|
|
98
98
|
exports.nodesToString = nodesToString;
|
|
99
|
-
const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
99
|
+
const renderNodes = (children, knownComponentsMap, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
100
100
|
if (targetString === '') return [];
|
|
101
101
|
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
102
102
|
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
|
|
103
|
-
if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
104
|
-
const data = {};
|
|
103
|
+
if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
104
|
+
const data = knownComponentsMap ?? {};
|
|
105
105
|
const getData = childs => {
|
|
106
106
|
const childrenArray = getAsArray(childs);
|
|
107
107
|
childrenArray.forEach(child => {
|
|
@@ -147,6 +147,7 @@ const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
147
147
|
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
148
148
|
if (node.type === 'tag') {
|
|
149
149
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
150
|
+
if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
|
|
150
151
|
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
151
152
|
if (!tmp) tmp = {};
|
|
152
153
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
@@ -155,7 +156,7 @@ const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
155
156
|
const isElement = (0, _react.isValidElement)(child);
|
|
156
157
|
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
157
158
|
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && (0, _utils.isObject)(child) && child.dummy && !isElement;
|
|
158
|
-
const isKnownComponent = (0, _utils.isObject)(
|
|
159
|
+
const isKnownComponent = (0, _utils.isObject)(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
|
|
159
160
|
if ((0, _utils.isString)(child)) {
|
|
160
161
|
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
161
162
|
mem.push(value);
|
|
@@ -250,6 +251,11 @@ const generateComponents = (components, translation, i18n, i18nKey) => {
|
|
|
250
251
|
});
|
|
251
252
|
return null;
|
|
252
253
|
};
|
|
254
|
+
const isComponentsMap = object => {
|
|
255
|
+
if (!(0, _utils.isObject)(object)) return false;
|
|
256
|
+
if (Array.isArray(object)) return false;
|
|
257
|
+
return Object.keys(object).reduce((acc, key) => acc && Number.isNaN(Number.parseFloat(key)), true);
|
|
258
|
+
};
|
|
253
259
|
function Trans({
|
|
254
260
|
children,
|
|
255
261
|
count,
|
|
@@ -312,7 +318,13 @@ function Trans({
|
|
|
312
318
|
};
|
|
313
319
|
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
314
320
|
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
315
|
-
|
|
321
|
+
let indexedChildren = generatedComponents || children;
|
|
322
|
+
let componentsMap = null;
|
|
323
|
+
if (isComponentsMap(generatedComponents)) {
|
|
324
|
+
componentsMap = generatedComponents;
|
|
325
|
+
indexedChildren = children;
|
|
326
|
+
}
|
|
327
|
+
const content = renderNodes(indexedChildren, componentsMap, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
316
328
|
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
|
|
317
329
|
return useAsParent ? (0, _react.createElement)(useAsParent, additionalProps, content) : content;
|
|
318
330
|
}
|
|
@@ -87,12 +87,12 @@ export const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
|
|
|
87
87
|
});
|
|
88
88
|
return stringNode;
|
|
89
89
|
};
|
|
90
|
-
const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
90
|
+
const renderNodes = (children, knownComponentsMap, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
91
91
|
if (targetString === '') return [];
|
|
92
92
|
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
93
93
|
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
|
|
94
|
-
if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
95
|
-
const data = {};
|
|
94
|
+
if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
95
|
+
const data = knownComponentsMap ?? {};
|
|
96
96
|
const getData = childs => {
|
|
97
97
|
const childrenArray = getAsArray(childs);
|
|
98
98
|
childrenArray.forEach(child => {
|
|
@@ -138,6 +138,7 @@ const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
138
138
|
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
139
139
|
if (node.type === 'tag') {
|
|
140
140
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
141
|
+
if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
|
|
141
142
|
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
142
143
|
if (!tmp) tmp = {};
|
|
143
144
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
@@ -146,7 +147,7 @@ const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
146
147
|
const isElement = isValidElement(child);
|
|
147
148
|
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
148
149
|
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
|
|
149
|
-
const isKnownComponent = isObject(
|
|
150
|
+
const isKnownComponent = isObject(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
|
|
150
151
|
if (isString(child)) {
|
|
151
152
|
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
152
153
|
mem.push(value);
|
|
@@ -241,6 +242,11 @@ const generateComponents = (components, translation, i18n, i18nKey) => {
|
|
|
241
242
|
});
|
|
242
243
|
return null;
|
|
243
244
|
};
|
|
245
|
+
const isComponentsMap = object => {
|
|
246
|
+
if (!isObject(object)) return false;
|
|
247
|
+
if (Array.isArray(object)) return false;
|
|
248
|
+
return Object.keys(object).reduce((acc, key) => acc && Number.isNaN(Number.parseFloat(key)), true);
|
|
249
|
+
};
|
|
244
250
|
export function Trans({
|
|
245
251
|
children,
|
|
246
252
|
count,
|
|
@@ -303,7 +309,13 @@ export function Trans({
|
|
|
303
309
|
};
|
|
304
310
|
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
305
311
|
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
306
|
-
|
|
312
|
+
let indexedChildren = generatedComponents || children;
|
|
313
|
+
let componentsMap = null;
|
|
314
|
+
if (isComponentsMap(generatedComponents)) {
|
|
315
|
+
componentsMap = generatedComponents;
|
|
316
|
+
indexedChildren = children;
|
|
317
|
+
}
|
|
318
|
+
const content = renderNodes(indexedChildren, componentsMap, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
307
319
|
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
|
|
308
320
|
return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
|
|
309
321
|
}
|
package/dist/es/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"15.
|
|
1
|
+
{"type":"module","version":"15.6.0"}
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
var r = {
|
|
33
33
|
type: "tag",
|
|
34
34
|
name: "",
|
|
35
|
-
voidElement:
|
|
35
|
+
voidElement: false,
|
|
36
36
|
attrs: {},
|
|
37
37
|
children: []
|
|
38
38
|
},
|
|
39
39
|
i = n.match(/<\/?([^\s]+?)[/\s>]/);
|
|
40
|
-
if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement =
|
|
40
|
+
if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = true), r.name.startsWith("!--"))) {
|
|
41
41
|
var s = n.indexOf("--\x3e");
|
|
42
42
|
return {
|
|
43
43
|
type: "comment",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
c = [],
|
|
76
76
|
o = [],
|
|
77
77
|
l = -1,
|
|
78
|
-
m =
|
|
78
|
+
m = false;
|
|
79
79
|
if (0 !== e.indexOf("<")) {
|
|
80
80
|
var u = e.indexOf("<");
|
|
81
81
|
c.push({
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
return e.replace(r, function (r, s) {
|
|
87
87
|
if (m) {
|
|
88
88
|
if (r !== "</" + a.name + ">") return;
|
|
89
|
-
m =
|
|
89
|
+
m = false;
|
|
90
90
|
}
|
|
91
91
|
var u,
|
|
92
92
|
f = "/" !== r.charAt(1),
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
var v = n(r);
|
|
98
98
|
return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
|
|
99
99
|
}
|
|
100
|
-
if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m =
|
|
100
|
+
if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m = true), a.voidElement || m || !d || "<" === d || a.children.push({
|
|
101
101
|
type: "text",
|
|
102
102
|
content: e.slice(p, e.indexOf("<", p))
|
|
103
103
|
}), 0 === l && c.push(a), (u = o[l - 1]) && u.children.push(a), o[l] = a), (!f || a.voidElement) && (l > -1 && (a.voidElement || a.name === r.slice(2, -1)) && (l--, a = -1 === l ? c : o[l]), !m && "<" !== d && d)) {
|
|
@@ -315,12 +315,12 @@
|
|
|
315
315
|
});
|
|
316
316
|
return stringNode;
|
|
317
317
|
};
|
|
318
|
-
const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
318
|
+
const renderNodes = (children, knownComponentsMap, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
319
319
|
if (targetString === '') return [];
|
|
320
320
|
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
321
321
|
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
|
|
322
|
-
if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
323
|
-
const data = {};
|
|
322
|
+
if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
323
|
+
const data = knownComponentsMap ?? {};
|
|
324
324
|
const getData = childs => {
|
|
325
325
|
const childrenArray = getAsArray(childs);
|
|
326
326
|
childrenArray.forEach(child => {
|
|
@@ -366,6 +366,7 @@
|
|
|
366
366
|
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
367
367
|
if (node.type === 'tag') {
|
|
368
368
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
369
|
+
if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
|
|
369
370
|
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
370
371
|
if (!tmp) tmp = {};
|
|
371
372
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
@@ -374,7 +375,7 @@
|
|
|
374
375
|
const isElement = react.isValidElement(child);
|
|
375
376
|
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
376
377
|
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
|
|
377
|
-
const isKnownComponent = isObject(
|
|
378
|
+
const isKnownComponent = isObject(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
|
|
378
379
|
if (isString(child)) {
|
|
379
380
|
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
380
381
|
mem.push(value);
|
|
@@ -469,6 +470,11 @@
|
|
|
469
470
|
});
|
|
470
471
|
return null;
|
|
471
472
|
};
|
|
473
|
+
const isComponentsMap = object => {
|
|
474
|
+
if (!isObject(object)) return false;
|
|
475
|
+
if (Array.isArray(object)) return false;
|
|
476
|
+
return Object.keys(object).reduce((acc, key) => acc && Number.isNaN(Number.parseFloat(key)), true);
|
|
477
|
+
};
|
|
472
478
|
function Trans$1({
|
|
473
479
|
children,
|
|
474
480
|
count,
|
|
@@ -531,7 +537,13 @@
|
|
|
531
537
|
};
|
|
532
538
|
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
533
539
|
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
534
|
-
|
|
540
|
+
let indexedChildren = generatedComponents || children;
|
|
541
|
+
let componentsMap = null;
|
|
542
|
+
if (isComponentsMap(generatedComponents)) {
|
|
543
|
+
componentsMap = generatedComponents;
|
|
544
|
+
indexedChildren = children;
|
|
545
|
+
}
|
|
546
|
+
const content = renderNodes(indexedChildren, componentsMap, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
535
547
|
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
|
|
536
548
|
return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
|
|
537
549
|
}
|
|
@@ -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(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==g&&g)){p=-1===c?s:r[c].children;var y=e.indexOf("<",m),x=e.slice(m,-1===y?void 0:y);o.test(x)&&(x=" "),(y>-1&&c+p.length>=0||" "!==x)&&p.push({type:"text",content:x})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,N=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},v=e=>b[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(N,v)};const O=(e={})=>{E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,T=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},k=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],A=(e,t,s,r)=>{if(!e)return"";let a="";const i=R(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=A(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(x(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i)=>{if(""===t)return[];const o=r.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!i)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(T(e)?p(k(e)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},m=(e,t,s)=>{const r=k(e),a=h(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},g=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.props.ref??e.ref},a?null:t)})))},h=(t,a,c)=>{const u=R(t);return R(a).reduce(((t,a,p)=>{const d=a.children?.[0]?.content&&s.services.interpolator.interpolate(a.children[0].content,f,s.language);if("tag"===a.type){let i=u[parseInt(a.name,10)];1!==c.length||i||(i=c[0][a.name]),i||(i={});const N=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},i):i,b=n.isValidElement(N),v=b&&T(a,!0)&&!a.voidElement,E=l&&x(N)&&N.dummy&&!b,O=x(e)&&Object.hasOwnProperty.call(e,a.name);if(y(N)){const e=s.services.interpolator.interpolate(N,f,s.language);t.push(e)}else if(T(N)||v){const e=m(N,a,c);g(N,e,t,p)}else if(E){const e=h(u,a.children,c);g(N,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(O){const e=m(N,a,c);g(N,e,t,p,a.voidElement)}else if(r.transSupportBasicHtmlNodes&&o.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=h(u,a.children,c);t.push(n.createElement(a.name,{key:`${a.name}-${p}`},e))}else if(a.voidElement)t.push(`<${a.name} />`);else{const e=h(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(x(N)&&!b){const e=a.children[0]?d:null;e&&t.push(e)}else g(N,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=r.transWrapTextNodes,o=i?r.unescape(s.services.interpolator.interpolate(a.content,f,s.language)):s.services.interpolator.interpolate(a.content,f,s.language);e?t.push(n.createElement(e,{key:`${a.name}-${p}`},o)):t.push(o)}return t}),[])},N=h([{dummy:!0,children:e||[]}],d,R(e||[]));return k(N[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):x(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null;function P({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:f,shouldUnescape:m,...g}){const h=p||$();if(!h)return d(h,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:r}),e;const x=f||h.t.bind(h)||(e=>e),N={...I(),...h.options?.react};let b=u||x.ns||h.options?.defaultNS;b=y(b)?[b]:b||["translation"];const v=A(e,N,h,r),E=l||v||N.transEmptyNodeValue||r,{hashTransKey:O}=N,S=r||(O?O(v||E):v||E);h.options?.interpolation?.defaultVariables&&(o=o&&Object.keys(o).length>0?{...o,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const w=o||void 0!==t&&!h.options?.interpolation?.alwaysFormat||!e?i.interpolation:{interpolation:{...i.interpolation,prefix:"#$?",suffix:"?$#"}},T={...i,context:a||i.context,count:t,...o,...w,defaultValue:E,ns:b},k=S?x(S,T):E,R=L(c,k,h,r),C=j(R||e,k,h,N,T,m),P=s??N.defaultTransParent;return P?n.createElement(P,g,C):C}const V={type:"3rdParty",init(e){O(e.options.react),w(e)}},_=n.createContext();class D{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const K=e=>async n=>({...await(e.getInitialProps?.(n))??{},...z()}),z=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),F=(e,t={})=>{const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(_)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new D),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:x(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>((e,n,t={})=>n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0))(e,i,o))),f=((e,t,s,r)=>n.useCallback(U(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,N=()=>U(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,v]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{S.current&&v(N)})):m(i,u,(()=>{S.current&&v(N)}))),p&&O&&O!==E&&S.current&&v(N);const s=()=>{S.current&&v(N)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,E]),n.useEffect((()=>{S.current&&p&&v(h)}),[i,c,p]);const w=[b,i,p];if(w.t=b,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const B=(e,t,s={})=>{const{i18n:r}=s,{i18n:a}=n.useContext(_)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=_,e.I18nextProvider=function({i18n:e,defaultNS:t,children:s}){const r=n.useMemo((()=>({i18n:e,defaultNS:t})),[e,t]);return n.createElement(_.Provider,{value:r},s)},e.Trans=function({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:d,shouldUnescape:f,...m}){const{i18n:g,defaultNS:h}=n.useContext(_)||{},y=p||g||$(),x=d||y?.t.bind(y);return P({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i,values:o,defaults:l,components:c,ns:u||x?.ns||h||y?.options?.defaultNS,i18n:y,t:d,shouldUnescape:f,...m})},e.TransWithoutContext=P,e.Translation=({ns:e,children:n,...t})=>{const[s,r,a]=F(e,t);return n(s,{i18n:r,lng:r.language},a)},e.composeInitialProps=K,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=z,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=B,e.useTranslation=F,e.withSSR=()=>function(e){function t({initialI18nStore:t,initialLanguage:s,...r}){return B(t,s),n.createElement(e,{...r})}return t.getInitialProps=K(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=(e,t={})=>function(s){function r({forwardedRef:r,...a}){const[i,o,l]=F(e,{...a,keyPrefix:t.keyPrefix}),c={...a,t:i,i18n:o,tReady:l};return t.withRef&&r?c.ref=r:!t.withRef&&r&&(c.forwardedRef=r),n.createElement(s,c)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}));
|
|
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(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==g&&g)){p=-1===c?s:r[c].children;var y=e.indexOf("<",m),N=e.slice(m,-1===y?void 0:y);o.test(N)&&(N=" "),(y>-1&&c+p.length>=0||" "!==N)&&p.push({type:"text",content:N})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,N=e=>"object"==typeof e&&null!==e,x=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},v=e=>b[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(x,v)};const O=(e={})=>{E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,k=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},T=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?A(n):n},A=e=>Array.isArray(e)?e:[e],R=(e,t,s,r)=>{if(!e)return"";let a="";const i=A(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=R(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(N(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i,o)=>{if(""===s)return[];const l=a.transKeepBasicHtmlNodesFor||[],u=s&&new RegExp(l.map((e=>`<${e}`)).join("|")).test(s);if(!(e||t||u||o))return[s];const p=t??{},d=e=>{A(e).forEach((e=>{y(e)||(k(e)?d(T(e)):N(e)&&!n.isValidElement(e)&&Object.assign(p,e))}))};d(e);const f=c(`<0>${s}</0>`),m={...p,...i},g=(e,t,s)=>{const r=T(e),a=x(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},h=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.props.ref??e.ref},a?null:t)})))},x=(e,s,i)=>{const c=A(e);return A(s).reduce(((e,s,p)=>{const d=s.children?.[0]?.content&&r.services.interpolator.interpolate(s.children[0].content,m,r.language);if("tag"===s.type){let o=c[parseInt(s.name,10)];!o&&t&&(o=t[s.name]),1!==i.length||o||(o=i[0][s.name]),o||(o={});const f=0!==Object.keys(s.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:s.attrs},o):o,b=n.isValidElement(f),v=b&&k(s,!0)&&!s.voidElement,E=u&&N(f)&&f.dummy&&!b,O=N(t)&&Object.hasOwnProperty.call(t,s.name);if(y(f)){const n=r.services.interpolator.interpolate(f,m,r.language);e.push(n)}else if(k(f)||v){const n=g(f,s,i);h(f,n,e,p)}else if(E){const n=x(c,s.children,i);h(f,n,e,p)}else if(Number.isNaN(parseFloat(s.name)))if(O){const n=g(f,s,i);h(f,n,e,p,s.voidElement)}else if(a.transSupportBasicHtmlNodes&&l.indexOf(s.name)>-1)if(s.voidElement)e.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const t=x(c,s.children,i);e.push(n.createElement(s.name,{key:`${s.name}-${p}`},t))}else if(s.voidElement)e.push(`<${s.name} />`);else{const n=x(c,s.children,i);e.push(`<${s.name}>${n}</${s.name}>`)}else if(N(f)&&!b){const n=s.children[0]?d:null;n&&e.push(n)}else h(f,d,e,p,1!==s.children.length||!d)}else if("text"===s.type){const t=a.transWrapTextNodes,i=o?a.unescape(r.services.interpolator.interpolate(s.content,m,r.language)):r.services.interpolator.interpolate(s.content,m,r.language);t?e.push(n.createElement(t,{key:`${s.name}-${p}`},i)):e.push(i)}return e}),[])},b=x([{dummy:!0,children:e||[]}],f,A(e||[]));return T(b[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):N(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null,P=e=>!!N(e)&&(!Array.isArray(e)&&Object.keys(e).reduce(((e,n)=>e&&Number.isNaN(Number.parseFloat(n))),!0));function V({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:f,shouldUnescape:m,...g}){const h=p||$();if(!h)return d(h,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:r}),e;const N=f||h.t.bind(h)||(e=>e),x={...I(),...h.options?.react};let b=u||N.ns||h.options?.defaultNS;b=y(b)?[b]:b||["translation"];const v=R(e,x,h,r),E=l||v||x.transEmptyNodeValue||r,{hashTransKey:O}=x,S=r||(O?O(v||E):v||E);h.options?.interpolation?.defaultVariables&&(o=o&&Object.keys(o).length>0?{...o,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const w=o||void 0!==t&&!h.options?.interpolation?.alwaysFormat||!e?i.interpolation:{interpolation:{...i.interpolation,prefix:"#$?",suffix:"?$#"}},k={...i,context:a||i.context,count:t,...o,...w,defaultValue:E,ns:b},T=S?N(S,k):E,A=L(c,T,h,r);let C=A||e,V=null;P(A)&&(V=A,C=e);const _=j(C,V,T,h,x,k,m),D=s??x.defaultTransParent;return D?n.createElement(D,g,_):_}const _={type:"3rdParty",init(e){O(e.options.react),w(e)}},D=n.createContext();class K{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const z=e=>async n=>({...await(e.getInitialProps?.(n))??{},...U()}),U=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const F=(e,n,t,s)=>e.getFixedT(n,t,s),B=(e,t={})=>{const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(D)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new K),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:N(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>((e,n,t={})=>n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0))(e,i,o))),f=((e,t,s,r)=>n.useCallback(F(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,x=()=>F(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,v]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{S.current&&v(x)})):m(i,u,(()=>{S.current&&v(x)}))),p&&O&&O!==E&&S.current&&v(x);const s=()=>{S.current&&v(x)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,E]),n.useEffect((()=>{S.current&&p&&v(h)}),[i,c,p]);const w=[b,i,p];if(w.t=b,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const W=(e,t,s={})=>{const{i18n:r}=s,{i18n:a}=n.useContext(D)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=D,e.I18nextProvider=function({i18n:e,defaultNS:t,children:s}){const r=n.useMemo((()=>({i18n:e,defaultNS:t})),[e,t]);return n.createElement(D.Provider,{value:r},s)},e.Trans=function({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:d,shouldUnescape:f,...m}){const{i18n:g,defaultNS:h}=n.useContext(D)||{},y=p||g||$(),N=d||y?.t.bind(y);return V({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i,values:o,defaults:l,components:c,ns:u||N?.ns||h||y?.options?.defaultNS,i18n:y,t:d,shouldUnescape:f,...m})},e.TransWithoutContext=V,e.Translation=({ns:e,children:n,...t})=>{const[s,r,a]=B(e,t);return n(s,{i18n:r,lng:r.language},a)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=U,e.initReactI18next=_,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=W,e.useTranslation=B,e.withSSR=()=>function(e){function t({initialI18nStore:t,initialLanguage:s,...r}){return W(t,s),n.createElement(e,{...r})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=(e,t={})=>function(s){function r({forwardedRef:r,...a}){const[i,o,l]=B(e,{...a,keyPrefix:t.keyPrefix}),c={...a,t:i,i18n:o,tReady:l};return t.withRef&&r?c.ref=r:!t.withRef&&r&&(c.forwardedRef=r),n.createElement(s,c)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-i18next",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.6.0",
|
|
4
4
|
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
|
|
5
5
|
"main": "dist/commonjs/index.js",
|
|
6
6
|
"types": "./index.d.mts",
|
|
@@ -84,28 +84,28 @@
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@babel/cli": "^7.
|
|
88
|
-
"@babel/core": "^7.
|
|
89
|
-
"@babel/eslint-parser": "^7.
|
|
87
|
+
"@babel/cli": "^7.28.0",
|
|
88
|
+
"@babel/core": "^7.28.0",
|
|
89
|
+
"@babel/eslint-parser": "^7.28.0",
|
|
90
90
|
"@babel/plugin-proposal-async-generator-functions": "^7.20.7",
|
|
91
91
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
92
92
|
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
|
|
93
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
93
|
+
"@babel/plugin-transform-runtime": "^7.28.0",
|
|
94
94
|
"@babel/polyfill": "^7.12.1",
|
|
95
|
-
"@babel/preset-env": "^7.
|
|
95
|
+
"@babel/preset-env": "^7.28.0",
|
|
96
96
|
"@babel/preset-react": "^7.27.1",
|
|
97
97
|
"@babel/register": "^7.27.1",
|
|
98
98
|
"@rollup/plugin-babel": "^6.0.4",
|
|
99
|
-
"@rollup/plugin-commonjs": "^26.0.
|
|
100
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
99
|
+
"@rollup/plugin-commonjs": "^26.0.3",
|
|
100
|
+
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
101
101
|
"@rollup/plugin-replace": "^5.0.7",
|
|
102
102
|
"@rollup/plugin-terser": "0.4.4",
|
|
103
103
|
"@testing-library/dom": "^10.4.0",
|
|
104
|
-
"@testing-library/jest-dom": "^6.
|
|
105
|
-
"@testing-library/react": "^16.
|
|
106
|
-
"@types/jest": "^29.5.
|
|
107
|
-
"@types/react": "^19.
|
|
108
|
-
"@vitest/coverage-v8": "^2.
|
|
104
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
105
|
+
"@testing-library/react": "^16.3.0",
|
|
106
|
+
"@types/jest": "^29.5.14",
|
|
107
|
+
"@types/react": "^19.1.8",
|
|
108
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
109
109
|
"all-contributors-cli": "^6.26.1",
|
|
110
110
|
"babel-core": "^7.0.0-bridge.0",
|
|
111
111
|
"babel-plugin-macros": "^3.1.0",
|
|
@@ -116,24 +116,24 @@
|
|
|
116
116
|
"eslint": "^8.57.0",
|
|
117
117
|
"eslint-config-airbnb": "19.0.4",
|
|
118
118
|
"eslint-config-prettier": "^9.1.0",
|
|
119
|
-
"eslint-plugin-import": "^2.
|
|
120
|
-
"eslint-plugin-jest-dom": "^5.
|
|
121
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
122
|
-
"eslint-plugin-react": "^7.
|
|
123
|
-
"eslint-plugin-testing-library": "^6.
|
|
119
|
+
"eslint-plugin-import": "^2.32.0",
|
|
120
|
+
"eslint-plugin-jest-dom": "^5.5.0",
|
|
121
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
122
|
+
"eslint-plugin-react": "^7.37.5",
|
|
123
|
+
"eslint-plugin-testing-library": "^6.5.0",
|
|
124
124
|
"happy-dom": "^14.12.3",
|
|
125
|
-
"husky": "^9.1.
|
|
126
|
-
"i18next": "^25.
|
|
127
|
-
"lint-staged": "^15.2
|
|
125
|
+
"husky": "^9.1.7",
|
|
126
|
+
"i18next": "^25.3.0",
|
|
127
|
+
"lint-staged": "^15.5.2",
|
|
128
128
|
"mkdirp": "^3.0.1",
|
|
129
|
-
"prettier": "^3.
|
|
130
|
-
"react": "^19.
|
|
131
|
-
"react-dom": "^19.
|
|
132
|
-
"react-test-renderer": "^19.
|
|
129
|
+
"prettier": "^3.6.2",
|
|
130
|
+
"react": "^19.1.0",
|
|
131
|
+
"react-dom": "^19.1.0",
|
|
132
|
+
"react-test-renderer": "^19.1.0",
|
|
133
133
|
"rimraf": "^6.0.1",
|
|
134
|
-
"rollup": "^4.
|
|
135
|
-
"typescript": "~5.
|
|
136
|
-
"vitest": "^2.
|
|
134
|
+
"rollup": "^4.44.1",
|
|
135
|
+
"typescript": "~5.8.3",
|
|
136
|
+
"vitest": "^2.1.9",
|
|
137
137
|
"yargs": "^17.7.2"
|
|
138
138
|
},
|
|
139
139
|
"scripts": {
|
package/react-i18next.js
CHANGED
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
var r = {
|
|
33
33
|
type: "tag",
|
|
34
34
|
name: "",
|
|
35
|
-
voidElement:
|
|
35
|
+
voidElement: false,
|
|
36
36
|
attrs: {},
|
|
37
37
|
children: []
|
|
38
38
|
},
|
|
39
39
|
i = n.match(/<\/?([^\s]+?)[/\s>]/);
|
|
40
|
-
if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement =
|
|
40
|
+
if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = true), r.name.startsWith("!--"))) {
|
|
41
41
|
var s = n.indexOf("--\x3e");
|
|
42
42
|
return {
|
|
43
43
|
type: "comment",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
c = [],
|
|
76
76
|
o = [],
|
|
77
77
|
l = -1,
|
|
78
|
-
m =
|
|
78
|
+
m = false;
|
|
79
79
|
if (0 !== e.indexOf("<")) {
|
|
80
80
|
var u = e.indexOf("<");
|
|
81
81
|
c.push({
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
return e.replace(r, function (r, s) {
|
|
87
87
|
if (m) {
|
|
88
88
|
if (r !== "</" + a.name + ">") return;
|
|
89
|
-
m =
|
|
89
|
+
m = false;
|
|
90
90
|
}
|
|
91
91
|
var u,
|
|
92
92
|
f = "/" !== r.charAt(1),
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
var v = n(r);
|
|
98
98
|
return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
|
|
99
99
|
}
|
|
100
|
-
if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m =
|
|
100
|
+
if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m = true), a.voidElement || m || !d || "<" === d || a.children.push({
|
|
101
101
|
type: "text",
|
|
102
102
|
content: e.slice(p, e.indexOf("<", p))
|
|
103
103
|
}), 0 === l && c.push(a), (u = o[l - 1]) && u.children.push(a), o[l] = a), (!f || a.voidElement) && (l > -1 && (a.voidElement || a.name === r.slice(2, -1)) && (l--, a = -1 === l ? c : o[l]), !m && "<" !== d && d)) {
|
|
@@ -315,12 +315,12 @@
|
|
|
315
315
|
});
|
|
316
316
|
return stringNode;
|
|
317
317
|
};
|
|
318
|
-
const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
318
|
+
const renderNodes = (children, knownComponentsMap, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
319
319
|
if (targetString === '') return [];
|
|
320
320
|
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
321
321
|
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
|
|
322
|
-
if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
323
|
-
const data = {};
|
|
322
|
+
if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
323
|
+
const data = knownComponentsMap ?? {};
|
|
324
324
|
const getData = childs => {
|
|
325
325
|
const childrenArray = getAsArray(childs);
|
|
326
326
|
childrenArray.forEach(child => {
|
|
@@ -366,6 +366,7 @@
|
|
|
366
366
|
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
367
367
|
if (node.type === 'tag') {
|
|
368
368
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
369
|
+
if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
|
|
369
370
|
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
370
371
|
if (!tmp) tmp = {};
|
|
371
372
|
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
@@ -374,7 +375,7 @@
|
|
|
374
375
|
const isElement = react.isValidElement(child);
|
|
375
376
|
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
376
377
|
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
|
|
377
|
-
const isKnownComponent = isObject(
|
|
378
|
+
const isKnownComponent = isObject(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
|
|
378
379
|
if (isString(child)) {
|
|
379
380
|
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
380
381
|
mem.push(value);
|
|
@@ -469,6 +470,11 @@
|
|
|
469
470
|
});
|
|
470
471
|
return null;
|
|
471
472
|
};
|
|
473
|
+
const isComponentsMap = object => {
|
|
474
|
+
if (!isObject(object)) return false;
|
|
475
|
+
if (Array.isArray(object)) return false;
|
|
476
|
+
return Object.keys(object).reduce((acc, key) => acc && Number.isNaN(Number.parseFloat(key)), true);
|
|
477
|
+
};
|
|
472
478
|
function Trans$1({
|
|
473
479
|
children,
|
|
474
480
|
count,
|
|
@@ -531,7 +537,13 @@
|
|
|
531
537
|
};
|
|
532
538
|
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
533
539
|
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
534
|
-
|
|
540
|
+
let indexedChildren = generatedComponents || children;
|
|
541
|
+
let componentsMap = null;
|
|
542
|
+
if (isComponentsMap(generatedComponents)) {
|
|
543
|
+
componentsMap = generatedComponents;
|
|
544
|
+
indexedChildren = children;
|
|
545
|
+
}
|
|
546
|
+
const content = renderNodes(indexedChildren, componentsMap, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
535
547
|
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
|
|
536
548
|
return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
|
|
537
549
|
}
|
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(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==g&&g)){p=-1===c?s:r[c].children;var y=e.indexOf("<",m),x=e.slice(m,-1===y?void 0:y);o.test(x)&&(x=" "),(y>-1&&c+p.length>=0||" "!==x)&&p.push({type:"text",content:x})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,N=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},v=e=>b[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(N,v)};const O=(e={})=>{E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,T=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},k=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],A=(e,t,s,r)=>{if(!e)return"";let a="";const i=R(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=A(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(x(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i)=>{if(""===t)return[];const o=r.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!i)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(T(e)?p(k(e)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},m=(e,t,s)=>{const r=k(e),a=h(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},g=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.props.ref??e.ref},a?null:t)})))},h=(t,a,c)=>{const u=R(t);return R(a).reduce(((t,a,p)=>{const d=a.children?.[0]?.content&&s.services.interpolator.interpolate(a.children[0].content,f,s.language);if("tag"===a.type){let i=u[parseInt(a.name,10)];1!==c.length||i||(i=c[0][a.name]),i||(i={});const N=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},i):i,b=n.isValidElement(N),v=b&&T(a,!0)&&!a.voidElement,E=l&&x(N)&&N.dummy&&!b,O=x(e)&&Object.hasOwnProperty.call(e,a.name);if(y(N)){const e=s.services.interpolator.interpolate(N,f,s.language);t.push(e)}else if(T(N)||v){const e=m(N,a,c);g(N,e,t,p)}else if(E){const e=h(u,a.children,c);g(N,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(O){const e=m(N,a,c);g(N,e,t,p,a.voidElement)}else if(r.transSupportBasicHtmlNodes&&o.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=h(u,a.children,c);t.push(n.createElement(a.name,{key:`${a.name}-${p}`},e))}else if(a.voidElement)t.push(`<${a.name} />`);else{const e=h(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(x(N)&&!b){const e=a.children[0]?d:null;e&&t.push(e)}else g(N,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=r.transWrapTextNodes,o=i?r.unescape(s.services.interpolator.interpolate(a.content,f,s.language)):s.services.interpolator.interpolate(a.content,f,s.language);e?t.push(n.createElement(e,{key:`${a.name}-${p}`},o)):t.push(o)}return t}),[])},N=h([{dummy:!0,children:e||[]}],d,R(e||[]));return k(N[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):x(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null;function P({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:f,shouldUnescape:m,...g}){const h=p||$();if(!h)return d(h,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:r}),e;const x=f||h.t.bind(h)||(e=>e),N={...I(),...h.options?.react};let b=u||x.ns||h.options?.defaultNS;b=y(b)?[b]:b||["translation"];const v=A(e,N,h,r),E=l||v||N.transEmptyNodeValue||r,{hashTransKey:O}=N,S=r||(O?O(v||E):v||E);h.options?.interpolation?.defaultVariables&&(o=o&&Object.keys(o).length>0?{...o,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const w=o||void 0!==t&&!h.options?.interpolation?.alwaysFormat||!e?i.interpolation:{interpolation:{...i.interpolation,prefix:"#$?",suffix:"?$#"}},T={...i,context:a||i.context,count:t,...o,...w,defaultValue:E,ns:b},k=S?x(S,T):E,R=L(c,k,h,r),C=j(R||e,k,h,N,T,m),P=s??N.defaultTransParent;return P?n.createElement(P,g,C):C}const V={type:"3rdParty",init(e){O(e.options.react),w(e)}},_=n.createContext();class D{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const K=e=>async n=>({...await(e.getInitialProps?.(n))??{},...z()}),z=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),F=(e,t={})=>{const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(_)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new D),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:x(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>((e,n,t={})=>n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0))(e,i,o))),f=((e,t,s,r)=>n.useCallback(U(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,N=()=>U(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,v]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{S.current&&v(N)})):m(i,u,(()=>{S.current&&v(N)}))),p&&O&&O!==E&&S.current&&v(N);const s=()=>{S.current&&v(N)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,E]),n.useEffect((()=>{S.current&&p&&v(h)}),[i,c,p]);const w=[b,i,p];if(w.t=b,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const B=(e,t,s={})=>{const{i18n:r}=s,{i18n:a}=n.useContext(_)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=_,e.I18nextProvider=function({i18n:e,defaultNS:t,children:s}){const r=n.useMemo((()=>({i18n:e,defaultNS:t})),[e,t]);return n.createElement(_.Provider,{value:r},s)},e.Trans=function({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:d,shouldUnescape:f,...m}){const{i18n:g,defaultNS:h}=n.useContext(_)||{},y=p||g||$(),x=d||y?.t.bind(y);return P({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i,values:o,defaults:l,components:c,ns:u||x?.ns||h||y?.options?.defaultNS,i18n:y,t:d,shouldUnescape:f,...m})},e.TransWithoutContext=P,e.Translation=({ns:e,children:n,...t})=>{const[s,r,a]=F(e,t);return n(s,{i18n:r,lng:r.language},a)},e.composeInitialProps=K,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=z,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=B,e.useTranslation=F,e.withSSR=()=>function(e){function t({initialI18nStore:t,initialLanguage:s,...r}){return B(t,s),n.createElement(e,{...r})}return t.getInitialProps=K(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=(e,t={})=>function(s){function r({forwardedRef:r,...a}){const[i,o,l]=F(e,{...a,keyPrefix:t.keyPrefix}),c={...a,t:i,i18n:o,tReady:l};return t.withRef&&r?c.ref=r:!t.withRef&&r&&(c.forwardedRef=r),n.createElement(s,c)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}));
|
|
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(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==g&&g)){p=-1===c?s:r[c].children;var y=e.indexOf("<",m),N=e.slice(m,-1===y?void 0:y);o.test(N)&&(N=" "),(y>-1&&c+p.length>=0||" "!==N)&&p.push({type:"text",content:N})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,N=e=>"object"==typeof e&&null!==e,x=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},v=e=>b[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(x,v)};const O=(e={})=>{E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,k=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},T=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?A(n):n},A=e=>Array.isArray(e)?e:[e],R=(e,t,s,r)=>{if(!e)return"";let a="";const i=A(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=R(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(N(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i,o)=>{if(""===s)return[];const l=a.transKeepBasicHtmlNodesFor||[],u=s&&new RegExp(l.map((e=>`<${e}`)).join("|")).test(s);if(!(e||t||u||o))return[s];const p=t??{},d=e=>{A(e).forEach((e=>{y(e)||(k(e)?d(T(e)):N(e)&&!n.isValidElement(e)&&Object.assign(p,e))}))};d(e);const f=c(`<0>${s}</0>`),m={...p,...i},g=(e,t,s)=>{const r=T(e),a=x(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},h=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.props.ref??e.ref},a?null:t)})))},x=(e,s,i)=>{const c=A(e);return A(s).reduce(((e,s,p)=>{const d=s.children?.[0]?.content&&r.services.interpolator.interpolate(s.children[0].content,m,r.language);if("tag"===s.type){let o=c[parseInt(s.name,10)];!o&&t&&(o=t[s.name]),1!==i.length||o||(o=i[0][s.name]),o||(o={});const f=0!==Object.keys(s.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:s.attrs},o):o,b=n.isValidElement(f),v=b&&k(s,!0)&&!s.voidElement,E=u&&N(f)&&f.dummy&&!b,O=N(t)&&Object.hasOwnProperty.call(t,s.name);if(y(f)){const n=r.services.interpolator.interpolate(f,m,r.language);e.push(n)}else if(k(f)||v){const n=g(f,s,i);h(f,n,e,p)}else if(E){const n=x(c,s.children,i);h(f,n,e,p)}else if(Number.isNaN(parseFloat(s.name)))if(O){const n=g(f,s,i);h(f,n,e,p,s.voidElement)}else if(a.transSupportBasicHtmlNodes&&l.indexOf(s.name)>-1)if(s.voidElement)e.push(n.createElement(s.name,{key:`${s.name}-${p}`}));else{const t=x(c,s.children,i);e.push(n.createElement(s.name,{key:`${s.name}-${p}`},t))}else if(s.voidElement)e.push(`<${s.name} />`);else{const n=x(c,s.children,i);e.push(`<${s.name}>${n}</${s.name}>`)}else if(N(f)&&!b){const n=s.children[0]?d:null;n&&e.push(n)}else h(f,d,e,p,1!==s.children.length||!d)}else if("text"===s.type){const t=a.transWrapTextNodes,i=o?a.unescape(r.services.interpolator.interpolate(s.content,m,r.language)):r.services.interpolator.interpolate(s.content,m,r.language);t?e.push(n.createElement(t,{key:`${s.name}-${p}`},i)):e.push(i)}return e}),[])},b=x([{dummy:!0,children:e||[]}],f,A(e||[]));return T(b[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):N(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null,P=e=>!!N(e)&&(!Array.isArray(e)&&Object.keys(e).reduce(((e,n)=>e&&Number.isNaN(Number.parseFloat(n))),!0));function V({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:f,shouldUnescape:m,...g}){const h=p||$();if(!h)return d(h,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:r}),e;const N=f||h.t.bind(h)||(e=>e),x={...I(),...h.options?.react};let b=u||N.ns||h.options?.defaultNS;b=y(b)?[b]:b||["translation"];const v=R(e,x,h,r),E=l||v||x.transEmptyNodeValue||r,{hashTransKey:O}=x,S=r||(O?O(v||E):v||E);h.options?.interpolation?.defaultVariables&&(o=o&&Object.keys(o).length>0?{...o,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const w=o||void 0!==t&&!h.options?.interpolation?.alwaysFormat||!e?i.interpolation:{interpolation:{...i.interpolation,prefix:"#$?",suffix:"?$#"}},k={...i,context:a||i.context,count:t,...o,...w,defaultValue:E,ns:b},T=S?N(S,k):E,A=L(c,T,h,r);let C=A||e,V=null;P(A)&&(V=A,C=e);const _=j(C,V,T,h,x,k,m),D=s??x.defaultTransParent;return D?n.createElement(D,g,_):_}const _={type:"3rdParty",init(e){O(e.options.react),w(e)}},D=n.createContext();class K{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const z=e=>async n=>({...await(e.getInitialProps?.(n))??{},...U()}),U=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const F=(e,n,t,s)=>e.getFixedT(n,t,s),B=(e,t={})=>{const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(D)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new K),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:N(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>((e,n,t={})=>n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0))(e,i,o))),f=((e,t,s,r)=>n.useCallback(F(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,x=()=>F(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,v]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{S.current&&v(x)})):m(i,u,(()=>{S.current&&v(x)}))),p&&O&&O!==E&&S.current&&v(x);const s=()=>{S.current&&v(x)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,E]),n.useEffect((()=>{S.current&&p&&v(h)}),[i,c,p]);const w=[b,i,p];if(w.t=b,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const W=(e,t,s={})=>{const{i18n:r}=s,{i18n:a}=n.useContext(D)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=D,e.I18nextProvider=function({i18n:e,defaultNS:t,children:s}){const r=n.useMemo((()=>({i18n:e,defaultNS:t})),[e,t]);return n.createElement(D.Provider,{value:r},s)},e.Trans=function({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:d,shouldUnescape:f,...m}){const{i18n:g,defaultNS:h}=n.useContext(D)||{},y=p||g||$(),N=d||y?.t.bind(y);return V({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i,values:o,defaults:l,components:c,ns:u||N?.ns||h||y?.options?.defaultNS,i18n:y,t:d,shouldUnescape:f,...m})},e.TransWithoutContext=V,e.Translation=({ns:e,children:n,...t})=>{const[s,r,a]=B(e,t);return n(s,{i18n:r,lng:r.language},a)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=U,e.initReactI18next=_,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=W,e.useTranslation=B,e.withSSR=()=>function(e){function t({initialI18nStore:t,initialLanguage:s,...r}){return W(t,s),n.createElement(e,{...r})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=(e,t={})=>function(s){function r({forwardedRef:r,...a}){const[i,o,l]=B(e,{...a,keyPrefix:t.keyPrefix}),c={...a,t:i,i18n:o,tReady:l};return t.withRef&&r?c.ref=r:!t.withRef&&r&&(c.forwardedRef=r),n.createElement(s,c)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}));
|
|
@@ -113,7 +113,15 @@ export const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
|
|
|
113
113
|
return stringNode;
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
const renderNodes = (
|
|
116
|
+
const renderNodes = (
|
|
117
|
+
children,
|
|
118
|
+
knownComponentsMap,
|
|
119
|
+
targetString,
|
|
120
|
+
i18n,
|
|
121
|
+
i18nOptions,
|
|
122
|
+
combinedTOpts,
|
|
123
|
+
shouldUnescape,
|
|
124
|
+
) => {
|
|
117
125
|
if (targetString === '') return [];
|
|
118
126
|
|
|
119
127
|
// check if contains tags we need to replace from html string to react nodes
|
|
@@ -122,10 +130,11 @@ const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
122
130
|
targetString && new RegExp(keepArray.map((keep) => `<${keep}`).join('|')).test(targetString);
|
|
123
131
|
|
|
124
132
|
// no need to replace tags in the targetstring
|
|
125
|
-
if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape)
|
|
133
|
+
if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape)
|
|
134
|
+
return [targetString];
|
|
126
135
|
|
|
127
136
|
// v2 -> interpolates upfront no need for "some <0>{{var}}</0>"" -> will be just "some {{var}}" in translation file
|
|
128
|
-
const data = {};
|
|
137
|
+
const data = knownComponentsMap ?? {};
|
|
129
138
|
|
|
130
139
|
const getData = (childs) => {
|
|
131
140
|
const childrenArray = getAsArray(childs);
|
|
@@ -194,6 +203,7 @@ const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
194
203
|
if (node.type === 'tag') {
|
|
195
204
|
// regular array (components or children)
|
|
196
205
|
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
206
|
+
if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
|
|
197
207
|
|
|
198
208
|
// trans components is an object
|
|
199
209
|
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
@@ -213,7 +223,7 @@ const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, s
|
|
|
213
223
|
emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
|
|
214
224
|
|
|
215
225
|
const isKnownComponent =
|
|
216
|
-
isObject(
|
|
226
|
+
isObject(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
|
|
217
227
|
|
|
218
228
|
if (isString(child)) {
|
|
219
229
|
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
@@ -366,6 +376,16 @@ const generateComponents = (components, translation, i18n, i18nKey) => {
|
|
|
366
376
|
return null;
|
|
367
377
|
};
|
|
368
378
|
|
|
379
|
+
// A component map is an object like: { Button: <button> }, but not an object like { 1: <button> }
|
|
380
|
+
const isComponentsMap = (object) => {
|
|
381
|
+
if (!isObject(object)) return false;
|
|
382
|
+
if (Array.isArray(object)) return false;
|
|
383
|
+
return Object.keys(object).reduce(
|
|
384
|
+
(acc, key) => acc && Number.isNaN(Number.parseFloat(key)),
|
|
385
|
+
true,
|
|
386
|
+
);
|
|
387
|
+
};
|
|
388
|
+
|
|
369
389
|
export function Trans({
|
|
370
390
|
children,
|
|
371
391
|
count,
|
|
@@ -434,9 +454,16 @@ export function Trans({
|
|
|
434
454
|
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
435
455
|
|
|
436
456
|
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
457
|
+
let indexedChildren = generatedComponents || children;
|
|
458
|
+
let componentsMap = null;
|
|
459
|
+
if (isComponentsMap(generatedComponents)) {
|
|
460
|
+
componentsMap = generatedComponents;
|
|
461
|
+
indexedChildren = children;
|
|
462
|
+
}
|
|
437
463
|
|
|
438
464
|
const content = renderNodes(
|
|
439
|
-
|
|
465
|
+
indexedChildren,
|
|
466
|
+
componentsMap,
|
|
440
467
|
translation,
|
|
441
468
|
i18n,
|
|
442
469
|
reactI18nextOptions,
|