diff --git a/CHANGELOG.md b/CHANGELOG.md index cf1dffa9c..c0d3b5f23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 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 + ### 15.2.0 This version may be breaking if you still use React < v18 with TypeScript. diff --git a/example/react/package-lock.json b/example/react/package-lock.json index 516cc306a..45e5a0708 100644 --- a/example/react/package-lock.json +++ b/example/react/package-lock.json @@ -8,12 +8,12 @@ "name": "react_usinghooks", "version": "0.1.0", "dependencies": { - "i18next": "^24.0.2", - "i18next-browser-languagedetector": "^8.0.0", + "i18next": "^24.2.0", + "i18next-browser-languagedetector": "^8.0.2", "i18next-http-backend": "^3.0.1", - "react": "^18.3.1", - "react-dom": "^18.3.1", - "react-i18next": "^15.1.1", + "react": "^19.0.0", + "react-dom": "^19.0.0", + "react-i18next": "^15.2.0", "react-scripts": "^5.0.1" } }, @@ -8912,9 +8912,9 @@ } }, "node_modules/i18next": { - "version": "24.0.2", - "resolved": "https://registry.npmjs.org/i18next/-/i18next-24.0.2.tgz", - "integrity": "sha512-D88xyIGcWAKwBTAs4RSqASi8NXR/NhCVSTM4LDbdoU8qb/5dcEZjNCLDhtQBB7Epw/Cp1w2vH/3ujoTbqLSs5g==", + "version": "24.2.0", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-24.2.0.tgz", + "integrity": "sha512-ArJJTS1lV6lgKH7yEf4EpgNZ7+THl7bsGxxougPYiXRTJ/Fe1j08/TBpV9QsXCIYVfdE/HWG/xLezJ5DOlfBOA==", "funding": [ { "type": "individual", @@ -8943,9 +8943,9 @@ } }, "node_modules/i18next-browser-languagedetector": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-8.0.0.tgz", - "integrity": "sha512-zhXdJXTTCoG39QsrOCiOabnWj2jecouOqbchu3EfhtSHxIB5Uugnm9JaizenOy39h7ne3+fLikIjeW88+rgszw==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-8.0.2.tgz", + "integrity": "sha512-shBvPmnIyZeD2VU5jVGIOWP7u9qNG3Lj7mpaiPFpbJ3LVfHZJvVzKR4v1Cb91wAOFpNw442N+LGPzHOHsten2g==", "license": "MIT", "dependencies": { "@babel/runtime": "^7.23.2" @@ -13582,13 +13582,10 @@ } }, "node_modules/react": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", - "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "version": "19.0.0", + "resolved": "https://registry.npmjs.org/react/-/react-19.0.0.tgz", + "integrity": "sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ==", "license": "MIT", - "dependencies": { - "loose-envify": "^1.1.0" - }, "engines": { "node": ">=0.10.0" } @@ -13722,16 +13719,15 @@ } }, "node_modules/react-dom": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", - "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", + "version": "19.0.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.0.0.tgz", + "integrity": "sha512-4GV5sHFG0e/0AD4X+ySy6UJd3jVl1iNsNHdpad0qhABJ11twS3TTBnseqsKurKcsNqCEFeGL3uLpVChpIO3QfQ==", "license": "MIT", "dependencies": { - "loose-envify": "^1.1.0", - "scheduler": "^0.23.2" + "scheduler": "^0.25.0" }, "peerDependencies": { - "react": "^18.3.1" + "react": "^19.0.0" } }, "node_modules/react-error-overlay": { @@ -13741,9 +13737,9 @@ "license": "MIT" }, "node_modules/react-i18next": { - "version": "15.1.1", - "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-15.1.1.tgz", - "integrity": "sha512-R/Vg9wIli2P3FfeI8o1eNJUJue5LWpFsQePCHdQDmX0Co3zkr6kdT8gAseb/yGeWbNz1Txc4bKDQuZYsC0kQfw==", + "version": "15.2.0", + "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-15.2.0.tgz", + "integrity": "sha512-iJNc8111EaDtVTVMKigvBtPHyrJV+KblWG73cUxqp+WmJCcwkzhWNFXmkAD5pwP2Z4woeDj/oXDdbjDsb3Gutg==", "license": "MIT", "dependencies": { "@babel/runtime": "^7.25.0", @@ -14405,13 +14401,10 @@ } }, "node_modules/scheduler": { - "version": "0.23.2", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", - "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", - "license": "MIT", - "dependencies": { - "loose-envify": "^1.1.0" - } + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.25.0.tgz", + "integrity": "sha512-xFVuu11jh+xcO7JOAGJNOXld8/TcEHK/4CituBUeUb5hqxJLj9YuemAEuvm9gQ/+pgXYfbQuqAkiYu+u7YEsNA==", + "license": "MIT" }, "node_modules/schema-utils": { "version": "4.2.0", diff --git a/example/react/package.json b/example/react/package.json index 6ba0c19f4..98f0ac941 100644 --- a/example/react/package.json +++ b/example/react/package.json @@ -3,14 +3,17 @@ "version": "0.1.0", "private": true, "dependencies": { - "i18next": "^24.0.2", - "i18next-browser-languagedetector": "^8.0.0", + "i18next": "^24.2.0", + "i18next-browser-languagedetector": "^8.0.2", "i18next-http-backend": "^3.0.1", - "react": "^18.3.1", - "react-dom": "^18.3.1", - "react-i18next": "^15.1.1", + "react": "^19.0.0", + "react-dom": "^19.0.0", + "react-i18next": "^15.2.0", "react-scripts": "^5.0.1" }, + "overrides": { + "typescript": "5.7.2" + }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", diff --git a/react-i18next.js b/react-i18next.js index a66da3546..2e16d310c 100644 --- a/react-i18next.js +++ b/react-i18next.js @@ -118,23 +118,28 @@ } }; - const warn = function () { - if (console?.warn) { - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } + 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]; + } + 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]}`; + 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 () { - for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; + 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(...args); + warn(i18n, ...args); }; const loadedClb = (i18n, cb) => () => { if (i18n.isInitialized) { @@ -163,7 +168,7 @@ const hasLoadedNamespace = function (ns, i18n) { let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!i18n.languages || !i18n.languages.length) { - warnOnce('i18n.languages were undefined or empty', i18n.languages); + warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages); return true; } return i18n.hasLoadedNamespace(ns, { @@ -248,7 +253,7 @@ newTarget.props = Object.assign(source.props, target.props); return newTarget; }; - const nodesToString = (children, i18nOptions) => { + const nodesToString = (children, i18nOptions, i18n, i18nKey) => { if (!children) return ''; let stringNode = ''; const childrenArray = getAsArray(children); @@ -271,11 +276,11 @@ } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) { stringNode += `<${type}>${childChildren}`; } else { - const content = nodesToString(childChildren, i18nOptions); + const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey); stringNode += `<${childIndex}>${content}`; } } else if (child === null) { - warn(`Trans: the passed in value is invalid - seems you passed in a null child.`); + warn(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`); } else if (isObject(child)) { const { format, @@ -286,10 +291,10 @@ const value = format ? `${keys[0]}, ${format}` : keys[0]; stringNode += `{{${value}}}`; } else { - warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child); + 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); } } else { - warn(`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); + 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); } }); return stringNode; @@ -433,7 +438,7 @@ }); return componentMap; }; - const generateComponents = (components, translation) => { + const generateComponents = (components, translation, i18n) => { if (!components) return null; if (Array.isArray(components)) { return generateArrayComponents(components, translation); @@ -441,7 +446,7 @@ if (isObject(components)) { return generateObjectComponents(components, translation); } - warnOnce(' component prop expects an object or an array'); + warnOnce(i18n, ' component prop expects an object or an array'); return null; }; function Trans$1(_ref) { @@ -463,7 +468,7 @@ } = _ref; const i18n = i18nFromProps || getI18n(); if (!i18n) { - warnOnce('You will need to pass in an i18next instance by using i18nextReactModule'); + warnOnce(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule'); return children; } const t = tFromProps || i18n.t.bind(i18n) || (k => k); @@ -473,7 +478,7 @@ }; let namespaces = ns || t.ns || i18n.options?.defaultNS; namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; - const nodeAsString = nodesToString(children, reactI18nextOptions); + const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey); const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey; const { hashTransKey @@ -504,7 +509,7 @@ ns: namespaces }; const translation = key ? t(key, combinedTOpts) : defaultValue; - const generatedComponents = generateComponents(components, translation); + const generatedComponents = generateComponents(components, translation, i18n); const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); const useAsParent = parent ?? reactI18nextOptions.defaultTransParent; return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content; @@ -618,7 +623,7 @@ const i18n = i18nFromProps || i18nFromContext || getI18n(); if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces(); if (!i18n) { - warnOnce('You will need to pass in an i18next instance by using initReactI18next'); + warnOnce(i18n, '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; @@ -630,7 +635,7 @@ retNotReady.ready = false; return retNotReady; } - if (i18n.options.react?.wait) 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(i18n, '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 5dd9df62a..2bc0d797c 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 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!=="")return;u=!1}var p,d="/"!==r.charAt(1),f=r.startsWith("\x3c!--"),m=l+r.length,h=e.charAt(m);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||!h||"<"===h||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===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("<",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(){if(console?.warn){for(var e=arguments.length,n=new Array(e),t=0;t()=>{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))},h=(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))},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 k=e=>{w=e},I=()=>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 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}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}`;else{const e=T(c,t);s+=`<${a}>${e}`}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,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},C=(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)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}`),f={...u,...i},m=(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},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)})))},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 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,v=n.isValidElement(b),E=v&&S(i,!0)&&!i.voidElement,O=l&&x(b)&&b.dummy&&!v,N=x(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=m(b,i,c);h(b,e,t,p)}else if(O){const e=g(u,i.children,c);h(b,e,t,p)}else if(Number.isNaN(parseFloat(i.name)))if(N){const e=m(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=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}`)}else if(x(b)&&!v){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=g([{dummy:!0,children:e||[]}],d,R(e||[]));return j(b[0])},A=(e,t,s)=>{const a=e.key||t,i=n.cloneElement(e,{key:a});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)}))},P=(e,n)=>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(" component prop expects an object or an array"),null):null;function L(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:m,shouldUnescape:h,...g}=e;const x=f||I();if(!x)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=m||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||i,{hashTransKey:w}=v,k=i||(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&&!x.options?.interpolation?.alwaysFormat||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},j={...o,context:r||o.context,count:s,...l,...S,defaultValue:N,ns:E},R=k?b(k,j):N,A=P(u,R),L=C(A||t,R,x,v,j,h),V=a??v.defaultTransParent;return V?n.createElement(V,g,L):L}const V={type:"3rdParty",init(e){N(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:i}=n.useContext(z)||{},r=s||a||I();if(r&&!r.reportNamespaces&&(r.reportNamespaces=new F),!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||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(D(e,t,s,a),[e,t,s,a]))(r,t.lng||null,"fallback"===o.nsMode?u:u[0],c),g=()=>f,b=()=>D(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?h(r,t.lng,u,(()=>{w.current&&E(b)})):m(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 k=[v,r,p];if(k.t=v,k.i18n=r,k.ready=p,p)return k;if(!p&&!l)return k;throw new Promise((e=>{t.lng?h(r,t.lng,u,(()=>e())):m(r,u,(()=>e()))}))};const W=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:a}=s,{i18n:i}=n.useContext(z)||{},r=a||i||I();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=z,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(z.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:m,...h}=e;const{i18n:g,defaultNS:y}=n.useContext(z)||{},x=d||g||I(),b=f||x?.t.bind(x);return L({children:t,count:s,parent:a,i18nKey:i,context:r,tOptions:o,values:l,defaults:c,components:u,ns:p||b?.ns||y||x?.options?.defaultNS,i18n:x,t:f,shouldUnescape:m,...h})},e.TransWithoutContext=L,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[a,i,r]=K(n,s);return t(a,{i18n:i,lng:i.language},r)},e.composeInitialProps=U,e.date=()=>"",e.getDefaults=$,e.getI18n=I,e.getInitialProps=B,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=N,e.setI18n=k,e.time=()=>"",e.useSSR=W,e.useTranslation=K,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:a,...i}=t;return W(s,a),n.createElement(e,{...i})}return t.getInitialProps=U(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]=K(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}}})); +!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}}})); diff --git a/src/TransWithoutContext.js b/src/TransWithoutContext.js index 270d92c24..f47a99ef4 100644 --- a/src/TransWithoutContext.js +++ b/src/TransWithoutContext.js @@ -29,7 +29,7 @@ const mergeProps = (source, target) => { return newTarget; }; -export const nodesToString = (children, i18nOptions) => { +export const nodesToString = (children, i18nOptions, i18n, i18nKey) => { if (!children) return ''; let stringNode = ''; @@ -72,11 +72,11 @@ export const nodesToString = (children, i18nOptions) => { stringNode += `<${type}>${childChildren}`; } else { // regular case mapping the inner children - const content = nodesToString(childChildren, i18nOptions); + const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey); stringNode += `<${childIndex}>${content}`; } } else if (child === null) { - warn(`Trans: the passed in value is invalid - seems you passed in a null child.`); + warn(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`); } else if (isObject(child)) { // e.g. lorem {{ value, format }} ipsum const { format, ...clone } = child; @@ -88,14 +88,18 @@ export const nodesToString = (children, i18nOptions) => { } else { // not a valid interpolation object (can only contain one value plus format) 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, ); } } 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, ); } }); @@ -332,7 +336,7 @@ const generateObjectComponents = (components, translation) => { return componentMap; }; -const generateComponents = (components, translation) => { +const generateComponents = (components, translation, i18n) => { if (!components) return null; // components could be either an array or an object @@ -347,7 +351,7 @@ const generateComponents = (components, translation) => { // if components is not an array or an object, warn the user // and return null - warnOnce(' component prop expects an object or an array'); + warnOnce(i18n, ' component prop expects an object or an array'); return null; }; @@ -370,7 +374,7 @@ export function Trans({ const i18n = i18nFromProps || getI18n(); if (!i18n) { - warnOnce('You will need to pass in an i18next instance by using i18nextReactModule'); + warnOnce(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule'); return children; } @@ -382,7 +386,7 @@ export function Trans({ let namespaces = ns || t.ns || i18n.options?.defaultNS; namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation']; - const nodeAsString = nodesToString(children, reactI18nextOptions); + const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey); const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey; const { hashTransKey } = reactI18nextOptions; @@ -413,7 +417,7 @@ export function Trans({ }; const translation = key ? t(key, combinedTOpts) : defaultValue; - const generatedComponents = generateComponents(components, translation); + const generatedComponents = generateComponents(components, translation, i18n); const content = renderNodes( generatedComponents || children, diff --git a/src/useTranslation.js b/src/useTranslation.js index 7b9b4426d..8241e1c20 100644 --- a/src/useTranslation.js +++ b/src/useTranslation.js @@ -35,7 +35,7 @@ export const useTranslation = (ns, props = {}) => { const i18n = i18nFromProps || i18nFromContext || getI18n(); if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces(); if (!i18n) { - warnOnce('You will need to pass in an i18next instance by using initReactI18next'); + warnOnce(i18n, '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)) @@ -51,6 +51,7 @@ export const useTranslation = (ns, props = {}) => { 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.', ); diff --git a/src/utils.js b/src/utils.js index 7cb32facc..0c96bd8f0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,23 +1,28 @@ -export const warn = (...args) => { - if (console?.warn) { +export const warn = (i18n, ...args) => { + 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]}`; + i18n.services.logger.warn(...args); + } else if (console?.warn) { if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`; console.warn(...args); } }; const alreadyWarned = {}; -export const warnOnce = (...args) => { +export const warnOnce = (i18n, ...args) => { if (isString(args[0]) && alreadyWarned[args[0]]) return; if (isString(args[0])) alreadyWarned[args[0]] = new Date(); - warn(...args); + warn(i18n, ...args); }; // not needed right now // -// export const deprecated = (...args) => { +// export const deprecated = (i18n, ...args) => { // if (process && process.env && (!process.env.NODE_ENV || process.env.NODE_ENV === 'development')) { // if (isString(args[0])) args[0] = `deprecation warning -> ${args[0]}`; -// warnOnce(...args); +// warnOnce(i18n, ...args); // } // } @@ -55,7 +60,7 @@ export const loadLanguages = (i18n, lng, ns, cb) => { export const hasLoadedNamespace = (ns, i18n, options = {}) => { if (!i18n.languages || !i18n.languages.length) { - warnOnce('i18n.languages were undefined or empty', i18n.languages); + warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages); return true; }