react-i18next
Advanced tools
Comparing version 14.1.3 to 15.0.0
@@ -0,1 +1,8 @@ | ||
### 15.0.0 | ||
- use optional chaining, nullish coalescing and nullish coalescing assignment [1774](https://github.com/i18next/react-i18next/pull/1774) | ||
- Build config and optimizations [1769](https://github.com/i18next/react-i18next/pull/1769) | ||
- some dependency updates [1768](https://github.com/i18next/react-i18next/pull/1768) | ||
- use modern hasLoadedNamespace code (now requires at least i18next > v19.4.5 (introduced in june 2020)) | ||
### 14.1.3 | ||
@@ -2,0 +9,0 @@ |
@@ -117,4 +117,4 @@ define(['exports', 'react'], (function (exports, react) { 'use strict'; | ||
function warn() { | ||
if (console && console.warn) { | ||
const warn = function () { | ||
if (console?.warn) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -126,5 +126,5 @@ args[_key] = arguments[_key]; | ||
} | ||
} | ||
}; | ||
const alreadyWarned = {}; | ||
function warnOnce() { | ||
const warnOnce = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
@@ -136,3 +136,3 @@ args[_key2] = arguments[_key2]; | ||
warn(...args); | ||
} | ||
}; | ||
const loadedClb = (i18n, cb) => () => { | ||
@@ -161,18 +161,2 @@ if (i18n.isInitialized) { | ||
}; | ||
const oldI18nextHasLoadedNamespace = function (ns, i18n) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const lng = i18n.languages[0]; | ||
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; | ||
const lastLng = i18n.languages[i18n.languages.length - 1]; | ||
if (lng.toLowerCase() === 'cimode') return true; | ||
const loadNotPending = (l, n) => { | ||
const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; | ||
return loadState === -1 || loadState === 2; | ||
}; | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false; | ||
if (i18n.hasResourceBundle(lng, ns)) return true; | ||
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true; | ||
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; | ||
return false; | ||
}; | ||
const hasLoadedNamespace = function (ns, i18n) { | ||
@@ -184,10 +168,6 @@ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
} | ||
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined; | ||
if (!isNewerI18next) { | ||
return oldI18nextHasLoadedNamespace(ns, i18n, options); | ||
} | ||
return i18n.hasLoadedNamespace(ns, { | ||
lng: options.lng, | ||
precheck: (i18nInstance, loadNotPending) => { | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
if (options.bindI18n?.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
} | ||
@@ -253,3 +233,3 @@ }); | ||
if (!node) return false; | ||
const base = node.props ? node.props.children : node.children; | ||
const base = node.props?.children ?? node.children; | ||
if (checkLength) return base.length > 0; | ||
@@ -260,4 +240,4 @@ return !!base; | ||
if (!node) return []; | ||
const children = node.props ? node.props.children : node.children; | ||
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children; | ||
const children = node.props?.children ?? node.children; | ||
return node.props?.i18nIsDynamicList ? getAsArray(children) : children; | ||
}; | ||
@@ -277,3 +257,3 @@ const hasValidReactChildren = children => Array.isArray(children) && children.every(react.isValidElement); | ||
const childrenArray = getAsArray(children); | ||
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : []; | ||
const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : []; | ||
childrenArray.forEach((child, childIndex) => { | ||
@@ -342,3 +322,3 @@ if (isString(child)) { | ||
const mappedChildren = mapAST(childs, node.children, rootReactNode); | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren; | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren; | ||
}; | ||
@@ -369,3 +349,3 @@ const pushTranslatedJSX = (child, inner, mem, i, isVoid) => { | ||
return astNodes.reduce((mem, node, i) => { | ||
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
if (node.type === 'tag') { | ||
@@ -463,5 +443,5 @@ let tmp = reactNodes[parseInt(node.name, 10)]; | ||
...getDefaults(), | ||
...(i18n.options && i18n.options.react) | ||
...i18n.options?.react | ||
}; | ||
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || t.ns || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
@@ -474,3 +454,3 @@ const nodeAsString = nodesToString(children, reactI18nextOptions); | ||
const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue); | ||
if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) { | ||
if (i18n.options?.interpolation?.defaultVariables) { | ||
values = values && Object.keys(values).length > 0 ? { | ||
@@ -511,3 +491,3 @@ ...values, | ||
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); | ||
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; | ||
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent; | ||
return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content; | ||
@@ -531,3 +511,3 @@ } | ||
namespaces.forEach(ns => { | ||
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true; | ||
this.usedNamespaces[ns] ??= true; | ||
}); | ||
@@ -538,3 +518,3 @@ } | ||
const composeInitialProps = ForComponent => async ctx => { | ||
const componentsInitialProps = ForComponent.getInitialProps ? await ForComponent.getInitialProps(ctx) : {}; | ||
const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {}; | ||
const i18nInitialProps = getInitialProps(); | ||
@@ -548,3 +528,3 @@ return { | ||
const i18n = getI18n(); | ||
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; | ||
const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? []; | ||
const ret = {}; | ||
@@ -585,3 +565,3 @@ const initialI18nStore = {}; | ||
const i18n = i18nFromProps || i18nFromContext || getI18n(); | ||
const t = tFromProps || i18n && i18n.t.bind(i18n); | ||
const t = tFromProps || i18n?.t.bind(i18n); | ||
return Trans$1({ | ||
@@ -597,3 +577,3 @@ children, | ||
components, | ||
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS, | ||
ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS, | ||
i18n, | ||
@@ -609,3 +589,3 @@ t: tFromProps, | ||
react.useEffect(() => { | ||
ref.current = ignore ? ref.current : value; | ||
ref.current = value; | ||
}, [value, ignore]); | ||
@@ -640,3 +620,3 @@ return ref.current; | ||
} | ||
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
if (i18n.options.react?.wait) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
const i18nOptions = { | ||
@@ -651,5 +631,5 @@ ...getDefaults(), | ||
} = i18nOptions; | ||
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); | ||
i18n.reportNamespaces.addUsedNamespaces?.(namespaces); | ||
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions)); | ||
@@ -687,7 +667,7 @@ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix); | ||
}; | ||
if (bindI18n && i18n) i18n.on(bindI18n, boundReset); | ||
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); | ||
if (bindI18n) i18n?.on(bindI18n, boundReset); | ||
if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset); | ||
return () => { | ||
isMounted.current = false; | ||
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (i18n) bindI18n?.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset)); | ||
@@ -750,8 +730,8 @@ }; | ||
function Translation(props) { | ||
const { | ||
const Translation = _ref => { | ||
let { | ||
ns, | ||
children, | ||
...options | ||
} = props; | ||
} = _ref; | ||
const [t, i18n, ready] = useTranslation(ns, options); | ||
@@ -762,3 +742,3 @@ return children(t, { | ||
}, ready); | ||
} | ||
}; | ||
@@ -789,3 +769,3 @@ function I18nextProvider(_ref) { | ||
const i18n = i18nFromProps || i18nFromContext || getI18n(); | ||
if (i18n.options && i18n.options.isClone) return; | ||
if (i18n.options?.isClone) return; | ||
if (initialI18nStore && !i18n.initializedStoreOnce) { | ||
@@ -792,0 +772,0 @@ i18n.services.resourceStore.data = initialI18nStore; |
@@ -1,1 +0,1 @@ | ||
define(["exports","react"],(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),a=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function i(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var i=e.indexOf("--\x3e");return{type:"comment",comment:-1!==i?e.slice(4,i):""}}for(var r=new RegExp(a),o=null;null!==(o=r.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],r.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],a=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(r,(function(r,l){if(u){if(r!=="</"+t.name+">")return;u=!1}var p,d="/"!==r.charAt(1),f=r.startsWith("\x3c!--"),g=l+r.length,h=e.charAt(g);if(f){var m=i(r);return c<0?(s.push(m),s):((p=a[c]).children.push(m),s)}if(d&&(c++,"tag"===(t=i(r)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===c&&s.push(t),(p=a[c-1])&&p.children.push(t),a[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===r.slice(2,-1))&&(c--,t=-1===c?s:a[c]),!u&&"<"!==h&&h)){p=-1===c?s:a[c].children;var y=e.indexOf("<",g),v=e.slice(g,-1===y?void 0:y);o.test(v)&&(v=" "),(y>-1&&c+p.length>=0||" "!==v)&&p.push({type:"text",content:v})}})),s};function u(){if(console&&console.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}}const p={};function d(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&p[n[0]]||(y(n[0])&&(p[n[0]]=new Date),u(...n))}const f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},g=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},h=(e,n,t,s)=>{y(t)&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},m=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,v=e=>"object"==typeof e&&null!==e,b=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},E=e=>x[e];let N={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(b,E)};const O=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N={...N,...e}},$=()=>N;let k;const w=e=>{k=e},I=()=>k,S=(e,n)=>{if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t},C=e=>{if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?j(n):n},j=e=>Array.isArray(e)?e:[e],R=(e,t)=>{if(!e)return"";let s="";const a=j(e),i=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return a.forEach(((e,a)=>{if(y(e))s+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:r}=e,o=Object.keys(n).length,l=i.indexOf(r)>-1,c=n.children;if(c||!l||o)if(!c&&(!l||o)||n.i18nIsDynamicList)s+=`<${a}></${a}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}</${r}>`;else{const e=R(c,t);s+=`<${a}>${e}</${a}>`}else s+=`<${r}/>`}else if(null===e)u("Trans: the passed in value is invalid - seems you passed in a null child.");else if(v(e)){const{format:n,...t}=e,a=Object.keys(t);if(1===a.length){const e=n?`${a[0]}, ${n}`:a[0];s+=`{{${e}}}`}else u("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else u("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",e)})),s},L=(e,t,s,a,i,r)=>{if(""===t)return[];const o=a.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!r)return[t];const u={},p=e=>{j(e).forEach((e=>{y(e)||(S(e)?p(C(e)):v(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...i},g=(e,t,s)=>{const a=C(e),i=m(a,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(a)&&0===i.length||e.props&&e.props.i18nIsDynamicList?a:i},h=(e,t,s,a,i)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:a},i?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:a,ref:e.ref},i?null:t)})))},m=(t,i,c)=>{const u=j(t);return j(i).reduce(((t,i,p)=>{const d=i.children&&i.children[0]&&i.children[0].content&&s.services.interpolator.interpolate(i.children[0].content,f,s.language);if("tag"===i.type){let r=u[parseInt(i.name,10)];1!==c.length||r||(r=c[0][i.name]),r||(r={});const b=0!==Object.keys(i.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:i.attrs},r):r,x=n.isValidElement(b),E=x&&S(i,!0)&&!i.voidElement,N=l&&v(b)&&b.dummy&&!x,O=v(e)&&Object.hasOwnProperty.call(e,i.name);if(y(b)){const e=s.services.interpolator.interpolate(b,f,s.language);t.push(e)}else if(S(b)||E){const e=g(b,i,c);h(b,e,t,p)}else if(N){const e=m(u,i.children,c);h(b,e,t,p)}else if(Number.isNaN(parseFloat(i.name)))if(O){const e=g(b,i,c);h(b,e,t,p,i.voidElement)}else if(a.transSupportBasicHtmlNodes&&o.indexOf(i.name)>-1)if(i.voidElement)t.push(n.createElement(i.name,{key:`${i.name}-${p}`}));else{const e=m(u,i.children,c);t.push(n.createElement(i.name,{key:`${i.name}-${p}`},e))}else if(i.voidElement)t.push(`<${i.name} />`);else{const e=m(u,i.children,c);t.push(`<${i.name}>${e}</${i.name}>`)}else if(v(b)&&!x){const e=i.children[0]?d:null;e&&t.push(e)}else h(b,d,t,p,1!==i.children.length||!d)}else if("text"===i.type){const e=a.transWrapTextNodes,o=r?a.unescape(s.services.interpolator.interpolate(i.content,f,s.language)):s.services.interpolator.interpolate(i.content,f,s.language);e?t.push(n.createElement(e,{key:`${i.name}-${p}`},o)):t.push(o)}return t}),[])},b=m([{dummy:!0,children:e||[]}],d,j(e||[]));return C(b[0])};function T(e){let{children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:g,shouldUnescape:h,...m}=e;const v=f||I();if(!v)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=g||v.t.bind(v)||(e=>e),x={...$(),...v.options&&v.options.react};let E=p||b.ns||v.options&&v.options.defaultNS;E=y(E)?[E]:E||["translation"];const N=R(t,x),O=c||N||x.transEmptyNodeValue||i,{hashTransKey:k}=x,w=i||(k?k(N||O):N||O);v.options&&v.options.interpolation&&v.options.interpolation.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...v.options.interpolation.defaultVariables}:{...v.options.interpolation.defaultVariables});const S=l||void 0!==s||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},C={...o,context:r||o.context,count:s,...l,...S,defaultValue:O,ns:E},j=w?b(w,C):O;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||j.indexOf(`${e}/>`)<0&&j.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const T=L(u||t,j,v,x,C,h),P=void 0!==a?a:x.defaultTransParent;return P?n.createElement(P,m,T):T}const P={type:"3rdParty",init(e){O(e.options.react),w(e)}},A=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces=()=>Object.keys(this.usedNamespaces)}const z=e=>async n=>({...e.getInitialProps?await e.getInitialProps(n):{},...B()}),B=()=>{const e=I(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const F=(e,n,t,s)=>e.getFixedT(n,t,s),U=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:a,defaultNS:i}=n.useContext(A)||{},r=s||a||I();if(r&&!r.reportNamespaces&&(r.reportNamespaces=new V),!r){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:v(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}r.options.react&&void 0!==r.options.react.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...$(),...r.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||i||r.options&&r.options.defaultNS;u=y(u)?[u]:u||["translation"],r.reportNamespaces.addUsedNamespaces&&r.reportNamespaces.addUsedNamespaces(u);const p=(r.isInitialized||r.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?void 0!==n.options.ignoreJSONStructure?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=n.languages[0],a=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===s.toLowerCase())return!0;const r=(e,t)=>{const s=n.services.backendConnector.state[`${e}|${t}`];return-1===s||2===s};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!r(n.isLanguageChangingTo,e)||!n.hasResourceBundle(s,e)&&n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages)&&(!r(s,e)||a&&!r(i,e)))}(e,n,t):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,r,o))),f=((e,t,s,a)=>n.useCallback(F(e,t,s,a),[e,t,s,a]))(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),m=()=>f,b=()=>F(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[x,E]=n.useState(m);let N=u.join();t.lng&&(N=`${t.lng}${N}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current})(N),k=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;k.current=!0,p||l||(t.lng?h(r,t.lng,u,(()=>{k.current&&E(b)})):g(r,u,(()=>{k.current&&E(b)}))),p&&O&&O!==N&&k.current&&E(b);const s=()=>{k.current&&E(b)};return e&&r&&r.on(e,s),n&&r&&r.store.on(n,s),()=>{k.current=!1,e&&r&&e.split(" ").forEach((e=>r.off(e,s))),n&&r&&n.split(" ").forEach((e=>r.store.off(e,s)))}}),[r,N]),n.useEffect((()=>{k.current&&p&&E(m)}),[r,c,p]);const w=[x,r,p];if(w.t=x,w.i18n=r,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?h(r,t.lng,u,(()=>e())):g(r,u,(()=>e()))}))};const K=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:a}=s,{i18n:i}=n.useContext(A)||{},r=a||i||I();r.options&&r.options.isClone||(e&&!r.initializedStoreOnce&&(r.services.resourceStore.data=e,r.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),r.options.ns),r.initializedStoreOnce=!0,r.isInitialized=!0),t&&!r.initializedLanguageOnce&&(r.changeLanguage(t),r.initializedLanguageOnce=!0))};e.I18nContext=A,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:a}=e;const i=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(A.Provider,{value:i},a)},e.Trans=function(e){let{children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(A)||{},v=d||m||I(),b=f||v&&v.t.bind(v);return T({children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o,values:l,defaults:c,components:u,ns:p||b&&b.ns||y||v&&v.options&&v.options.defaultNS,i18n:v,t:f,shouldUnescape:g,...h})},e.TransWithoutContext=T,e.Translation=function(e){const{ns:n,children:t,...s}=e,[a,i,r]=U(n,s);return t(a,{i18n:i,lng:i.language},r)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=I,e.getInitialProps=B,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=K,e.useTranslation=U,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:a,...i}=t;return K(s,a),n.createElement(e,{...i})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${m(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function a(a){let{forwardedRef:i,...r}=a;const[o,l,c]=U(e,{...r,keyPrefix:t.keyPrefix}),u={...r,t:o,i18n:l,tReady:c};return t.withRef&&i?u.ref=i:!t.withRef&&i&&(u.forwardedRef=i),n.createElement(s,u)}a.displayName=`withI18nextTranslation(${m(s)})`,a.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(a,Object.assign({},e,{forwardedRef:t})))):a}}})); | ||
define(["exports","react"],(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),a=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function i(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var i=e.indexOf("--\x3e");return{type:"comment",comment:-1!==i?e.slice(4,i):""}}for(var r=new RegExp(a),o=null;null!==(o=r.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],r.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],a=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(r,(function(r,l){if(u){if(r!=="</"+t.name+">")return;u=!1}var p,d="/"!==r.charAt(1),f=r.startsWith("\x3c!--"),h=l+r.length,m=e.charAt(h);if(f){var g=i(r);return c<0?(s.push(g),s):((p=a[c]).children.push(g),s)}if(d&&(c++,"tag"===(t=i(r)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!m||"<"===m||t.children.push({type:"text",content:e.slice(h,e.indexOf("<",h))}),0===c&&s.push(t),(p=a[c-1])&&p.children.push(t),a[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===r.slice(2,-1))&&(c--,t=-1===c?s:a[c]),!u&&"<"!==m&&m)){p=-1===c?s:a[c].children;var y=e.indexOf("<",h),v=e.slice(h,-1===y?void 0:y);o.test(v)&&(v=" "),(y>-1&&c+p.length>=0||" "!==v)&&p.push({type:"text",content:v})}})),s};const u=function(){if(console?.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}},p={},d=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&p[n[0]]||(y(n[0])&&(p[n[0]]=new Date),u(...n))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},h=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},m=(e,n,t,s)=>{y(t)&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},g=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,v=e=>"object"==typeof e&&null!==e,x=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},E=e=>b[e];let O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(x,E)};const N=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}},$=()=>O;let w;const I=e=>{w=e},k=()=>w,S=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},j=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],C=(e,t)=>{if(!e)return"";let s="";const a=R(e),i=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach(((e,a)=>{if(y(e))s+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:r}=e,o=Object.keys(n).length,l=i.indexOf(r)>-1,c=n.children;if(c||!l||o)if(!c&&(!l||o)||n.i18nIsDynamicList)s+=`<${a}></${a}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}</${r}>`;else{const e=C(c,t);s+=`<${a}>${e}</${a}>`}else s+=`<${r}/>`}else if(null===e)u("Trans: the passed in value is invalid - seems you passed in a null child.");else if(v(e)){const{format:n,...t}=e,a=Object.keys(t);if(1===a.length){const e=n?`${a[0]}, ${n}`:a[0];s+=`{{${e}}}`}else u("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else u("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",e)})),s},T=(e,t,s,a,i,r)=>{if(""===t)return[];const o=a.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!r)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(S(e)?p(j(e)):v(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...i},h=(e,t,s)=>{const a=j(e),i=g(a,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(a)&&0===i.length||e.props?.i18nIsDynamicList?a:i},m=(e,t,s,a,i)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:a},i?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:a,ref:e.ref},i?null:t)})))},g=(t,i,c)=>{const u=R(t);return R(i).reduce(((t,i,p)=>{const d=i.children?.[0]?.content&&s.services.interpolator.interpolate(i.children[0].content,f,s.language);if("tag"===i.type){let r=u[parseInt(i.name,10)];1!==c.length||r||(r=c[0][i.name]),r||(r={});const x=0!==Object.keys(i.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:i.attrs},r):r,b=n.isValidElement(x),E=b&&S(i,!0)&&!i.voidElement,O=l&&v(x)&&x.dummy&&!b,N=v(e)&&Object.hasOwnProperty.call(e,i.name);if(y(x)){const e=s.services.interpolator.interpolate(x,f,s.language);t.push(e)}else if(S(x)||E){const e=h(x,i,c);m(x,e,t,p)}else if(O){const e=g(u,i.children,c);m(x,e,t,p)}else if(Number.isNaN(parseFloat(i.name)))if(N){const e=h(x,i,c);m(x,e,t,p,i.voidElement)}else if(a.transSupportBasicHtmlNodes&&o.indexOf(i.name)>-1)if(i.voidElement)t.push(n.createElement(i.name,{key:`${i.name}-${p}`}));else{const e=g(u,i.children,c);t.push(n.createElement(i.name,{key:`${i.name}-${p}`},e))}else if(i.voidElement)t.push(`<${i.name} />`);else{const e=g(u,i.children,c);t.push(`<${i.name}>${e}</${i.name}>`)}else if(v(x)&&!b){const e=i.children[0]?d:null;e&&t.push(e)}else m(x,d,t,p,1!==i.children.length||!d)}else if("text"===i.type){const e=a.transWrapTextNodes,o=r?a.unescape(s.services.interpolator.interpolate(i.content,f,s.language)):s.services.interpolator.interpolate(i.content,f,s.language);e?t.push(n.createElement(e,{key:`${i.name}-${p}`},o)):t.push(o)}return t}),[])},x=g([{dummy:!0,children:e||[]}],d,R(e||[]));return j(x[0])};function P(e){let{children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:h,shouldUnescape:m,...g}=e;const v=f||k();if(!v)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const x=h||v.t.bind(v)||(e=>e),b={...$(),...v.options?.react};let E=p||x.ns||v.options?.defaultNS;E=y(E)?[E]:E||["translation"];const O=C(t,b),N=c||O||b.transEmptyNodeValue||i,{hashTransKey:w}=b,I=i||(w?w(O||N):O||N);v.options?.interpolation?.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...v.options.interpolation.defaultVariables}:{...v.options.interpolation.defaultVariables});const S=l||void 0!==s||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},j={...o,context:r||o.context,count:s,...l,...S,defaultValue:N,ns:E},R=I?x(I,j):N;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||R.indexOf(`${e}/>`)<0&&R.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const P=T(u||t,R,v,b,j,m),L=a??b.defaultTransParent;return L?n.createElement(L,g,P):P}const L={type:"3rdParty",init(e){N(e.options.react),I(e)}},A=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]??=!0}))}getUsedNamespaces=()=>Object.keys(this.usedNamespaces)}const z=e=>async n=>({...await(e.getInitialProps?.(n))??{},...F()}),F=()=>{const e=k(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),B=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:a,defaultNS:i}=n.useContext(A)||{},r=s||a||k();if(r&&!r.reportNamespaces&&(r.reportNamespaces=new V),!r){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:v(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}r.options.react?.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...$(),...r.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||i||r.options?.defaultNS;u=y(u)?[u]:u||["translation"],r.reportNamespaces.addUsedNamespaces?.(u);const p=(r.isInitialized||r.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,r,o))),f=((e,t,s,a)=>n.useCallback(U(e,t,s,a),[e,t,s,a]))(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),g=()=>f,x=()=>U(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,E]=n.useState(g);let O=u.join();t.lng&&(O=`${t.lng}${O}`);const N=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(O),w=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;w.current=!0,p||l||(t.lng?m(r,t.lng,u,(()=>{w.current&&E(x)})):h(r,u,(()=>{w.current&&E(x)}))),p&&N&&N!==O&&w.current&&E(x);const s=()=>{w.current&&E(x)};return e&&r?.on(e,s),n&&r?.store.on(n,s),()=>{w.current=!1,r&&e?.split(" ").forEach((e=>r.off(e,s))),n&&r&&n.split(" ").forEach((e=>r.store.off(e,s)))}}),[r,O]),n.useEffect((()=>{w.current&&p&&E(g)}),[r,c,p]);const I=[b,r,p];if(I.t=b,I.i18n=r,I.ready=p,p)return I;if(!p&&!l)return I;throw new Promise((e=>{t.lng?m(r,t.lng,u,(()=>e())):h(r,u,(()=>e()))}))};const D=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:a}=s,{i18n:i}=n.useContext(A)||{},r=a||i||k();r.options?.isClone||(e&&!r.initializedStoreOnce&&(r.services.resourceStore.data=e,r.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),r.options.ns),r.initializedStoreOnce=!0,r.isInitialized=!0),t&&!r.initializedLanguageOnce&&(r.changeLanguage(t),r.initializedLanguageOnce=!0))};e.I18nContext=A,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:a}=e;const i=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(A.Provider,{value:i},a)},e.Trans=function(e){let{children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:h,...m}=e;const{i18n:g,defaultNS:y}=n.useContext(A)||{},v=d||g||k(),x=f||v?.t.bind(v);return P({children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o,values:l,defaults:c,components:u,ns:p||x?.ns||y||v?.options?.defaultNS,i18n:v,t:f,shouldUnescape:h,...m})},e.TransWithoutContext=P,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[a,i,r]=B(n,s);return t(a,{i18n:i,lng:i.language},r)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=k,e.getInitialProps=F,e.initReactI18next=L,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=N,e.setI18n=I,e.time=()=>"",e.useSSR=D,e.useTranslation=B,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:a,...i}=t;return D(s,a),n.createElement(e,{...i})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${g(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function a(a){let{forwardedRef:i,...r}=a;const[o,l,c]=B(e,{...r,keyPrefix:t.keyPrefix}),u={...r,t:o,i18n:l,tReady:c};return t.withRef&&i?u.ref=i:!t.withRef&&i&&(u.forwardedRef=i),n.createElement(s,u)}a.displayName=`withI18nextTranslation(${g(s)})`,a.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(a,Object.assign({},e,{forwardedRef:t})))):a}}})); |
@@ -49,3 +49,3 @@ "use strict"; | ||
namespaces.forEach(ns => { | ||
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true; | ||
this.usedNamespaces[ns] ??= true; | ||
}); | ||
@@ -57,3 +57,3 @@ } | ||
const composeInitialProps = ForComponent => async ctx => { | ||
const componentsInitialProps = ForComponent.getInitialProps ? await ForComponent.getInitialProps(ctx) : {}; | ||
const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {}; | ||
const i18nInitialProps = getInitialProps(); | ||
@@ -68,3 +68,3 @@ return { | ||
const i18n = (0, _i18nInstance.getI18n)(); | ||
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; | ||
const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? []; | ||
const ret = {}; | ||
@@ -71,0 +71,0 @@ const initialI18nStore = {}; |
@@ -38,3 +38,3 @@ "use strict"; | ||
const i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)(); | ||
const t = tFromProps || i18n && i18n.t.bind(i18n); | ||
const t = tFromProps || i18n?.t.bind(i18n); | ||
return (0, _TransWithoutContext.Trans)({ | ||
@@ -50,3 +50,3 @@ children, | ||
components, | ||
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS, | ||
ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS, | ||
i18n, | ||
@@ -53,0 +53,0 @@ t: tFromProps, |
@@ -6,10 +6,10 @@ "use strict"; | ||
}); | ||
exports.Translation = Translation; | ||
exports.Translation = void 0; | ||
var _useTranslation = require("./useTranslation.js"); | ||
function Translation(props) { | ||
const { | ||
const Translation = _ref => { | ||
let { | ||
ns, | ||
children, | ||
...options | ||
} = props; | ||
} = _ref; | ||
const [t, i18n, ready] = (0, _useTranslation.useTranslation)(ns, options); | ||
@@ -20,2 +20,3 @@ return children(t, { | ||
}, ready); | ||
} | ||
}; | ||
exports.Translation = Translation; |
@@ -16,3 +16,3 @@ "use strict"; | ||
if (!node) return false; | ||
const base = node.props ? node.props.children : node.children; | ||
const base = node.props?.children ?? node.children; | ||
if (checkLength) return base.length > 0; | ||
@@ -23,4 +23,4 @@ return !!base; | ||
if (!node) return []; | ||
const children = node.props ? node.props.children : node.children; | ||
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children; | ||
const children = node.props?.children ?? node.children; | ||
return node.props?.i18nIsDynamicList ? getAsArray(children) : children; | ||
}; | ||
@@ -40,3 +40,3 @@ const hasValidReactChildren = children => Array.isArray(children) && children.every(_react.isValidElement); | ||
const childrenArray = getAsArray(children); | ||
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : []; | ||
const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : []; | ||
childrenArray.forEach((child, childIndex) => { | ||
@@ -106,3 +106,3 @@ if ((0, _utils.isString)(child)) { | ||
const mappedChildren = mapAST(childs, node.children, rootReactNode); | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren; | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren; | ||
}; | ||
@@ -133,3 +133,3 @@ const pushTranslatedJSX = (child, inner, mem, i, isVoid) => { | ||
return astNodes.reduce((mem, node, i) => { | ||
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
if (node.type === 'tag') { | ||
@@ -227,5 +227,5 @@ let tmp = reactNodes[parseInt(node.name, 10)]; | ||
...(0, _defaults.getDefaults)(), | ||
...(i18n.options && i18n.options.react) | ||
...i18n.options?.react | ||
}; | ||
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || t.ns || i18n.options?.defaultNS; | ||
namespaces = (0, _utils.isString)(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
@@ -238,3 +238,3 @@ const nodeAsString = nodesToString(children, reactI18nextOptions); | ||
const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue); | ||
if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) { | ||
if (i18n.options?.interpolation?.defaultVariables) { | ||
values = values && Object.keys(values).length > 0 ? { | ||
@@ -275,4 +275,4 @@ ...values, | ||
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); | ||
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; | ||
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent; | ||
return useAsParent ? (0, _react.createElement)(useAsParent, additionalProps, content) : content; | ||
} |
@@ -18,3 +18,3 @@ "use strict"; | ||
const i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)(); | ||
if (i18n.options && i18n.options.isClone) return; | ||
if (i18n.options?.isClone) return; | ||
if (initialI18nStore && !i18n.initializedStoreOnce) { | ||
@@ -21,0 +21,0 @@ i18n.services.resourceStore.data = initialI18nStore; |
@@ -43,3 +43,3 @@ "use strict"; | ||
} | ||
if (i18n.options.react && i18n.options.react.wait !== undefined) (0, _utils.warnOnce)('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
if (i18n.options.react?.wait) (0, _utils.warnOnce)('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
const i18nOptions = { | ||
@@ -54,5 +54,5 @@ ...(0, _context.getDefaults)(), | ||
} = i18nOptions; | ||
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS; | ||
namespaces = (0, _utils.isString)(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); | ||
i18n.reportNamespaces.addUsedNamespaces?.(namespaces); | ||
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => (0, _utils.hasLoadedNamespace)(n, i18n, i18nOptions)); | ||
@@ -90,7 +90,7 @@ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix); | ||
}; | ||
if (bindI18n && i18n) i18n.on(bindI18n, boundReset); | ||
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); | ||
if (bindI18n) i18n?.on(bindI18n, boundReset); | ||
if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset); | ||
return () => { | ||
isMounted.current = false; | ||
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (i18n) bindI18n?.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset)); | ||
@@ -97,0 +97,0 @@ }; |
@@ -6,7 +6,5 @@ "use strict"; | ||
}); | ||
exports.loadNamespaces = exports.loadLanguages = exports.isString = exports.isObject = exports.hasLoadedNamespace = exports.getDisplayName = void 0; | ||
exports.warn = warn; | ||
exports.warnOnce = warnOnce; | ||
function warn() { | ||
if (console && console.warn) { | ||
exports.warnOnce = exports.warn = exports.loadNamespaces = exports.loadLanguages = exports.isString = exports.isObject = exports.hasLoadedNamespace = exports.getDisplayName = void 0; | ||
const warn = function () { | ||
if (console?.warn) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -18,5 +16,6 @@ args[_key] = arguments[_key]; | ||
} | ||
} | ||
}; | ||
exports.warn = warn; | ||
const alreadyWarned = {}; | ||
function warnOnce() { | ||
const warnOnce = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
@@ -28,3 +27,4 @@ args[_key2] = arguments[_key2]; | ||
warn(...args); | ||
} | ||
}; | ||
exports.warnOnce = warnOnce; | ||
const loadedClb = (i18n, cb) => () => { | ||
@@ -55,18 +55,2 @@ if (i18n.isInitialized) { | ||
exports.loadLanguages = loadLanguages; | ||
const oldI18nextHasLoadedNamespace = function (ns, i18n) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const lng = i18n.languages[0]; | ||
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; | ||
const lastLng = i18n.languages[i18n.languages.length - 1]; | ||
if (lng.toLowerCase() === 'cimode') return true; | ||
const loadNotPending = (l, n) => { | ||
const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; | ||
return loadState === -1 || loadState === 2; | ||
}; | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false; | ||
if (i18n.hasResourceBundle(lng, ns)) return true; | ||
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true; | ||
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; | ||
return false; | ||
}; | ||
const hasLoadedNamespace = function (ns, i18n) { | ||
@@ -78,10 +62,6 @@ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
} | ||
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined; | ||
if (!isNewerI18next) { | ||
return oldI18nextHasLoadedNamespace(ns, i18n, options); | ||
} | ||
return i18n.hasLoadedNamespace(ns, { | ||
lng: options.lng, | ||
precheck: (i18nInstance, loadNotPending) => { | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
if (options.bindI18n?.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
} | ||
@@ -88,0 +68,0 @@ }); |
@@ -13,3 +13,3 @@ import { createContext } from 'react'; | ||
namespaces.forEach(ns => { | ||
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true; | ||
this.usedNamespaces[ns] ??= true; | ||
}); | ||
@@ -20,3 +20,3 @@ } | ||
export const composeInitialProps = ForComponent => async ctx => { | ||
const componentsInitialProps = ForComponent.getInitialProps ? await ForComponent.getInitialProps(ctx) : {}; | ||
const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {}; | ||
const i18nInitialProps = getInitialProps(); | ||
@@ -30,3 +30,3 @@ return { | ||
const i18n = getI18n(); | ||
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; | ||
const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? []; | ||
const ret = {}; | ||
@@ -33,0 +33,0 @@ const initialI18nStore = {}; |
@@ -12,4 +12,3 @@ import { unescape } from './unescape.js'; | ||
}; | ||
export const setDefaults = function () { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
export const setDefaults = (options = {}) => { | ||
defaultOptions = { | ||
@@ -16,0 +15,0 @@ ...defaultOptions, |
import { createElement, useMemo } from 'react'; | ||
import { I18nContext } from './context.js'; | ||
export function I18nextProvider(_ref) { | ||
let { | ||
i18n, | ||
defaultNS, | ||
children | ||
} = _ref; | ||
export function I18nextProvider({ | ||
i18n, | ||
defaultNS, | ||
children | ||
}) { | ||
const value = useMemo(() => ({ | ||
@@ -10,0 +9,0 @@ i18n, |
@@ -1,1 +0,1 @@ | ||
{"type":"module","version":"14.1.3"} | ||
{"type":"module","version":"15.0.0"} |
@@ -5,19 +5,18 @@ import { useContext } from 'react'; | ||
export { nodesToString }; | ||
export function Trans(_ref) { | ||
let { | ||
children, | ||
count, | ||
parent, | ||
i18nKey, | ||
context, | ||
tOptions = {}, | ||
values, | ||
defaults, | ||
components, | ||
ns, | ||
i18n: i18nFromProps, | ||
t: tFromProps, | ||
shouldUnescape, | ||
...additionalProps | ||
} = _ref; | ||
export function Trans({ | ||
children, | ||
count, | ||
parent, | ||
i18nKey, | ||
context, | ||
tOptions = {}, | ||
values, | ||
defaults, | ||
components, | ||
ns, | ||
i18n: i18nFromProps, | ||
t: tFromProps, | ||
shouldUnescape, | ||
...additionalProps | ||
}) { | ||
const { | ||
@@ -28,3 +27,3 @@ i18n: i18nFromContext, | ||
const i18n = i18nFromProps || i18nFromContext || getI18n(); | ||
const t = tFromProps || i18n && i18n.t.bind(i18n); | ||
const t = tFromProps || i18n?.t.bind(i18n); | ||
return TransWithoutContext({ | ||
@@ -40,3 +39,3 @@ children, | ||
components, | ||
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS, | ||
ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS, | ||
i18n, | ||
@@ -43,0 +42,0 @@ t: tFromProps, |
import { useTranslation } from './useTranslation.js'; | ||
export function Translation(props) { | ||
const { | ||
ns, | ||
children, | ||
...options | ||
} = props; | ||
export const Translation = ({ | ||
ns, | ||
children, | ||
...options | ||
}) => { | ||
const [t, i18n, ready] = useTranslation(ns, options); | ||
@@ -13,2 +12,2 @@ return children(t, { | ||
}, ready); | ||
} | ||
}; |
@@ -8,3 +8,3 @@ import { Fragment, isValidElement, cloneElement, createElement, Children } from 'react'; | ||
if (!node) return false; | ||
const base = node.props ? node.props.children : node.children; | ||
const base = node.props?.children ?? node.children; | ||
if (checkLength) return base.length > 0; | ||
@@ -15,4 +15,4 @@ return !!base; | ||
if (!node) return []; | ||
const children = node.props ? node.props.children : node.children; | ||
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children; | ||
const children = node.props?.children ?? node.children; | ||
return node.props?.i18nIsDynamicList ? getAsArray(children) : children; | ||
}; | ||
@@ -32,3 +32,3 @@ const hasValidReactChildren = children => Array.isArray(children) && children.every(isValidElement); | ||
const childrenArray = getAsArray(children); | ||
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : []; | ||
const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : []; | ||
childrenArray.forEach((child, childIndex) => { | ||
@@ -97,3 +97,3 @@ if (isString(child)) { | ||
const mappedChildren = mapAST(childs, node.children, rootReactNode); | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren; | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren; | ||
}; | ||
@@ -124,3 +124,3 @@ const pushTranslatedJSX = (child, inner, mem, i, isVoid) => { | ||
return astNodes.reduce((mem, node, i) => { | ||
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
if (node.type === 'tag') { | ||
@@ -193,19 +193,18 @@ let tmp = reactNodes[parseInt(node.name, 10)]; | ||
}; | ||
export function Trans(_ref) { | ||
let { | ||
children, | ||
count, | ||
parent, | ||
i18nKey, | ||
context, | ||
tOptions = {}, | ||
values, | ||
defaults, | ||
components, | ||
ns, | ||
i18n: i18nFromProps, | ||
t: tFromProps, | ||
shouldUnescape, | ||
...additionalProps | ||
} = _ref; | ||
export function Trans({ | ||
children, | ||
count, | ||
parent, | ||
i18nKey, | ||
context, | ||
tOptions = {}, | ||
values, | ||
defaults, | ||
components, | ||
ns, | ||
i18n: i18nFromProps, | ||
t: tFromProps, | ||
shouldUnescape, | ||
...additionalProps | ||
}) { | ||
const i18n = i18nFromProps || getI18n(); | ||
@@ -219,5 +218,5 @@ if (!i18n) { | ||
...getDefaults(), | ||
...(i18n.options && i18n.options.react) | ||
...i18n.options?.react | ||
}; | ||
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || t.ns || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
@@ -230,3 +229,3 @@ const nodeAsString = nodesToString(children, reactI18nextOptions); | ||
const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue); | ||
if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) { | ||
if (i18n.options?.interpolation?.defaultVariables) { | ||
values = values && Object.keys(values).length > 0 ? { | ||
@@ -267,4 +266,4 @@ ...values, | ||
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); | ||
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; | ||
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent; | ||
return useAsParent ? createElement(useAsParent, additionalProps, content) : content; | ||
} |
import { useContext } from 'react'; | ||
import { getI18n, I18nContext } from './context.js'; | ||
export const useSSR = function (initialI18nStore, initialLanguage) { | ||
let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
export const useSSR = (initialI18nStore, initialLanguage, props = {}) => { | ||
const { | ||
@@ -12,3 +11,3 @@ i18n: i18nFromProps | ||
const i18n = i18nFromProps || i18nFromContext || getI18n(); | ||
if (i18n.options && i18n.options.isClone) return; | ||
if (i18n.options?.isClone) return; | ||
if (initialI18nStore && !i18n.initializedStoreOnce) { | ||
@@ -15,0 +14,0 @@ i18n.services.resourceStore.data = initialI18nStore; |
@@ -13,4 +13,3 @@ import { useState, useEffect, useContext, useRef, useCallback } from 'react'; | ||
const useMemoizedT = (i18n, language, namespace, keyPrefix) => useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]); | ||
export const useTranslation = function (ns) { | ||
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
export const useTranslation = (ns, props = {}) => { | ||
const { | ||
@@ -38,3 +37,3 @@ i18n: i18nFromProps | ||
} | ||
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
if (i18n.options.react?.wait) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
const i18nOptions = { | ||
@@ -49,5 +48,5 @@ ...getDefaults(), | ||
} = i18nOptions; | ||
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); | ||
i18n.reportNamespaces.addUsedNamespaces?.(namespaces); | ||
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions)); | ||
@@ -85,7 +84,7 @@ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix); | ||
}; | ||
if (bindI18n && i18n) i18n.on(bindI18n, boundReset); | ||
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); | ||
if (bindI18n) i18n?.on(bindI18n, boundReset); | ||
if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset); | ||
return () => { | ||
isMounted.current = false; | ||
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (i18n) bindI18n?.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset)); | ||
@@ -92,0 +91,0 @@ }; |
@@ -1,19 +0,13 @@ | ||
export function warn() { | ||
if (console && console.warn) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
export const warn = (...args) => { | ||
if (console?.warn) { | ||
if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`; | ||
console.warn(...args); | ||
} | ||
} | ||
}; | ||
const alreadyWarned = {}; | ||
export function warnOnce() { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
export const warnOnce = (...args) => { | ||
if (isString(args[0]) && alreadyWarned[args[0]]) return; | ||
if (isString(args[0])) alreadyWarned[args[0]] = new Date(); | ||
warn(...args); | ||
} | ||
}; | ||
const loadedClb = (i18n, cb) => () => { | ||
@@ -42,20 +36,3 @@ if (i18n.isInitialized) { | ||
}; | ||
const oldI18nextHasLoadedNamespace = function (ns, i18n) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const lng = i18n.languages[0]; | ||
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; | ||
const lastLng = i18n.languages[i18n.languages.length - 1]; | ||
if (lng.toLowerCase() === 'cimode') return true; | ||
const loadNotPending = (l, n) => { | ||
const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; | ||
return loadState === -1 || loadState === 2; | ||
}; | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false; | ||
if (i18n.hasResourceBundle(lng, ns)) return true; | ||
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true; | ||
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; | ||
return false; | ||
}; | ||
export const hasLoadedNamespace = function (ns, i18n) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
export const hasLoadedNamespace = (ns, i18n, options = {}) => { | ||
if (!i18n.languages || !i18n.languages.length) { | ||
@@ -65,10 +42,6 @@ warnOnce('i18n.languages were undefined or empty', i18n.languages); | ||
} | ||
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined; | ||
if (!isNewerI18next) { | ||
return oldI18nextHasLoadedNamespace(ns, i18n, options); | ||
} | ||
return i18n.hasLoadedNamespace(ns, { | ||
lng: options.lng, | ||
precheck: (i18nInstance, loadNotPending) => { | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
if (options.bindI18n?.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
} | ||
@@ -75,0 +48,0 @@ }); |
@@ -6,8 +6,7 @@ import { createElement } from 'react'; | ||
export const withSSR = () => function Extend(WrappedComponent) { | ||
function I18nextWithSSR(_ref) { | ||
let { | ||
initialI18nStore, | ||
initialLanguage, | ||
...rest | ||
} = _ref; | ||
function I18nextWithSSR({ | ||
initialI18nStore, | ||
initialLanguage, | ||
...rest | ||
}) { | ||
useSSR(initialI18nStore, initialLanguage); | ||
@@ -14,0 +13,0 @@ return createElement(WrappedComponent, { |
import { createElement, forwardRef as forwardRefReact } from 'react'; | ||
import { useTranslation } from './useTranslation.js'; | ||
import { getDisplayName } from './utils.js'; | ||
export const withTranslation = function (ns) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function Extend(WrappedComponent) { | ||
function I18nextWithTranslation(_ref) { | ||
let { | ||
forwardedRef, | ||
...rest | ||
} = _ref; | ||
const [t, i18n, ready] = useTranslation(ns, { | ||
...rest, | ||
keyPrefix: options.keyPrefix | ||
}); | ||
const passDownProps = { | ||
...rest, | ||
t, | ||
i18n, | ||
tReady: ready | ||
}; | ||
if (options.withRef && forwardedRef) { | ||
passDownProps.ref = forwardedRef; | ||
} else if (!options.withRef && forwardedRef) { | ||
passDownProps.forwardedRef = forwardedRef; | ||
} | ||
return createElement(WrappedComponent, passDownProps); | ||
export const withTranslation = (ns, options = {}) => function Extend(WrappedComponent) { | ||
function I18nextWithTranslation({ | ||
forwardedRef, | ||
...rest | ||
}) { | ||
const [t, i18n, ready] = useTranslation(ns, { | ||
...rest, | ||
keyPrefix: options.keyPrefix | ||
}); | ||
const passDownProps = { | ||
...rest, | ||
t, | ||
i18n, | ||
tReady: ready | ||
}; | ||
if (options.withRef && forwardedRef) { | ||
passDownProps.ref = forwardedRef; | ||
} else if (!options.withRef && forwardedRef) { | ||
passDownProps.forwardedRef = forwardedRef; | ||
} | ||
I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`; | ||
I18nextWithTranslation.WrappedComponent = WrappedComponent; | ||
const forwardRef = (props, ref) => createElement(I18nextWithTranslation, Object.assign({}, props, { | ||
forwardedRef: ref | ||
})); | ||
return options.withRef ? forwardRefReact(forwardRef) : I18nextWithTranslation; | ||
}; | ||
return createElement(WrappedComponent, passDownProps); | ||
} | ||
I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`; | ||
I18nextWithTranslation.WrappedComponent = WrappedComponent; | ||
const forwardRef = (props, ref) => createElement(I18nextWithTranslation, Object.assign({}, props, { | ||
forwardedRef: ref | ||
})); | ||
return options.withRef ? forwardRefReact(forwardRef) : I18nextWithTranslation; | ||
}; |
@@ -121,4 +121,4 @@ (function (global, factory) { | ||
function warn() { | ||
if (console && console.warn) { | ||
const warn = function () { | ||
if (console?.warn) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -130,5 +130,5 @@ args[_key] = arguments[_key]; | ||
} | ||
} | ||
}; | ||
const alreadyWarned = {}; | ||
function warnOnce() { | ||
const warnOnce = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
@@ -140,3 +140,3 @@ args[_key2] = arguments[_key2]; | ||
warn(...args); | ||
} | ||
}; | ||
const loadedClb = (i18n, cb) => () => { | ||
@@ -165,18 +165,2 @@ if (i18n.isInitialized) { | ||
}; | ||
const oldI18nextHasLoadedNamespace = function (ns, i18n) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const lng = i18n.languages[0]; | ||
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; | ||
const lastLng = i18n.languages[i18n.languages.length - 1]; | ||
if (lng.toLowerCase() === 'cimode') return true; | ||
const loadNotPending = (l, n) => { | ||
const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; | ||
return loadState === -1 || loadState === 2; | ||
}; | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false; | ||
if (i18n.hasResourceBundle(lng, ns)) return true; | ||
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true; | ||
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; | ||
return false; | ||
}; | ||
const hasLoadedNamespace = function (ns, i18n) { | ||
@@ -188,10 +172,6 @@ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
} | ||
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined; | ||
if (!isNewerI18next) { | ||
return oldI18nextHasLoadedNamespace(ns, i18n, options); | ||
} | ||
return i18n.hasLoadedNamespace(ns, { | ||
lng: options.lng, | ||
precheck: (i18nInstance, loadNotPending) => { | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
if (options.bindI18n?.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
} | ||
@@ -257,3 +237,3 @@ }); | ||
if (!node) return false; | ||
const base = node.props ? node.props.children : node.children; | ||
const base = node.props?.children ?? node.children; | ||
if (checkLength) return base.length > 0; | ||
@@ -264,4 +244,4 @@ return !!base; | ||
if (!node) return []; | ||
const children = node.props ? node.props.children : node.children; | ||
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children; | ||
const children = node.props?.children ?? node.children; | ||
return node.props?.i18nIsDynamicList ? getAsArray(children) : children; | ||
}; | ||
@@ -281,3 +261,3 @@ const hasValidReactChildren = children => Array.isArray(children) && children.every(react.isValidElement); | ||
const childrenArray = getAsArray(children); | ||
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : []; | ||
const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : []; | ||
childrenArray.forEach((child, childIndex) => { | ||
@@ -346,3 +326,3 @@ if (isString(child)) { | ||
const mappedChildren = mapAST(childs, node.children, rootReactNode); | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren; | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren; | ||
}; | ||
@@ -373,3 +353,3 @@ const pushTranslatedJSX = (child, inner, mem, i, isVoid) => { | ||
return astNodes.reduce((mem, node, i) => { | ||
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
if (node.type === 'tag') { | ||
@@ -467,5 +447,5 @@ let tmp = reactNodes[parseInt(node.name, 10)]; | ||
...getDefaults(), | ||
...(i18n.options && i18n.options.react) | ||
...i18n.options?.react | ||
}; | ||
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || t.ns || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
@@ -478,3 +458,3 @@ const nodeAsString = nodesToString(children, reactI18nextOptions); | ||
const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue); | ||
if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) { | ||
if (i18n.options?.interpolation?.defaultVariables) { | ||
values = values && Object.keys(values).length > 0 ? { | ||
@@ -515,3 +495,3 @@ ...values, | ||
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); | ||
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; | ||
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent; | ||
return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content; | ||
@@ -535,3 +515,3 @@ } | ||
namespaces.forEach(ns => { | ||
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true; | ||
this.usedNamespaces[ns] ??= true; | ||
}); | ||
@@ -542,3 +522,3 @@ } | ||
const composeInitialProps = ForComponent => async ctx => { | ||
const componentsInitialProps = ForComponent.getInitialProps ? await ForComponent.getInitialProps(ctx) : {}; | ||
const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {}; | ||
const i18nInitialProps = getInitialProps(); | ||
@@ -552,3 +532,3 @@ return { | ||
const i18n = getI18n(); | ||
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; | ||
const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? []; | ||
const ret = {}; | ||
@@ -589,3 +569,3 @@ const initialI18nStore = {}; | ||
const i18n = i18nFromProps || i18nFromContext || getI18n(); | ||
const t = tFromProps || i18n && i18n.t.bind(i18n); | ||
const t = tFromProps || i18n?.t.bind(i18n); | ||
return Trans$1({ | ||
@@ -601,3 +581,3 @@ children, | ||
components, | ||
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS, | ||
ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS, | ||
i18n, | ||
@@ -613,3 +593,3 @@ t: tFromProps, | ||
react.useEffect(() => { | ||
ref.current = ignore ? ref.current : value; | ||
ref.current = value; | ||
}, [value, ignore]); | ||
@@ -644,3 +624,3 @@ return ref.current; | ||
} | ||
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
if (i18n.options.react?.wait) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
const i18nOptions = { | ||
@@ -655,5 +635,5 @@ ...getDefaults(), | ||
} = i18nOptions; | ||
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); | ||
i18n.reportNamespaces.addUsedNamespaces?.(namespaces); | ||
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions)); | ||
@@ -691,7 +671,7 @@ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix); | ||
}; | ||
if (bindI18n && i18n) i18n.on(bindI18n, boundReset); | ||
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); | ||
if (bindI18n) i18n?.on(bindI18n, boundReset); | ||
if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset); | ||
return () => { | ||
isMounted.current = false; | ||
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (i18n) bindI18n?.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset)); | ||
@@ -754,8 +734,8 @@ }; | ||
function Translation(props) { | ||
const { | ||
const Translation = _ref => { | ||
let { | ||
ns, | ||
children, | ||
...options | ||
} = props; | ||
} = _ref; | ||
const [t, i18n, ready] = useTranslation(ns, options); | ||
@@ -766,3 +746,3 @@ return children(t, { | ||
}, ready); | ||
} | ||
}; | ||
@@ -793,3 +773,3 @@ function I18nextProvider(_ref) { | ||
const i18n = i18nFromProps || i18nFromContext || getI18n(); | ||
if (i18n.options && i18n.options.isClone) return; | ||
if (i18n.options?.isClone) return; | ||
if (initialI18nStore && !i18n.initializedStoreOnce) { | ||
@@ -796,0 +776,0 @@ i18n.services.resourceStore.data = initialI18nStore; |
@@ -1,1 +0,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}),i=/\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 o=new RegExp(i),r=null;null!==(r=o.exec(e));)if(r[0].trim())if(r[1]){var l=r[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],o.lastIndex--}else r[2]&&(n.attrs[r[2]]=r[3].trim().substring(1,r[3].length-1));return n}var o=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,r=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],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(o,(function(o,l){if(u){if(o!=="</"+t.name+">")return;u=!1}var p,d="/"!==o.charAt(1),f=o.startsWith("\x3c!--"),g=l+o.length,h=e.charAt(g);if(f){var m=a(o);return c<0?(s.push(m),s):((p=i[c]).children.push(m),s)}if(d&&(c++,"tag"===(t=a(o)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===c&&s.push(t),(p=i[c-1])&&p.children.push(t),i[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===o.slice(2,-1))&&(c--,t=-1===c?s:i[c]),!u&&"<"!==h&&h)){p=-1===c?s:i[c].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);r.test(b)&&(b=" "),(y>-1&&c+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s};function u(){if(console&&console.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}}const p={};function d(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&p[n[0]]||(y(n[0])&&(p[n[0]]=new Date),u(...n))}const f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},g=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},h=(e,n,t,s)=>{y(t)&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},m=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,b=e=>"object"==typeof e&&null!==e,v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},E=e=>x[e];let N={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,E)};const O=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N={...N,...e}},$=()=>N;let k;const w=e=>{k=e},I=()=>k,S=(e,n)=>{if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t},C=e=>{if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],j=(e,t)=>{if(!e)return"";let s="";const i=R(e),a=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return i.forEach(((e,i)=>{if(y(e))s+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:o}=e,r=Object.keys(n).length,l=a.indexOf(o)>-1,c=n.children;if(c||!l||r)if(!c&&(!l||r)||n.i18nIsDynamicList)s+=`<${i}></${i}>`;else if(l&&1===r&&y(c))s+=`<${o}>${c}</${o}>`;else{const e=j(c,t);s+=`<${i}>${e}</${i}>`}else s+=`<${o}/>`}else if(null===e)u("Trans: the passed in value is invalid - seems you passed in a null child.");else if(b(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];s+=`{{${e}}}`}else u("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else u("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",e)})),s},T=(e,t,s,i,a,o)=>{if(""===t)return[];const r=i.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(r.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!o)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(S(e)?p(C(e)):b(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},g=(e,t,s)=>{const i=C(e),a=m(i,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(i)&&0===a.length||e.props&&e.props.i18nIsDynamicList?i:a},h=(e,t,s,i,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:i},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:i,ref:e.ref},a?null:t)})))},m=(t,a,c)=>{const u=R(t);return R(a).reduce(((t,a,p)=>{const d=a.children&&a.children[0]&&a.children[0].content&&s.services.interpolator.interpolate(a.children[0].content,f,s.language);if("tag"===a.type){let o=u[parseInt(a.name,10)];1!==c.length||o||(o=c[0][a.name]),o||(o={});const v=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},o):o,x=n.isValidElement(v),E=x&&S(a,!0)&&!a.voidElement,N=l&&b(v)&&v.dummy&&!x,O=b(e)&&Object.hasOwnProperty.call(e,a.name);if(y(v)){const e=s.services.interpolator.interpolate(v,f,s.language);t.push(e)}else if(S(v)||E){const e=g(v,a,c);h(v,e,t,p)}else if(N){const e=m(u,a.children,c);h(v,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(O){const e=g(v,a,c);h(v,e,t,p,a.voidElement)}else if(i.transSupportBasicHtmlNodes&&r.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=m(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=m(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(b(v)&&!x){const e=a.children[0]?d:null;e&&t.push(e)}else h(v,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=i.transWrapTextNodes,r=o?i.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}`},r)):t.push(r)}return t}),[])},v=m([{dummy:!0,children:e||[]}],d,R(e||[]));return C(v[0])};function L(e){let{children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r={},values:l,defaults:c,components:u,ns:p,i18n:f,t:g,shouldUnescape:h,...m}=e;const b=f||I();if(!b)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const v=g||b.t.bind(b)||(e=>e),x={...$(),...b.options&&b.options.react};let E=p||v.ns||b.options&&b.options.defaultNS;E=y(E)?[E]:E||["translation"];const N=j(t,x),O=c||N||x.transEmptyNodeValue||a,{hashTransKey:k}=x,w=a||(k?k(N||O):N||O);b.options&&b.options.interpolation&&b.options.interpolation.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...b.options.interpolation.defaultVariables}:{...b.options.interpolation.defaultVariables});const S=l||void 0!==s||!t?r.interpolation:{interpolation:{...r.interpolation,prefix:"#$?",suffix:"?$#"}},C={...r,context:o||r.context,count:s,...l,...S,defaultValue:O,ns:E},R=w?v(w,C):O;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||R.indexOf(`${e}/>`)<0&&R.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const L=T(u||t,R,b,x,C,h),P=void 0!==i?i:x.defaultTransParent;return P?n.createElement(P,m,L):L}const P={type:"3rdParty",init(e){O(e.options.react),w(e)}},A=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces=()=>Object.keys(this.usedNamespaces)}const z=e=>async n=>({...e.getInitialProps?await e.getInitialProps(n):{},...B()}),B=()=>{const e=I(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const F=(e,n,t,s)=>e.getFixedT(n,t,s),U=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:a}=n.useContext(A)||{},o=s||i||I();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new V),!o){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:b(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}o.options.react&&void 0!==o.options.react.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const r={...$(),...o.options.react,...t},{useSuspense:l,keyPrefix:c}=r;let u=e||a||o.options&&o.options.defaultNS;u=y(u)?[u]:u||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(u);const p=(o.isInitialized||o.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?void 0!==n.options.ignoreJSONStructure?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=n.languages[n.languages.length-1];if("cimode"===s.toLowerCase())return!0;const o=(e,t)=>{const s=n.services.backendConnector.state[`${e}|${t}`];return-1===s||2===s};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e)||!n.hasResourceBundle(s,e)&&n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages)&&(!o(s,e)||i&&!o(a,e)))}(e,n,t):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,o,r))),f=((e,t,s,i)=>n.useCallback(F(e,t,s,i),[e,t,s,i]))(o,t.lng||null,"fallback"===r.nsMode?u:u[0],c),m=()=>f,v=()=>F(o,t.lng||null,"fallback"===r.nsMode?u:u[0],c),[x,E]=n.useState(m);let N=u.join();t.lng&&(N=`${t.lng}${N}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current})(N),k=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=r;k.current=!0,p||l||(t.lng?h(o,t.lng,u,(()=>{k.current&&E(v)})):g(o,u,(()=>{k.current&&E(v)}))),p&&O&&O!==N&&k.current&&E(v);const s=()=>{k.current&&E(v)};return e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{k.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,N]),n.useEffect((()=>{k.current&&p&&E(m)}),[o,c,p]);const w=[x,o,p];if(w.t=x,w.i18n=o,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?h(o,t.lng,u,(()=>e())):g(o,u,(()=>e()))}))};const K=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:i}=s,{i18n:a}=n.useContext(A)||{},o=i||a||I();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))};e.I18nContext=A,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:i}=e;const a=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(A.Provider,{value:a},i)},e.Trans=function(e){let{children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(A)||{},b=d||m||I(),v=f||b&&b.t.bind(b);return L({children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r,values:l,defaults:c,components:u,ns:p||v&&v.ns||y||b&&b.options&&b.options.defaultNS,i18n:b,t:f,shouldUnescape:g,...h})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,a,o]=U(n,s);return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=I,e.getInitialProps=B,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=K,e.useTranslation=U,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:i,...a}=t;return K(s,i),n.createElement(e,{...a})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${m(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function i(i){let{forwardedRef:a,...o}=i;const[r,l,c]=U(e,{...o,keyPrefix:t.keyPrefix}),u={...o,t:r,i18n:l,tReady:c};return t.withRef&&a?u.ref=a:!t.withRef&&a&&(u.forwardedRef=a),n.createElement(s,u)}i.displayName=`withI18nextTranslation(${m(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}})); | ||
!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}),i=/\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 r=new RegExp(i),o=null;null!==(o=r.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],r.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(r,(function(r,l){if(u){if(r!=="</"+t.name+">")return;u=!1}var p,d="/"!==r.charAt(1),f=r.startsWith("\x3c!--"),h=l+r.length,m=e.charAt(h);if(f){var g=a(r);return c<0?(s.push(g),s):((p=i[c]).children.push(g),s)}if(d&&(c++,"tag"===(t=a(r)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!m||"<"===m||t.children.push({type:"text",content:e.slice(h,e.indexOf("<",h))}),0===c&&s.push(t),(p=i[c-1])&&p.children.push(t),i[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===r.slice(2,-1))&&(c--,t=-1===c?s:i[c]),!u&&"<"!==m&&m)){p=-1===c?s:i[c].children;var y=e.indexOf("<",h),x=e.slice(h,-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=function(){if(console?.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}},p={},d=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&p[n[0]]||(y(n[0])&&(p[n[0]]=new Date),u(...n))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},h=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},m=(e,n,t,s)=>{y(t)&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},g=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,b=/&(?: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 O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(b,E)};const N=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}},$=()=>O;let w;const I=e=>{w=e},k=()=>w,S=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},j=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],T=(e,t)=>{if(!e)return"";let s="";const i=R(e),a=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))s+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:r}=e,o=Object.keys(n).length,l=a.indexOf(r)>-1,c=n.children;if(c||!l||o)if(!c&&(!l||o)||n.i18nIsDynamicList)s+=`<${i}></${i}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}</${r}>`;else{const e=T(c,t);s+=`<${i}>${e}</${i}>`}else s+=`<${r}/>`}else if(null===e)u("Trans: the passed in value is invalid - seems you passed in a null child.");else if(x(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];s+=`{{${e}}}`}else u("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else u("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",e)})),s},C=(e,t,s,i,a,r)=>{if(""===t)return[];const o=i.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!r)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(S(e)?p(j(e)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},h=(e,t,s)=>{const i=j(e),a=g(i,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(i)&&0===a.length||e.props?.i18nIsDynamicList?i:a},m=(e,t,s,i,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:i},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:i,ref:e.ref},a?null:t)})))},g=(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 r=u[parseInt(a.name,10)];1!==c.length||r||(r=c[0][a.name]),r||(r={});const b=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},r):r,v=n.isValidElement(b),E=v&&S(a,!0)&&!a.voidElement,O=l&&x(b)&&b.dummy&&!v,N=x(e)&&Object.hasOwnProperty.call(e,a.name);if(y(b)){const e=s.services.interpolator.interpolate(b,f,s.language);t.push(e)}else if(S(b)||E){const e=h(b,a,c);m(b,e,t,p)}else if(O){const e=g(u,a.children,c);m(b,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(N){const e=h(b,a,c);m(b,e,t,p,a.voidElement)}else if(i.transSupportBasicHtmlNodes&&o.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=g(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=g(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(x(b)&&!v){const e=a.children[0]?d:null;e&&t.push(e)}else m(b,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=i.transWrapTextNodes,o=r?i.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}),[])},b=g([{dummy:!0,children:e||[]}],d,R(e||[]));return j(b[0])};function P(e){let{children:t,count:s,parent:i,i18nKey:a,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:h,shouldUnescape:m,...g}=e;const x=f||k();if(!x)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=h||x.t.bind(x)||(e=>e),v={...$(),...x.options?.react};let E=p||b.ns||x.options?.defaultNS;E=y(E)?[E]:E||["translation"];const O=T(t,v),N=c||O||v.transEmptyNodeValue||a,{hashTransKey:w}=v,I=a||(w?w(O||N):O||N);x.options?.interpolation?.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...x.options.interpolation.defaultVariables}:{...x.options.interpolation.defaultVariables});const S=l||void 0!==s||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},j={...o,context:r||o.context,count:s,...l,...S,defaultValue:N,ns:E},R=I?b(I,j):N;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||R.indexOf(`${e}/>`)<0&&R.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const P=C(u||t,R,x,v,j,m),L=i??v.defaultTransParent;return L?n.createElement(L,g,P):P}const L={type:"3rdParty",init(e){N(e.options.react),I(e)}},A=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]??=!0}))}getUsedNamespaces=()=>Object.keys(this.usedNamespaces)}const z=e=>async n=>({...await(e.getInitialProps?.(n))??{},...F()}),F=()=>{const e=k(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),B=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:a}=n.useContext(A)||{},r=s||i||k();if(r&&!r.reportNamespaces&&(r.reportNamespaces=new V),!r){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n: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}r.options.react?.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...$(),...r.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||r.options?.defaultNS;u=y(u)?[u]:u||["translation"],r.reportNamespaces.addUsedNamespaces?.(u);const p=(r.isInitialized||r.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,r,o))),f=((e,t,s,i)=>n.useCallback(U(e,t,s,i),[e,t,s,i]))(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),g=()=>f,b=()=>U(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[v,E]=n.useState(g);let O=u.join();t.lng&&(O=`${t.lng}${O}`);const N=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(O),w=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;w.current=!0,p||l||(t.lng?m(r,t.lng,u,(()=>{w.current&&E(b)})):h(r,u,(()=>{w.current&&E(b)}))),p&&N&&N!==O&&w.current&&E(b);const s=()=>{w.current&&E(b)};return e&&r?.on(e,s),n&&r?.store.on(n,s),()=>{w.current=!1,r&&e?.split(" ").forEach((e=>r.off(e,s))),n&&r&&n.split(" ").forEach((e=>r.store.off(e,s)))}}),[r,O]),n.useEffect((()=>{w.current&&p&&E(g)}),[r,c,p]);const I=[v,r,p];if(I.t=v,I.i18n=r,I.ready=p,p)return I;if(!p&&!l)return I;throw new Promise((e=>{t.lng?m(r,t.lng,u,(()=>e())):h(r,u,(()=>e()))}))};const D=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:i}=s,{i18n:a}=n.useContext(A)||{},r=i||a||k();r.options?.isClone||(e&&!r.initializedStoreOnce&&(r.services.resourceStore.data=e,r.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),r.options.ns),r.initializedStoreOnce=!0,r.isInitialized=!0),t&&!r.initializedLanguageOnce&&(r.changeLanguage(t),r.initializedLanguageOnce=!0))};e.I18nContext=A,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:i}=e;const a=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(A.Provider,{value:a},i)},e.Trans=function(e){let{children:t,count:s,parent:i,i18nKey:a,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:h,...m}=e;const{i18n:g,defaultNS:y}=n.useContext(A)||{},x=d||g||k(),b=f||x?.t.bind(x);return P({children:t,count:s,parent:i,i18nKey:a,context:r,tOptions:o,values:l,defaults:c,components:u,ns:p||b?.ns||y||x?.options?.defaultNS,i18n:x,t:f,shouldUnescape:h,...m})},e.TransWithoutContext=P,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[i,a,r]=B(n,s);return t(i,{i18n:a,lng:a.language},r)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=k,e.getInitialProps=F,e.initReactI18next=L,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=N,e.setI18n=I,e.time=()=>"",e.useSSR=D,e.useTranslation=B,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:i,...a}=t;return D(s,i),n.createElement(e,{...a})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${g(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function i(i){let{forwardedRef:a,...r}=i;const[o,l,c]=B(e,{...r,keyPrefix:t.keyPrefix}),u={...r,t:o,i18n:l,tReady:c};return t.withRef&&a?u.ref=a:!t.withRef&&a&&(u.forwardedRef=a),n.createElement(s,u)}i.displayName=`withI18nextTranslation(${g(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}})); |
@@ -36,7 +36,7 @@ import { ReactElement } from 'react'; | ||
: // this supports infinite $0={..} or $123={..} | ||
// technically it also supports $-1={..} and $2.3={..} but we don't need to | ||
// worry since that's invalid syntax. | ||
P extends `$${number}` | ||
? string | ReactElement | ||
: never; | ||
// technically it also supports $-1={..} and $2.3={..} but we don't need to | ||
// worry since that's invalid syntax. | ||
P extends `$${number}` | ||
? string | ReactElement | ||
: never; | ||
}; | ||
@@ -43,0 +43,0 @@ |
@@ -98,4 +98,4 @@ import type { $Subtract, $Tuple } from './helpers.js'; | ||
: Ns extends Namespace | ||
? Ns | ||
: _DefaultNamespace; | ||
? Ns | ||
: _DefaultNamespace; | ||
@@ -102,0 +102,0 @@ export function useTranslation< |
{ | ||
"name": "react-i18next", | ||
"version": "14.1.3", | ||
"version": "15.0.0", | ||
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.", | ||
@@ -67,19 +67,19 @@ "main": "dist/commonjs/index.js", | ||
"dependencies": { | ||
"@babel/runtime": "^7.23.9", | ||
"@babel/runtime": "^7.24.8", | ||
"html-parse-stringify": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.23.9", | ||
"@babel/core": "^7.23.9", | ||
"@babel/eslint-parser": "^7.23.10", | ||
"@babel/plugin-proposal-async-generator-functions": "^7.20.5", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.20.5", | ||
"@babel/plugin-transform-modules-commonjs": "^7.23.3", | ||
"@babel/plugin-transform-runtime": "^7.23.9", | ||
"@babel/polyfill": "^7.2.5", | ||
"@babel/preset-env": "^7.23.9", | ||
"@babel/preset-react": "^7.23.3", | ||
"@babel/register": "^7.23.7", | ||
"@babel/cli": "^7.24.8", | ||
"@babel/core": "^7.24.9", | ||
"@babel/eslint-parser": "^7.24.8", | ||
"@babel/plugin-proposal-async-generator-functions": "^7.20.7", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.20.7", | ||
"@babel/plugin-transform-modules-commonjs": "^7.24.8", | ||
"@babel/plugin-transform-runtime": "^7.24.7", | ||
"@babel/polyfill": "^7.12.1", | ||
"@babel/preset-env": "^7.24.8", | ||
"@babel/preset-react": "^7.24.7", | ||
"@babel/register": "^7.24.6", | ||
"@rollup/plugin-babel": "^6.0.4", | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-commonjs": "^26.0.1", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
@@ -110,11 +110,11 @@ "@rollup/plugin-replace": "^5.0.5", | ||
"husky": "^8.0.3", | ||
"i18next": "^23.11.5", | ||
"lint-staged": "^8.1.3", | ||
"i18next": "^23.12.1", | ||
"lint-staged": "^15.2.7", | ||
"mkdirp": "^1.0.4", | ||
"prettier": "2.8.8", | ||
"prettier": "^3.3.3", | ||
"react": "^16.14.0", | ||
"react-dom": "^16.14.0", | ||
"react-test-renderer": "^16.14.0", | ||
"rimraf": "2.6.3", | ||
"rollup": "3.25.1", | ||
"rimraf": "^6.0.1", | ||
"rollup": "^4.18.1", | ||
"typescript": "5.3.3", | ||
@@ -142,3 +142,3 @@ "vitest": "1.2.2", | ||
"copy": "cp-cli ./dist/umd/react-i18next.min.js ./react-i18next.min.js && cp-cli ./dist/umd/react-i18next.js ./react-i18next.js && echo '{\"type\":\"module\"}' > dist/es/package.json", | ||
"build:es": "cross-env BABEL_ENV=jsnext babel src --out-dir dist/es", | ||
"build:es": "cross-env BABEL_ENV=ESNext babel src --out-dir dist/es", | ||
"build:cjs": "babel src --out-dir dist/commonjs", | ||
@@ -162,12 +162,5 @@ "build:umd": "rollup -c rollup.config.mjs --format umd && rollup -c rollup.config.mjs --format umd --uglify", | ||
"lint-staged": { | ||
"linters": { | ||
"*.{mts,ts,tsx,js,json,md}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"ignore": [ | ||
"**/dist/**/*.js", | ||
"**/react-i18next.js", | ||
"**/react-i18next.min.js" | ||
"*.{mts,ts,tsx,js,json,md}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
@@ -174,0 +167,0 @@ }, |
@@ -121,4 +121,4 @@ (function (global, factory) { | ||
function warn() { | ||
if (console && console.warn) { | ||
const warn = function () { | ||
if (console?.warn) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -130,5 +130,5 @@ args[_key] = arguments[_key]; | ||
} | ||
} | ||
}; | ||
const alreadyWarned = {}; | ||
function warnOnce() { | ||
const warnOnce = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
@@ -140,3 +140,3 @@ args[_key2] = arguments[_key2]; | ||
warn(...args); | ||
} | ||
}; | ||
const loadedClb = (i18n, cb) => () => { | ||
@@ -165,18 +165,2 @@ if (i18n.isInitialized) { | ||
}; | ||
const oldI18nextHasLoadedNamespace = function (ns, i18n) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const lng = i18n.languages[0]; | ||
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; | ||
const lastLng = i18n.languages[i18n.languages.length - 1]; | ||
if (lng.toLowerCase() === 'cimode') return true; | ||
const loadNotPending = (l, n) => { | ||
const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; | ||
return loadState === -1 || loadState === 2; | ||
}; | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false; | ||
if (i18n.hasResourceBundle(lng, ns)) return true; | ||
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true; | ||
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; | ||
return false; | ||
}; | ||
const hasLoadedNamespace = function (ns, i18n) { | ||
@@ -188,10 +172,6 @@ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
} | ||
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined; | ||
if (!isNewerI18next) { | ||
return oldI18nextHasLoadedNamespace(ns, i18n, options); | ||
} | ||
return i18n.hasLoadedNamespace(ns, { | ||
lng: options.lng, | ||
precheck: (i18nInstance, loadNotPending) => { | ||
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
if (options.bindI18n?.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; | ||
} | ||
@@ -257,3 +237,3 @@ }); | ||
if (!node) return false; | ||
const base = node.props ? node.props.children : node.children; | ||
const base = node.props?.children ?? node.children; | ||
if (checkLength) return base.length > 0; | ||
@@ -264,4 +244,4 @@ return !!base; | ||
if (!node) return []; | ||
const children = node.props ? node.props.children : node.children; | ||
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children; | ||
const children = node.props?.children ?? node.children; | ||
return node.props?.i18nIsDynamicList ? getAsArray(children) : children; | ||
}; | ||
@@ -281,3 +261,3 @@ const hasValidReactChildren = children => Array.isArray(children) && children.every(react.isValidElement); | ||
const childrenArray = getAsArray(children); | ||
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : []; | ||
const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : []; | ||
childrenArray.forEach((child, childIndex) => { | ||
@@ -346,3 +326,3 @@ if (isString(child)) { | ||
const mappedChildren = mapAST(childs, node.children, rootReactNode); | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren; | ||
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren; | ||
}; | ||
@@ -373,3 +353,3 @@ const pushTranslatedJSX = (child, inner, mem, i, isVoid) => { | ||
return astNodes.reduce((mem, node, i) => { | ||
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
if (node.type === 'tag') { | ||
@@ -467,5 +447,5 @@ let tmp = reactNodes[parseInt(node.name, 10)]; | ||
...getDefaults(), | ||
...(i18n.options && i18n.options.react) | ||
...i18n.options?.react | ||
}; | ||
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || t.ns || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
@@ -478,3 +458,3 @@ const nodeAsString = nodesToString(children, reactI18nextOptions); | ||
const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue); | ||
if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) { | ||
if (i18n.options?.interpolation?.defaultVariables) { | ||
values = values && Object.keys(values).length > 0 ? { | ||
@@ -515,3 +495,3 @@ ...values, | ||
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); | ||
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; | ||
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent; | ||
return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content; | ||
@@ -535,3 +515,3 @@ } | ||
namespaces.forEach(ns => { | ||
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true; | ||
this.usedNamespaces[ns] ??= true; | ||
}); | ||
@@ -542,3 +522,3 @@ } | ||
const composeInitialProps = ForComponent => async ctx => { | ||
const componentsInitialProps = ForComponent.getInitialProps ? await ForComponent.getInitialProps(ctx) : {}; | ||
const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {}; | ||
const i18nInitialProps = getInitialProps(); | ||
@@ -552,3 +532,3 @@ return { | ||
const i18n = getI18n(); | ||
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; | ||
const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? []; | ||
const ret = {}; | ||
@@ -589,3 +569,3 @@ const initialI18nStore = {}; | ||
const i18n = i18nFromProps || i18nFromContext || getI18n(); | ||
const t = tFromProps || i18n && i18n.t.bind(i18n); | ||
const t = tFromProps || i18n?.t.bind(i18n); | ||
return Trans$1({ | ||
@@ -601,3 +581,3 @@ children, | ||
components, | ||
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS, | ||
ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS, | ||
i18n, | ||
@@ -613,3 +593,3 @@ t: tFromProps, | ||
react.useEffect(() => { | ||
ref.current = ignore ? ref.current : value; | ||
ref.current = value; | ||
}, [value, ignore]); | ||
@@ -644,3 +624,3 @@ return ref.current; | ||
} | ||
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
if (i18n.options.react?.wait) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); | ||
const i18nOptions = { | ||
@@ -655,5 +635,5 @@ ...getDefaults(), | ||
} = i18nOptions; | ||
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; | ||
let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); | ||
i18n.reportNamespaces.addUsedNamespaces?.(namespaces); | ||
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions)); | ||
@@ -691,7 +671,7 @@ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix); | ||
}; | ||
if (bindI18n && i18n) i18n.on(bindI18n, boundReset); | ||
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); | ||
if (bindI18n) i18n?.on(bindI18n, boundReset); | ||
if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset); | ||
return () => { | ||
isMounted.current = false; | ||
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (i18n) bindI18n?.split(' ').forEach(e => i18n.off(e, boundReset)); | ||
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset)); | ||
@@ -754,8 +734,8 @@ }; | ||
function Translation(props) { | ||
const { | ||
const Translation = _ref => { | ||
let { | ||
ns, | ||
children, | ||
...options | ||
} = props; | ||
} = _ref; | ||
const [t, i18n, ready] = useTranslation(ns, options); | ||
@@ -766,3 +746,3 @@ return children(t, { | ||
}, ready); | ||
} | ||
}; | ||
@@ -793,3 +773,3 @@ function I18nextProvider(_ref) { | ||
const i18n = i18nFromProps || i18nFromContext || getI18n(); | ||
if (i18n.options && i18n.options.isClone) return; | ||
if (i18n.options?.isClone) return; | ||
if (initialI18nStore && !i18n.initializedStoreOnce) { | ||
@@ -796,0 +776,0 @@ i18n.services.resourceStore.data = initialI18nStore; |
@@ -1,1 +0,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}),i=/\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 o=new RegExp(i),r=null;null!==(r=o.exec(e));)if(r[0].trim())if(r[1]){var l=r[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],o.lastIndex--}else r[2]&&(n.attrs[r[2]]=r[3].trim().substring(1,r[3].length-1));return n}var o=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,r=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],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(o,(function(o,l){if(u){if(o!=="</"+t.name+">")return;u=!1}var p,d="/"!==o.charAt(1),f=o.startsWith("\x3c!--"),g=l+o.length,h=e.charAt(g);if(f){var m=a(o);return c<0?(s.push(m),s):((p=i[c]).children.push(m),s)}if(d&&(c++,"tag"===(t=a(o)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===c&&s.push(t),(p=i[c-1])&&p.children.push(t),i[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===o.slice(2,-1))&&(c--,t=-1===c?s:i[c]),!u&&"<"!==h&&h)){p=-1===c?s:i[c].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);r.test(b)&&(b=" "),(y>-1&&c+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s};function u(){if(console&&console.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}}const p={};function d(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&p[n[0]]||(y(n[0])&&(p[n[0]]=new Date),u(...n))}const f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},g=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},h=(e,n,t,s)=>{y(t)&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},m=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,b=e=>"object"==typeof e&&null!==e,v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},E=e=>x[e];let N={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,E)};const O=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N={...N,...e}},$=()=>N;let k;const w=e=>{k=e},I=()=>k,S=(e,n)=>{if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t},C=e=>{if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],j=(e,t)=>{if(!e)return"";let s="";const i=R(e),a=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return i.forEach(((e,i)=>{if(y(e))s+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:o}=e,r=Object.keys(n).length,l=a.indexOf(o)>-1,c=n.children;if(c||!l||r)if(!c&&(!l||r)||n.i18nIsDynamicList)s+=`<${i}></${i}>`;else if(l&&1===r&&y(c))s+=`<${o}>${c}</${o}>`;else{const e=j(c,t);s+=`<${i}>${e}</${i}>`}else s+=`<${o}/>`}else if(null===e)u("Trans: the passed in value is invalid - seems you passed in a null child.");else if(b(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];s+=`{{${e}}}`}else u("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else u("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",e)})),s},T=(e,t,s,i,a,o)=>{if(""===t)return[];const r=i.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(r.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!o)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(S(e)?p(C(e)):b(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},g=(e,t,s)=>{const i=C(e),a=m(i,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(i)&&0===a.length||e.props&&e.props.i18nIsDynamicList?i:a},h=(e,t,s,i,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:i},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:i,ref:e.ref},a?null:t)})))},m=(t,a,c)=>{const u=R(t);return R(a).reduce(((t,a,p)=>{const d=a.children&&a.children[0]&&a.children[0].content&&s.services.interpolator.interpolate(a.children[0].content,f,s.language);if("tag"===a.type){let o=u[parseInt(a.name,10)];1!==c.length||o||(o=c[0][a.name]),o||(o={});const v=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},o):o,x=n.isValidElement(v),E=x&&S(a,!0)&&!a.voidElement,N=l&&b(v)&&v.dummy&&!x,O=b(e)&&Object.hasOwnProperty.call(e,a.name);if(y(v)){const e=s.services.interpolator.interpolate(v,f,s.language);t.push(e)}else if(S(v)||E){const e=g(v,a,c);h(v,e,t,p)}else if(N){const e=m(u,a.children,c);h(v,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(O){const e=g(v,a,c);h(v,e,t,p,a.voidElement)}else if(i.transSupportBasicHtmlNodes&&r.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=m(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=m(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(b(v)&&!x){const e=a.children[0]?d:null;e&&t.push(e)}else h(v,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=i.transWrapTextNodes,r=o?i.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}`},r)):t.push(r)}return t}),[])},v=m([{dummy:!0,children:e||[]}],d,R(e||[]));return C(v[0])};function L(e){let{children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r={},values:l,defaults:c,components:u,ns:p,i18n:f,t:g,shouldUnescape:h,...m}=e;const b=f||I();if(!b)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const v=g||b.t.bind(b)||(e=>e),x={...$(),...b.options&&b.options.react};let E=p||v.ns||b.options&&b.options.defaultNS;E=y(E)?[E]:E||["translation"];const N=j(t,x),O=c||N||x.transEmptyNodeValue||a,{hashTransKey:k}=x,w=a||(k?k(N||O):N||O);b.options&&b.options.interpolation&&b.options.interpolation.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...b.options.interpolation.defaultVariables}:{...b.options.interpolation.defaultVariables});const S=l||void 0!==s||!t?r.interpolation:{interpolation:{...r.interpolation,prefix:"#$?",suffix:"?$#"}},C={...r,context:o||r.context,count:s,...l,...S,defaultValue:O,ns:E},R=w?v(w,C):O;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||R.indexOf(`${e}/>`)<0&&R.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const L=T(u||t,R,b,x,C,h),P=void 0!==i?i:x.defaultTransParent;return P?n.createElement(P,m,L):L}const P={type:"3rdParty",init(e){O(e.options.react),w(e)}},A=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces=()=>Object.keys(this.usedNamespaces)}const z=e=>async n=>({...e.getInitialProps?await e.getInitialProps(n):{},...B()}),B=()=>{const e=I(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const F=(e,n,t,s)=>e.getFixedT(n,t,s),U=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:a}=n.useContext(A)||{},o=s||i||I();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new V),!o){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:b(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}o.options.react&&void 0!==o.options.react.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const r={...$(),...o.options.react,...t},{useSuspense:l,keyPrefix:c}=r;let u=e||a||o.options&&o.options.defaultNS;u=y(u)?[u]:u||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(u);const p=(o.isInitialized||o.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?void 0!==n.options.ignoreJSONStructure?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=n.languages[n.languages.length-1];if("cimode"===s.toLowerCase())return!0;const o=(e,t)=>{const s=n.services.backendConnector.state[`${e}|${t}`];return-1===s||2===s};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e)||!n.hasResourceBundle(s,e)&&n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages)&&(!o(s,e)||i&&!o(a,e)))}(e,n,t):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,o,r))),f=((e,t,s,i)=>n.useCallback(F(e,t,s,i),[e,t,s,i]))(o,t.lng||null,"fallback"===r.nsMode?u:u[0],c),m=()=>f,v=()=>F(o,t.lng||null,"fallback"===r.nsMode?u:u[0],c),[x,E]=n.useState(m);let N=u.join();t.lng&&(N=`${t.lng}${N}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current})(N),k=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=r;k.current=!0,p||l||(t.lng?h(o,t.lng,u,(()=>{k.current&&E(v)})):g(o,u,(()=>{k.current&&E(v)}))),p&&O&&O!==N&&k.current&&E(v);const s=()=>{k.current&&E(v)};return e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{k.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,N]),n.useEffect((()=>{k.current&&p&&E(m)}),[o,c,p]);const w=[x,o,p];if(w.t=x,w.i18n=o,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?h(o,t.lng,u,(()=>e())):g(o,u,(()=>e()))}))};const K=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:i}=s,{i18n:a}=n.useContext(A)||{},o=i||a||I();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))};e.I18nContext=A,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:i}=e;const a=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(A.Provider,{value:a},i)},e.Trans=function(e){let{children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(A)||{},b=d||m||I(),v=f||b&&b.t.bind(b);return L({children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r,values:l,defaults:c,components:u,ns:p||v&&v.ns||y||b&&b.options&&b.options.defaultNS,i18n:b,t:f,shouldUnescape:g,...h})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,a,o]=U(n,s);return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=I,e.getInitialProps=B,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=K,e.useTranslation=U,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:i,...a}=t;return K(s,i),n.createElement(e,{...a})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${m(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function i(i){let{forwardedRef:a,...o}=i;const[r,l,c]=U(e,{...o,keyPrefix:t.keyPrefix}),u={...o,t:r,i18n:l,tReady:c};return t.withRef&&a?u.ref=a:!t.withRef&&a&&(u.forwardedRef=a),n.createElement(s,u)}i.displayName=`withI18nextTranslation(${m(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}})); | ||
!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}),i=/\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 r=new RegExp(i),o=null;null!==(o=r.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],r.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(r,(function(r,l){if(u){if(r!=="</"+t.name+">")return;u=!1}var p,d="/"!==r.charAt(1),f=r.startsWith("\x3c!--"),h=l+r.length,m=e.charAt(h);if(f){var g=a(r);return c<0?(s.push(g),s):((p=i[c]).children.push(g),s)}if(d&&(c++,"tag"===(t=a(r)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!m||"<"===m||t.children.push({type:"text",content:e.slice(h,e.indexOf("<",h))}),0===c&&s.push(t),(p=i[c-1])&&p.children.push(t),i[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===r.slice(2,-1))&&(c--,t=-1===c?s:i[c]),!u&&"<"!==m&&m)){p=-1===c?s:i[c].children;var y=e.indexOf("<",h),x=e.slice(h,-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=function(){if(console?.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}},p={},d=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y(n[0])&&p[n[0]]||(y(n[0])&&(p[n[0]]=new Date),u(...n))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},h=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},m=(e,n,t,s)=>{y(t)&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},g=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,b=/&(?: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 O={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(b,E)};const N=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}},$=()=>O;let w;const I=e=>{w=e},k=()=>w,S=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},j=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],T=(e,t)=>{if(!e)return"";let s="";const i=R(e),a=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))s+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:r}=e,o=Object.keys(n).length,l=a.indexOf(r)>-1,c=n.children;if(c||!l||o)if(!c&&(!l||o)||n.i18nIsDynamicList)s+=`<${i}></${i}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}</${r}>`;else{const e=T(c,t);s+=`<${i}>${e}</${i}>`}else s+=`<${r}/>`}else if(null===e)u("Trans: the passed in value is invalid - seems you passed in a null child.");else if(x(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];s+=`{{${e}}}`}else u("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else u("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",e)})),s},C=(e,t,s,i,a,r)=>{if(""===t)return[];const o=i.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!r)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(S(e)?p(j(e)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},h=(e,t,s)=>{const i=j(e),a=g(i,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(i)&&0===a.length||e.props?.i18nIsDynamicList?i:a},m=(e,t,s,i,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:i},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:i,ref:e.ref},a?null:t)})))},g=(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 r=u[parseInt(a.name,10)];1!==c.length||r||(r=c[0][a.name]),r||(r={});const b=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},r):r,v=n.isValidElement(b),E=v&&S(a,!0)&&!a.voidElement,O=l&&x(b)&&b.dummy&&!v,N=x(e)&&Object.hasOwnProperty.call(e,a.name);if(y(b)){const e=s.services.interpolator.interpolate(b,f,s.language);t.push(e)}else if(S(b)||E){const e=h(b,a,c);m(b,e,t,p)}else if(O){const e=g(u,a.children,c);m(b,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(N){const e=h(b,a,c);m(b,e,t,p,a.voidElement)}else if(i.transSupportBasicHtmlNodes&&o.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=g(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=g(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(x(b)&&!v){const e=a.children[0]?d:null;e&&t.push(e)}else m(b,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=i.transWrapTextNodes,o=r?i.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}),[])},b=g([{dummy:!0,children:e||[]}],d,R(e||[]));return j(b[0])};function P(e){let{children:t,count:s,parent:i,i18nKey:a,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:h,shouldUnescape:m,...g}=e;const x=f||k();if(!x)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=h||x.t.bind(x)||(e=>e),v={...$(),...x.options?.react};let E=p||b.ns||x.options?.defaultNS;E=y(E)?[E]:E||["translation"];const O=T(t,v),N=c||O||v.transEmptyNodeValue||a,{hashTransKey:w}=v,I=a||(w?w(O||N):O||N);x.options?.interpolation?.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...x.options.interpolation.defaultVariables}:{...x.options.interpolation.defaultVariables});const S=l||void 0!==s||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},j={...o,context:r||o.context,count:s,...l,...S,defaultValue:N,ns:E},R=I?b(I,j):N;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||R.indexOf(`${e}/>`)<0&&R.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const P=C(u||t,R,x,v,j,m),L=i??v.defaultTransParent;return L?n.createElement(L,g,P):P}const L={type:"3rdParty",init(e){N(e.options.react),I(e)}},A=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]??=!0}))}getUsedNamespaces=()=>Object.keys(this.usedNamespaces)}const z=e=>async n=>({...await(e.getInitialProps?.(n))??{},...F()}),F=()=>{const e=k(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),B=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:a}=n.useContext(A)||{},r=s||i||k();if(r&&!r.reportNamespaces&&(r.reportNamespaces=new V),!r){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n: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}r.options.react?.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...$(),...r.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||r.options?.defaultNS;u=y(u)?[u]:u||["translation"],r.reportNamespaces.addUsedNamespaces?.(u);const p=(r.isInitialized||r.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,r,o))),f=((e,t,s,i)=>n.useCallback(U(e,t,s,i),[e,t,s,i]))(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),g=()=>f,b=()=>U(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[v,E]=n.useState(g);let O=u.join();t.lng&&(O=`${t.lng}${O}`);const N=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(O),w=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;w.current=!0,p||l||(t.lng?m(r,t.lng,u,(()=>{w.current&&E(b)})):h(r,u,(()=>{w.current&&E(b)}))),p&&N&&N!==O&&w.current&&E(b);const s=()=>{w.current&&E(b)};return e&&r?.on(e,s),n&&r?.store.on(n,s),()=>{w.current=!1,r&&e?.split(" ").forEach((e=>r.off(e,s))),n&&r&&n.split(" ").forEach((e=>r.store.off(e,s)))}}),[r,O]),n.useEffect((()=>{w.current&&p&&E(g)}),[r,c,p]);const I=[v,r,p];if(I.t=v,I.i18n=r,I.ready=p,p)return I;if(!p&&!l)return I;throw new Promise((e=>{t.lng?m(r,t.lng,u,(()=>e())):h(r,u,(()=>e()))}))};const D=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:i}=s,{i18n:a}=n.useContext(A)||{},r=i||a||k();r.options?.isClone||(e&&!r.initializedStoreOnce&&(r.services.resourceStore.data=e,r.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),r.options.ns),r.initializedStoreOnce=!0,r.isInitialized=!0),t&&!r.initializedLanguageOnce&&(r.changeLanguage(t),r.initializedLanguageOnce=!0))};e.I18nContext=A,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:i}=e;const a=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(A.Provider,{value:a},i)},e.Trans=function(e){let{children:t,count:s,parent:i,i18nKey:a,context:r,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:h,...m}=e;const{i18n:g,defaultNS:y}=n.useContext(A)||{},x=d||g||k(),b=f||x?.t.bind(x);return P({children:t,count:s,parent:i,i18nKey:a,context:r,tOptions:o,values:l,defaults:c,components:u,ns:p||b?.ns||y||x?.options?.defaultNS,i18n:x,t:f,shouldUnescape:h,...m})},e.TransWithoutContext=P,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[i,a,r]=B(n,s);return t(i,{i18n:a,lng:a.language},r)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=k,e.getInitialProps=F,e.initReactI18next=L,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=N,e.setI18n=I,e.time=()=>"",e.useSSR=D,e.useTranslation=B,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:i,...a}=t;return D(s,i),n.createElement(e,{...a})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${g(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function i(i){let{forwardedRef:a,...r}=i;const[o,l,c]=B(e,{...r,keyPrefix:t.keyPrefix}),u={...r,t:o,i18n:l,tReady:c};return t.withRef&&a?u.ref=a:!t.withRef&&a&&(u.forwardedRef=a),n.createElement(s,u)}i.displayName=`withI18nextTranslation(${g(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}})); |
@@ -17,3 +17,3 @@ import { createContext } from 'react'; | ||
namespaces.forEach((ns) => { | ||
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true; | ||
this.usedNamespaces[ns] ??= true; | ||
}); | ||
@@ -26,5 +26,3 @@ } | ||
export const composeInitialProps = (ForComponent) => async (ctx) => { | ||
const componentsInitialProps = ForComponent.getInitialProps | ||
? await ForComponent.getInitialProps(ctx) | ||
: {}; | ||
const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {}; | ||
@@ -41,3 +39,3 @@ const i18nInitialProps = getInitialProps(); | ||
const i18n = getI18n(); | ||
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; | ||
const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? []; | ||
@@ -44,0 +42,0 @@ const ret = {}; |
@@ -26,3 +26,3 @@ import { useContext } from 'react'; | ||
const t = tFromProps || (i18n && i18n.t.bind(i18n)); | ||
const t = tFromProps || i18n?.t.bind(i18n); | ||
@@ -40,4 +40,3 @@ return TransWithoutContext({ | ||
// prepare having a namespace | ||
ns: | ||
ns || (t && t.ns) || defaultNSFromContext || (i18n && i18n.options && i18n.options.defaultNS), | ||
ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS, | ||
i18n, | ||
@@ -44,0 +43,0 @@ t: tFromProps, |
import { useTranslation } from './useTranslation.js'; | ||
export function Translation(props) { | ||
const { ns, children, ...options } = props; | ||
export const Translation = ({ ns, children, ...options }) => { | ||
const [t, i18n, ready] = useTranslation(ns, options); | ||
@@ -15,2 +14,2 @@ | ||
); | ||
} | ||
}; |
@@ -9,3 +9,3 @@ import { Fragment, isValidElement, cloneElement, createElement, Children } from 'react'; | ||
if (!node) return false; | ||
const base = node.props ? node.props.children : node.children; | ||
const base = node.props?.children ?? node.children; | ||
if (checkLength) return base.length > 0; | ||
@@ -17,4 +17,4 @@ return !!base; | ||
if (!node) return []; | ||
const children = node.props ? node.props.children : node.children; | ||
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children; | ||
const children = node.props?.children ?? node.children; | ||
return node.props?.i18nIsDynamicList ? getAsArray(children) : children; | ||
}; | ||
@@ -40,6 +40,5 @@ | ||
const childrenArray = getAsArray(children); | ||
const keepArray = | ||
i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor | ||
? i18nOptions.transKeepBasicHtmlNodesFor | ||
: []; | ||
const keepArray = i18nOptions?.transSupportBasicHtmlNodes | ||
? (i18nOptions.transKeepBasicHtmlNodesFor ?? []) | ||
: []; | ||
@@ -147,3 +146,3 @@ // e.g. lorem <br/> ipsum {{ messageCount, format }} dolor <strong>bold</strong> amet | ||
return (hasValidReactChildren(childs) && mappedChildren.length === 0) || | ||
(child.props && child.props.i18nIsDynamicList) | ||
child.props?.i18nIsDynamicList | ||
? childs | ||
@@ -186,5 +185,3 @@ : mappedChildren; | ||
const translationContent = | ||
node.children && | ||
node.children[0] && | ||
node.children[0].content && | ||
node.children?.[0]?.content && | ||
i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); | ||
@@ -334,6 +331,6 @@ | ||
const reactI18nextOptions = { ...getDefaults(), ...(i18n.options && i18n.options.react) }; | ||
const reactI18nextOptions = { ...getDefaults(), ...i18n.options?.react }; | ||
// prepare having a namespace | ||
let namespaces = ns || t.ns || (i18n.options && i18n.options.defaultNS); | ||
let namespaces = ns || t.ns || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
@@ -348,3 +345,3 @@ | ||
(hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue); | ||
if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) { | ||
if (i18n.options?.interpolation?.defaultVariables) { | ||
// eslint-disable-next-line no-param-reassign | ||
@@ -403,5 +400,5 @@ values = | ||
// and override `defaultTransParent` if is present | ||
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; | ||
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent; | ||
return useAsParent ? createElement(useAsParent, additionalProps, content) : content; | ||
} |
@@ -11,3 +11,3 @@ import { useContext } from 'react'; | ||
// -> do not set initial stuff on server side | ||
if (i18n.options && i18n.options.isClone) return; | ||
if (i18n.options?.isClone) return; | ||
@@ -14,0 +14,0 @@ // nextjs / SSR: getting data from next.js or other ssr stack |
@@ -52,3 +52,3 @@ import { useState, useEffect, useContext, useRef, useCallback } from 'react'; | ||
if (i18n.options.react && i18n.options.react.wait !== undefined) | ||
if (i18n.options.react?.wait) | ||
warnOnce( | ||
@@ -62,7 +62,7 @@ 'It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.', | ||
// prepare having a namespace | ||
let namespaces = ns || defaultNSFromContext || (i18n.options && i18n.options.defaultNS); | ||
let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS; | ||
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; | ||
// report namespaces as used | ||
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); | ||
i18n.reportNamespaces.addUsedNamespaces?.(namespaces); | ||
@@ -125,4 +125,4 @@ // are we ready? yes if all namespaces in first language are loaded already (either with data or empty object on failed load) | ||
// bind events to trigger change, like languageChanged | ||
if (bindI18n && i18n) i18n.on(bindI18n, boundReset); | ||
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); | ||
if (bindI18n) i18n?.on(bindI18n, boundReset); | ||
if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset); | ||
@@ -132,3 +132,3 @@ // unbinding on unmount | ||
isMounted.current = false; | ||
if (bindI18n && i18n) bindI18n.split(' ').forEach((e) => i18n.off(e, boundReset)); | ||
if (i18n) bindI18n?.split(' ').forEach((e) => i18n.off(e, boundReset)); | ||
if (bindI18nStore && i18n) | ||
@@ -135,0 +135,0 @@ bindI18nStore.split(' ').forEach((e) => i18n.store.off(e, boundReset)); |
@@ -1,20 +0,18 @@ | ||
// Do not use arrow function here as it will break optimizations of arguments | ||
export function warn(...args) { | ||
if (console && console.warn) { | ||
export const warn = (...args) => { | ||
if (console?.warn) { | ||
if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`; | ||
console.warn(...args); | ||
} | ||
} | ||
}; | ||
const alreadyWarned = {}; | ||
// Do not use arrow function here as it will break optimizations of arguments | ||
export function warnOnce(...args) { | ||
export const warnOnce = (...args) => { | ||
if (isString(args[0]) && alreadyWarned[args[0]]) return; | ||
if (isString(args[0])) alreadyWarned[args[0]] = new Date(); | ||
warn(...args); | ||
} | ||
}; | ||
// not needed right now | ||
// | ||
// export function deprecated(...args) { | ||
// export const deprecated = (...args) => { | ||
// if (process && process.env && (!process.env.NODE_ENV || process.env.NODE_ENV === 'development')) { | ||
@@ -56,44 +54,2 @@ // if (isString(args[0])) args[0] = `deprecation warning -> ${args[0]}`; | ||
// WAIT A LITTLE FOR I18NEXT BEING UPDATED IN THE WILD, before removing this old i18next version support | ||
const oldI18nextHasLoadedNamespace = (ns, i18n, options = {}) => { | ||
const lng = i18n.languages[0]; | ||
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; | ||
const lastLng = i18n.languages[i18n.languages.length - 1]; | ||
// we're in cimode so this shall pass | ||
if (lng.toLowerCase() === 'cimode') return true; | ||
const loadNotPending = (l, n) => { | ||
const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; | ||
return loadState === -1 || loadState === 2; | ||
}; | ||
// bound to trigger on event languageChanging | ||
// so set ready to false while we are changing the language | ||
// and namespace pending (depends on having a backend) | ||
if ( | ||
options.bindI18n && | ||
options.bindI18n.indexOf('languageChanging') > -1 && | ||
i18n.services.backendConnector.backend && | ||
i18n.isLanguageChangingTo && | ||
!loadNotPending(i18n.isLanguageChangingTo, ns) | ||
) | ||
return false; | ||
// loaded -> SUCCESS | ||
if (i18n.hasResourceBundle(lng, ns)) return true; | ||
// were not loading at all -> SEMI SUCCESS | ||
if ( | ||
!i18n.services.backendConnector.backend || | ||
(i18n.options.resources && !i18n.options.partialBundledLanguages) | ||
) | ||
return true; | ||
// failed loading ns - but at least fallback is not pending -> SEMI SUCCESS | ||
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; | ||
return false; | ||
}; | ||
export const hasLoadedNamespace = (ns, i18n, options = {}) => { | ||
@@ -105,10 +61,2 @@ if (!i18n.languages || !i18n.languages.length) { | ||
// ignoreJSONStructure was introduced in v20.0.0 (MARCH 2021) | ||
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined; | ||
if (!isNewerI18next) { | ||
// WAIT A LITTLE FOR I18NEXT BEING UPDATED IN THE WILD, before removing this old i18next version support | ||
return oldI18nextHasLoadedNamespace(ns, i18n, options); | ||
} | ||
// IN I18NEXT > v19.4.5 WE CAN (INTRODUCED JUNE 2020) | ||
return i18n.hasLoadedNamespace(ns, { | ||
@@ -118,4 +66,3 @@ lng: options.lng, | ||
if ( | ||
options.bindI18n && | ||
options.bindI18n.indexOf('languageChanging') > -1 && | ||
options.bindI18n?.indexOf('languageChanging') > -1 && | ||
i18nInstance.services.backendConnector.backend && | ||
@@ -122,0 +69,0 @@ i18nInstance.isLanguageChangingTo && |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
315520
6005
Updated@babel/runtime@^7.24.8