From 26ab5a3e8134efd775ee5e7d10cc77442a634ff3 Mon Sep 17 00:00:00 2001 From: Adriano Raiano Date: Mon, 30 Dec 2024 11:19:00 +0100 Subject: [PATCH] release --- CHANGELOG.md | 4 ++ react-i18next.js | 92 +++++++++++++++++++++++++++----------------- react-i18next.min.js | 2 +- 3 files changed, 62 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0d3b5f2..8cf6a9dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 15.4.0 + +feat: add meta with codes on warnings to allow conditional logging [1826](https://github.com/i18next/react-i18next/pull/1826) + ### 15.3.0 Uses the i18next logger instead of the default console logger, if there is a valid i18next instance. Now the debug i18next option is respected, and you can also inject your own logger module: https://www.i18next.com/misc/creating-own-plugins#logger diff --git a/react-i18next.js b/react-i18next.js index 2e16d310..91e512d4 100644 --- a/react-i18next.js +++ b/react-i18next.js @@ -118,28 +118,26 @@ } }; - const warn = function (i18n) { - for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } + const warn = (i18n, code, msg, rest) => { + const args = [msg, { + code, + ...(rest || {}) + }]; if (i18n?.services?.logger?.forward) { - i18n.services.logger.forward(args, 'warn', 'react-i18next::', true); - } else if (i18n?.services?.logger?.warn) { - if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`; + return i18n.services.logger.forward(args, 'warn', 'react-i18next::', true); + } + if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`; + if (i18n?.services?.logger?.warn) { i18n.services.logger.warn(...args); } else if (console?.warn) { - if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`; console.warn(...args); } }; const alreadyWarned = {}; - const warnOnce = function (i18n) { - for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { - args[_key2 - 1] = arguments[_key2]; - } - if (isString(args[0]) && alreadyWarned[args[0]]) return; - if (isString(args[0])) alreadyWarned[args[0]] = new Date(); - warn(i18n, ...args); + const warnOnce = (i18n, code, msg, rest) => { + if (isString(msg) && alreadyWarned[msg]) return; + if (isString(msg)) alreadyWarned[msg] = new Date(); + warn(i18n, code, msg, rest); }; const loadedClb = (i18n, cb) => () => { if (i18n.isInitialized) { @@ -168,7 +166,9 @@ const hasLoadedNamespace = function (ns, i18n) { let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!i18n.languages || !i18n.languages.length) { - warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages); + warnOnce(i18n, 'NO_LANGUAGES', 'i18n.languages were undefined or empty', { + languages: i18n.languages + }); return true; } return i18n.hasLoadedNamespace(ns, { @@ -261,7 +261,9 @@ childrenArray.forEach((child, childIndex) => { if (isString(child)) { stringNode += `${child}`; - } else if (react.isValidElement(child)) { + return; + } + if (react.isValidElement(child)) { const { props, type @@ -271,17 +273,27 @@ const childChildren = props.children; if (!childChildren && shouldKeepChild && !childPropsCount) { stringNode += `<${type}/>`; - } else if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) { + return; + } + if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) { stringNode += `<${childIndex}>`; - } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) { + return; + } + if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) { stringNode += `<${type}>${childChildren}`; - } else { - const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey); - stringNode += `<${childIndex}>${content}`; + return; } - } else if (child === null) { - warn(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`); - } else if (isObject(child)) { + const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey); + stringNode += `<${childIndex}>${content}`; + return; + } + if (child === null) { + warn(i18n, 'TRANS_NULL_VALUE', `Passed in a null value as child`, { + i18nKey + }); + return; + } + if (isObject(child)) { const { format, ...clone @@ -290,12 +302,18 @@ if (keys.length === 1) { const value = format ? `${keys[0]}, ${format}` : keys[0]; stringNode += `{{${value}}}`; - } else { - warn(i18n, `react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child, i18nKey); + return; } - } else { - warn(i18n, `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}}.`, child, i18nKey); + warn(i18n, 'TRANS_INVALID_OBJ', `Invalid child - Object should only have keys {{ value, format }} (format is optional).`, { + i18nKey, + child + }); + return; } + warn(i18n, 'TRANS_INVALID_VAR', `Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`, { + i18nKey, + child + }); }); return stringNode; }; @@ -438,7 +456,7 @@ }); return componentMap; }; - const generateComponents = (components, translation, i18n) => { + const generateComponents = (components, translation, i18n, i18nKey) => { if (!components) return null; if (Array.isArray(components)) { return generateArrayComponents(components, translation); @@ -446,7 +464,9 @@ if (isObject(components)) { return generateObjectComponents(components, translation); } - warnOnce(i18n, ' component prop expects an object or an array'); + warnOnce(i18n, 'TRANS_INVALID_COMPONENTS', ` "components" prop expects an object or array`, { + i18nKey + }); return null; }; function Trans$1(_ref) { @@ -468,7 +488,9 @@ } = _ref; const i18n = i18nFromProps || getI18n(); if (!i18n) { - warnOnce(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule'); + warnOnce(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, { + i18nKey + }); return children; } const t = tFromProps || i18n.t.bind(i18n) || (k => k); @@ -509,7 +531,7 @@ ns: namespaces }; const translation = key ? t(key, combinedTOpts) : defaultValue; - const generatedComponents = generateComponents(components, translation, i18n); + const generatedComponents = generateComponents(components, translation, i18n, i18nKey); const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); const useAsParent = parent ?? reactI18nextOptions.defaultTransParent; return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content; @@ -623,7 +645,7 @@ const i18n = i18nFromProps || i18nFromContext || getI18n(); if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces(); if (!i18n) { - warnOnce(i18n, 'You will need to pass in an i18next instance by using initReactI18next'); + warnOnce(i18n, 'NO_I18NEXT_INSTANCE', 'useTranslation: You will need to pass in an i18next instance by using initReactI18next'); const notReadyT = (k, optsOrDefaultValue) => { if (isString(optsOrDefaultValue)) return optsOrDefaultValue; if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue; @@ -635,7 +657,7 @@ retNotReady.ready = false; return retNotReady; } - if (i18n.options.react?.wait) warnOnce(i18n, 'It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); + if (i18n.options.react?.wait) warnOnce(i18n, 'DEPRECATED_OPTION', 'useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); const i18nOptions = { ...getDefaults(), ...i18n.options.react, diff --git a/react-i18next.min.js b/react-i18next.min.js index 2bc0d797..b088038f 100644 --- a/react-i18next.min.js +++ b/react-i18next.min.js @@ -1 +1 @@ -!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),a=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function r(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var i=new RegExp(a),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],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(i,(function(i,l){if(u){if(i!=="")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=r(i);return c<0?(s.push(h),s):((p=a[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=r(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=a[c-1])&&p.children.push(t),a[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:a[c]),!u&&"<"!==g&&g)){p=-1===c?s:a[c].children;var y=e.indexOf("<",m),x=e.slice(m,-1===y?void 0:y);o.test(x)&&(x=" "),(y>-1&&c+p.length>=0||" "!==x)&&p.push({type:"text",content:x})}})),s};const u=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),s=1;s1?n-1:0),s=1;s()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,v=/&(?: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(v,E)};const w=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};O={...O,...e}},N=()=>O;let $;const k=e=>{$=e},I=()=>$,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,s,a)=>{if(!e)return"";let r="";const i=R(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))r+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(p||!u||c)if(!p&&(!u||c)||n.i18nIsDynamicList)r+=`<${i}>`;else if(u&&1===c&&y(p))r+=`<${l}>${p}`;else{const e=T(p,t,s,a);r+=`<${i}>${e}`}else r+=`<${l}/>`}else if(null===e)u(s,"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];r+=`{{${e}}}`}else u(s,"react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e,a)}else u(s,"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,a)})),r},C=(e,t,s,a,r,i)=>{if(""===t)return[];const o=a.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!i)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(S(e)?p(j(e)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}`),f={...u,...r},m=(e,t,s)=>{const a=j(e),r=h(a,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(a)&&0===r.length||e.props?.i18nIsDynamicList?a:r},g=(e,t,s,a,r)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:a},r?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:a,ref:e.ref},r?null:t)})))},h=(t,r,c)=>{const u=R(t);return R(r).reduce(((t,r,p)=>{const d=r.children?.[0]?.content&&s.services.interpolator.interpolate(r.children[0].content,f,s.language);if("tag"===r.type){let i=u[parseInt(r.name,10)];1!==c.length||i||(i=c[0][r.name]),i||(i={});const v=0!==Object.keys(r.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:r.attrs},i):i,b=n.isValidElement(v),E=b&&S(r,!0)&&!r.voidElement,O=l&&x(v)&&v.dummy&&!b,w=x(e)&&Object.hasOwnProperty.call(e,r.name);if(y(v)){const e=s.services.interpolator.interpolate(v,f,s.language);t.push(e)}else if(S(v)||E){const e=m(v,r,c);g(v,e,t,p)}else if(O){const e=h(u,r.children,c);g(v,e,t,p)}else if(Number.isNaN(parseFloat(r.name)))if(w){const e=m(v,r,c);g(v,e,t,p,r.voidElement)}else if(a.transSupportBasicHtmlNodes&&o.indexOf(r.name)>-1)if(r.voidElement)t.push(n.createElement(r.name,{key:`${r.name}-${p}`}));else{const e=h(u,r.children,c);t.push(n.createElement(r.name,{key:`${r.name}-${p}`},e))}else if(r.voidElement)t.push(`<${r.name} />`);else{const e=h(u,r.children,c);t.push(`<${r.name}>${e}`)}else if(x(v)&&!b){const e=r.children[0]?d:null;e&&t.push(e)}else g(v,d,t,p,1!==r.children.length||!d)}else if("text"===r.type){const e=a.transWrapTextNodes,o=i?a.unescape(s.services.interpolator.interpolate(r.content,f,s.language)):s.services.interpolator.interpolate(r.content,f,s.language);e?t.push(n.createElement(e,{key:`${r.name}-${p}`},o)):t.push(o)}return t}),[])},v=h([{dummy:!0,children:e||[]}],d,R(e||[]));return j(v[0])},A=(e,t,s)=>{const a=e.key||t,r=n.cloneElement(e,{key:a});if(!r.props||!r.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return r;return n.createElement((function(){return n.createElement(n.Fragment,null,r)}))},P=(e,n,t)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>A(e,t,n))))(e,n):x(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:A(e[s],s,n)})})),t})(e,n):(d(t," component prop expects an object or an array"),null):null;function L(e){let{children:t,count:s,parent:a,i18nKey:r,context:i,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:m,shouldUnescape:g,...h}=e;const x=f||I();if(!x)return d(x,"You will need to pass in an i18next instance by using i18nextReactModule"),t;const v=m||x.t.bind(x)||(e=>e),b={...N(),...x.options?.react};let E=p||v.ns||x.options?.defaultNS;E=y(E)?[E]:E||["translation"];const O=T(t,b,x,r),w=c||O||b.transEmptyNodeValue||r,{hashTransKey:$}=b,k=r||($?$(O||w):O||w);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&&!x.options?.interpolation?.alwaysFormat||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},j={...o,context:i||o.context,count:s,...l,...S,defaultValue:w,ns:E},R=k?v(k,j):w,A=P(u,R,x),L=C(A||t,R,x,b,j,g),V=a??b.defaultTransParent;return V?n.createElement(V,h,L):L}const V={type:"3rdParty",init(e){w(e.options.react),k(e)}},z=n.createContext();class F{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const U=e=>async n=>({...await(e.getInitialProps?.(n))??{},...B()}),B=()=>{const e=I(),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 D=(e,n,t,s)=>e.getFixedT(n,t,s),K=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:a,defaultNS:r}=n.useContext(z)||{},i=s||a||I();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new F),!i){d(i,"You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:x(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...N(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||r||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.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(n,"i18n.languages were undefined or empty",n.languages),!0)}(e,i,o))),f=((e,t,s,a)=>n.useCallback(D(e,t,s,a),[e,t,s,a]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,v=()=>D(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,E]=n.useState(h);let O=u.join();t.lng&&(O=`${t.lng}${O}`);const w=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(O),$=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;$.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{$.current&&E(v)})):m(i,u,(()=>{$.current&&E(v)}))),p&&w&&w!==O&&$.current&&E(v);const s=()=>{$.current&&E(v)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{$.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,O]),n.useEffect((()=>{$.current&&p&&E(h)}),[i,c,p]);const k=[b,i,p];if(k.t=b,k.i18n=i,k.ready=p,p)return k;if(!p&&!l)return k;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const W=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:a}=s,{i18n:r}=n.useContext(z)||{},i=a||r||I();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=z,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:a}=e;const r=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(z.Provider,{value:r},a)},e.Trans=function(e){let{children:t,count:s,parent:a,i18nKey:r,context:i,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:m,...g}=e;const{i18n:h,defaultNS:y}=n.useContext(z)||{},x=d||h||I(),v=f||x?.t.bind(x);return L({children:t,count:s,parent:a,i18nKey:r,context:i,tOptions:o,values:l,defaults:c,components:u,ns:p||v?.ns||y||x?.options?.defaultNS,i18n:x,t:f,shouldUnescape:m,...g})},e.TransWithoutContext=L,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[a,r,i]=K(n,s);return t(a,{i18n:r,lng:r.language},i)},e.composeInitialProps=U,e.date=()=>"",e.getDefaults=N,e.getI18n=I,e.getInitialProps=B,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=w,e.setI18n=k,e.time=()=>"",e.useSSR=W,e.useTranslation=K,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:a,...r}=t;return W(s,a),n.createElement(e,{...r})}return t.getInitialProps=U(e),t.displayName=`withI18nextSSR(${h(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:r,...i}=a;const[o,l,c]=K(e,{...i,keyPrefix:t.keyPrefix}),u={...i,t:o,i18n:l,tReady:c};return t.withRef&&r?u.ref=r:!t.withRef&&r&&(u.forwardedRef=r),n.createElement(s,u)}a.displayName=`withI18nextTranslation(${h(s)})`,a.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(a,Object.assign({},e,{forwardedRef:t})))):a}}})); +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function 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 a=new RegExp(r),o=null;null!==(o=a.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],a.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(a,(function(a,l){if(u){if(a!=="")return;u=!1}var p,d="/"!==a.charAt(1),f=a.startsWith("\x3c!--"),g=l+a.length,m=e.charAt(g);if(f){var h=i(a);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=i(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!m||"<"===m||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==m&&m)){p=-1===c?s:r[c].children;var y=e.indexOf("<",g),x=e.slice(g,-1===y?void 0:y);o.test(x)&&(x=" "),(y>-1&&c+p.length>=0||" "!==x)&&p.push({type:"text",content:x})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},g=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},m=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return g(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,N={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},b=e=>N[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,b)};const O=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,T=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},k=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],A=(e,t,s,r)=>{if(!e)return"";let i="";const a=R(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach(((e,a)=>{if(y(e))i+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(i+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(i+=`<${a}>`);if(u&&1===c&&y(p))return void(i+=`<${l}>${p}`);const d=A(p,t,s,r);i+=`<${a}>${d}`}else if(null!==e)if(x(e)){const{format:n,...t}=e,a=Object.keys(t);if(1===a.length){const e=n?`${a[0]}, ${n}`:a[0];return void(i+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),i},j=(e,t,s,r,i,a)=>{if(""===t)return[];const o=r.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!a)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(T(e)?p(k(e)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}`),f={...u,...i},g=(e,t,s)=>{const r=k(e),i=h(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===i.length||e.props?.i18nIsDynamicList?r:i},m=(e,t,s,r,i)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},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:r,ref:e.ref},i?null:t)})))},h=(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 a=u[parseInt(i.name,10)];1!==c.length||a||(a=c[0][i.name]),a||(a={});const v=0!==Object.keys(i.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:i.attrs},a):a,N=n.isValidElement(v),b=N&&T(i,!0)&&!i.voidElement,E=l&&x(v)&&v.dummy&&!N,O=x(e)&&Object.hasOwnProperty.call(e,i.name);if(y(v)){const e=s.services.interpolator.interpolate(v,f,s.language);t.push(e)}else if(T(v)||b){const e=g(v,i,c);m(v,e,t,p)}else if(E){const e=h(u,i.children,c);m(v,e,t,p)}else if(Number.isNaN(parseFloat(i.name)))if(O){const e=g(v,i,c);m(v,e,t,p,i.voidElement)}else if(r.transSupportBasicHtmlNodes&&o.indexOf(i.name)>-1)if(i.voidElement)t.push(n.createElement(i.name,{key:`${i.name}-${p}`}));else{const e=h(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=h(u,i.children,c);t.push(`<${i.name}>${e}`)}else if(x(v)&&!N){const e=i.children[0]?d:null;e&&t.push(e)}else m(v,d,t,p,1!==i.children.length||!d)}else if("text"===i.type){const e=r.transWrapTextNodes,o=a?r.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}),[])},v=h([{dummy:!0,children:e||[]}],d,R(e||[]));return k(v[0])},C=(e,t,s)=>{const r=e.key||t,i=n.cloneElement(e,{key:r});if(!i.props||!i.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return i;return n.createElement((function(){return n.createElement(n.Fragment,null,i)}))},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):x(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",' "components" prop expects an object or array',{i18nKey:s}),null):null;function P(e){let{children:t,count:s,parent:r,i18nKey:i,context:a,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:g,shouldUnescape:m,...h}=e;const x=f||$();if(!x)return d(x,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:i}),t;const v=g||x.t.bind(x)||(e=>e),N={...I(),...x.options?.react};let b=p||v.ns||x.options?.defaultNS;b=y(b)?[b]:b||["translation"];const E=A(t,N,x,i),O=c||E||N.transEmptyNodeValue||i,{hashTransKey:S}=N,w=i||(S?S(E||O):E||O);x.options?.interpolation?.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...x.options.interpolation.defaultVariables}:{...x.options.interpolation.defaultVariables});const T=l||void 0!==s&&!x.options?.interpolation?.alwaysFormat||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},k={...o,context:a||o.context,count:s,...l,...T,defaultValue:O,ns:b},R=w?v(w,k):O,C=L(u,R,x,i),P=j(C||t,R,x,N,k,m),V=r??N.defaultTransParent;return V?n.createElement(V,h,P):P}const V={type:"3rdParty",init(e){O(e.options.react),w(e)}},_=n.createContext();class D{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const K=e=>async n=>({...await(e.getInitialProps?.(n))??{},...z()}),z=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),F=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:r,defaultNS:i}=n.useContext(_)||{},a=s||r||$();if(a&&!a.reportNamespaces&&(a.reportNamespaces=new D),!a){d(a,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:x(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}a.options.react?.wait&&d(a,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...a.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||i||a.options?.defaultNS;u=y(u)?[u]:u||["translation"],a.reportNamespaces.addUsedNamespaces?.(u);const p=(a.isInitialized||a.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(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0)}(e,a,o))),f=((e,t,s,r)=>n.useCallback(U(e,t,s,r),[e,t,s,r]))(a,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,v=()=>U(a,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[N,b]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?m(a,t.lng,u,(()=>{S.current&&b(v)})):g(a,u,(()=>{S.current&&b(v)}))),p&&O&&O!==E&&S.current&&b(v);const s=()=>{S.current&&b(v)};return e&&a?.on(e,s),n&&a?.store.on(n,s),()=>{S.current=!1,a&&e?.split(" ").forEach((e=>a.off(e,s))),n&&a&&n.split(" ").forEach((e=>a.store.off(e,s)))}}),[a,E]),n.useEffect((()=>{S.current&&p&&b(h)}),[a,c,p]);const w=[N,a,p];if(w.t=N,w.i18n=a,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?m(a,t.lng,u,(()=>e())):g(a,u,(()=>e()))}))};const B=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:r}=s,{i18n:i}=n.useContext(_)||{},a=r||i||$();a.options?.isClone||(e&&!a.initializedStoreOnce&&(a.services.resourceStore.data=e,a.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),a.options.ns),a.initializedStoreOnce=!0,a.isInitialized=!0),t&&!a.initializedLanguageOnce&&(a.changeLanguage(t),a.initializedLanguageOnce=!0))};e.I18nContext=_,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:r}=e;const i=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(_.Provider,{value:i},r)},e.Trans=function(e){let{children:t,count:s,parent:r,i18nKey:i,context:a,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...m}=e;const{i18n:h,defaultNS:y}=n.useContext(_)||{},x=d||h||$(),v=f||x?.t.bind(x);return P({children:t,count:s,parent:r,i18nKey:i,context:a,tOptions:o,values:l,defaults:c,components:u,ns:p||v?.ns||y||x?.options?.defaultNS,i18n:x,t:f,shouldUnescape:g,...m})},e.TransWithoutContext=P,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[r,i,a]=F(n,s);return t(r,{i18n:i,lng:i.language},a)},e.composeInitialProps=K,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=z,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=B,e.useTranslation=F,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:r,...i}=t;return B(s,r),n.createElement(e,{...i})}return t.getInitialProps=K(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function r(r){let{forwardedRef:i,...a}=r;const[o,l,c]=F(e,{...a,keyPrefix:t.keyPrefix}),u={...a,t:o,i18n:l,tReady:c};return t.withRef&&i?u.ref=i:!t.withRef&&i&&(u.forwardedRef=i),n.createElement(s,u)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}}));