react-i18next 15.2.0 → 15.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 15.3.0
2
+
3
+ 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
4
+
1
5
  ### 15.2.0
2
6
 
3
7
  This version may be breaking if you still use React < v18 with TypeScript.
@@ -114,23 +114,28 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
114
114
  }
115
115
  };
116
116
 
117
- const warn = function () {
118
- if (console?.warn) {
119
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
120
- args[_key] = arguments[_key];
121
- }
117
+ const warn = function (i18n) {
118
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
119
+ args[_key - 1] = arguments[_key];
120
+ }
121
+ if (i18n?.services?.logger?.forward) {
122
+ i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
123
+ } else if (i18n?.services?.logger?.warn) {
124
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
125
+ i18n.services.logger.warn(...args);
126
+ } else if (console?.warn) {
122
127
  if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
123
128
  console.warn(...args);
124
129
  }
125
130
  };
126
131
  const alreadyWarned = {};
127
- const warnOnce = function () {
128
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
129
- args[_key2] = arguments[_key2];
132
+ const warnOnce = function (i18n) {
133
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
134
+ args[_key2 - 1] = arguments[_key2];
130
135
  }
131
136
  if (isString(args[0]) && alreadyWarned[args[0]]) return;
132
137
  if (isString(args[0])) alreadyWarned[args[0]] = new Date();
133
- warn(...args);
138
+ warn(i18n, ...args);
134
139
  };
135
140
  const loadedClb = (i18n, cb) => () => {
136
141
  if (i18n.isInitialized) {
@@ -159,7 +164,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
159
164
  const hasLoadedNamespace = function (ns, i18n) {
160
165
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
161
166
  if (!i18n.languages || !i18n.languages.length) {
162
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
167
+ warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages);
163
168
  return true;
164
169
  }
165
170
  return i18n.hasLoadedNamespace(ns, {
@@ -244,7 +249,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
244
249
  newTarget.props = Object.assign(source.props, target.props);
245
250
  return newTarget;
246
251
  };
247
- const nodesToString = (children, i18nOptions) => {
252
+ const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
248
253
  if (!children) return '';
249
254
  let stringNode = '';
250
255
  const childrenArray = getAsArray(children);
@@ -267,11 +272,11 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
267
272
  } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
268
273
  stringNode += `<${type}>${childChildren}</${type}>`;
269
274
  } else {
270
- const content = nodesToString(childChildren, i18nOptions);
275
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
271
276
  stringNode += `<${childIndex}>${content}</${childIndex}>`;
272
277
  }
273
278
  } else if (child === null) {
274
- warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
279
+ warn(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`);
275
280
  } else if (isObject(child)) {
276
281
  const {
277
282
  format,
@@ -282,10 +287,10 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
282
287
  const value = format ? `${keys[0]}, ${format}` : keys[0];
283
288
  stringNode += `{{${value}}}`;
284
289
  } else {
285
- warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
290
+ 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);
286
291
  }
287
292
  } else {
288
- 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);
293
+ 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);
289
294
  }
290
295
  });
291
296
  return stringNode;
@@ -429,7 +434,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
429
434
  });
430
435
  return componentMap;
431
436
  };
432
- const generateComponents = (components, translation) => {
437
+ const generateComponents = (components, translation, i18n) => {
433
438
  if (!components) return null;
434
439
  if (Array.isArray(components)) {
435
440
  return generateArrayComponents(components, translation);
@@ -437,7 +442,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
437
442
  if (isObject(components)) {
438
443
  return generateObjectComponents(components, translation);
439
444
  }
440
- warnOnce('<Trans /> component prop expects an object or an array');
445
+ warnOnce(i18n, '<Trans /> component prop expects an object or an array');
441
446
  return null;
442
447
  };
443
448
  function Trans$1(_ref) {
@@ -459,7 +464,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
459
464
  } = _ref;
460
465
  const i18n = i18nFromProps || getI18n();
461
466
  if (!i18n) {
462
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
467
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule');
463
468
  return children;
464
469
  }
465
470
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
@@ -469,7 +474,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
469
474
  };
470
475
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
471
476
  namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
472
- const nodeAsString = nodesToString(children, reactI18nextOptions);
477
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
473
478
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
474
479
  const {
475
480
  hashTransKey
@@ -500,7 +505,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
500
505
  ns: namespaces
501
506
  };
502
507
  const translation = key ? t(key, combinedTOpts) : defaultValue;
503
- const generatedComponents = generateComponents(components, translation);
508
+ const generatedComponents = generateComponents(components, translation, i18n);
504
509
  const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
505
510
  const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
506
511
  return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
@@ -614,7 +619,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
614
619
  const i18n = i18nFromProps || i18nFromContext || getI18n();
615
620
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
616
621
  if (!i18n) {
617
- warnOnce('You will need to pass in an i18next instance by using initReactI18next');
622
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using initReactI18next');
618
623
  const notReadyT = (k, optsOrDefaultValue) => {
619
624
  if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
620
625
  if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
@@ -626,7 +631,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
626
631
  retNotReady.ready = false;
627
632
  return retNotReady;
628
633
  }
629
- if (i18n.options.react?.wait) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
634
+ 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.');
630
635
  const i18nOptions = {
631
636
  ...getDefaults(),
632
637
  ...i18n.options.react,
@@ -1 +1 @@
1
- define(["exports","react"],(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),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!--"),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<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)}},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,v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},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 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}></${a}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}</${r}>`;else{const e=T(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(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}</0>`),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 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},r):r,b=n.isValidElement(v),E=b&&S(i,!0)&&!i.voidElement,O=l&&x(v)&&v.dummy&&!b,N=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(S(v)||E){const e=m(v,i,c);h(v,e,t,p)}else if(O){const e=g(u,i.children,c);h(v,e,t,p)}else if(Number.isNaN(parseFloat(i.name)))if(N){const e=m(v,i,c);h(v,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(x(v)&&!b){const e=i.children[0]?d:null;e&&t.push(e)}else h(v,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}),[])},v=g([{dummy:!0,children:e||[]}],d,R(e||[]));return j(v[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("<Trans /> 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 v=m||x.t.bind(x)||(e=>e),b={...$(),...x.options?.react};let E=p||v.ns||x.options?.defaultNS;E=y(E)?[E]:E||["translation"];const O=T(t,b),N=c||O||b.transEmptyNodeValue||i,{hashTransKey:w}=b,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?v(k,j):N,A=P(u,R),L=C(A||t,R,x,b,j,h),V=a??b.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,v=()=>D(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?h(r,t.lng,u,(()=>{w.current&&E(v)})):m(r,u,(()=>{w.current&&E(v)}))),p&&N&&N!==O&&w.current&&E(v);const s=()=>{w.current&&E(v)};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=[b,r,p];if(k.t=b,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(),v=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||v?.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}}}));
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 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!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=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),v=e.slice(m,-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(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),s=1;s<n;s++)t[s-1]=arguments[s];e?.services?.logger?.forward?e.services.logger.forward(t,"warn","react-i18next::",!0):e?.services?.logger?.warn?(y(t[0])&&(t[0]=`react-i18next:: ${t[0]}`),e.services.logger.warn(...t)):console?.warn&&(y(t[0])&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t))},p={},d=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),s=1;s<n;s++)t[s-1]=arguments[s];y(t[0])&&p[t[0]]||(y(t[0])&&(p[t[0]]=new Date),u(e,...t))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,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={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},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 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}></${i}>`;else if(u&&1===c&&y(p))r+=`<${l}>${p}</${l}>`;else{const e=T(p,t,s,a);r+=`<${i}>${e}</${i}>`}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(v(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)):v(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),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 x=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(x),E=b&&S(r,!0)&&!r.voidElement,O=l&&v(x)&&x.dummy&&!b,w=v(e)&&Object.hasOwnProperty.call(e,r.name);if(y(x)){const e=s.services.interpolator.interpolate(x,f,s.language);t.push(e)}else if(S(x)||E){const e=m(x,r,c);g(x,e,t,p)}else if(O){const e=h(u,r.children,c);g(x,e,t,p)}else if(Number.isNaN(parseFloat(r.name)))if(w){const e=m(x,r,c);g(x,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}</${r.name}>`)}else if(v(x)&&!b){const e=r.children[0]?d:null;e&&t.push(e)}else g(x,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}),[])},x=h([{dummy:!0,children:e||[]}],d,R(e||[]));return j(x[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):v(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,"<Trans /> 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 v=f||I();if(!v)return d(v,"You will need to pass in an i18next instance by using i18nextReactModule"),t;const x=m||v.t.bind(v)||(e=>e),b={...N(),...v.options?.react};let E=p||x.ns||v.options?.defaultNS;E=y(E)?[E]:E||["translation"];const O=T(t,b,v,r),w=c||O||b.transEmptyNodeValue||r,{hashTransKey:$}=b,k=r||($?$(O||w):O||w);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&&!v.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?x(k,j):w,A=P(u,R,v),L=C(A||t,R,v,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: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}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,x=()=>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(x)})):m(i,u,(()=>{$.current&&E(x)}))),p&&w&&w!==O&&$.current&&E(x);const s=()=>{$.current&&E(x)};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)||{},v=d||h||I(),x=f||v?.t.bind(v);return L({children:t,count:s,parent:a,i18nKey:r,context:i,tOptions:o,values:l,defaults:c,components:u,ns:p||x?.ns||y||v?.options?.defaultNS,i18n:v,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}}}));
@@ -31,7 +31,7 @@ const mergeProps = (source, target) => {
31
31
  newTarget.props = Object.assign(source.props, target.props);
32
32
  return newTarget;
33
33
  };
34
- const nodesToString = (children, i18nOptions) => {
34
+ const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
35
35
  if (!children) return '';
36
36
  let stringNode = '';
37
37
  const childrenArray = getAsArray(children);
@@ -54,11 +54,11 @@ const nodesToString = (children, i18nOptions) => {
54
54
  } else if (shouldKeepChild && childPropsCount === 1 && (0, _utils.isString)(childChildren)) {
55
55
  stringNode += `<${type}>${childChildren}</${type}>`;
56
56
  } else {
57
- const content = nodesToString(childChildren, i18nOptions);
57
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
58
58
  stringNode += `<${childIndex}>${content}</${childIndex}>`;
59
59
  }
60
60
  } else if (child === null) {
61
- (0, _utils.warn)(`Trans: the passed in value is invalid - seems you passed in a null child.`);
61
+ (0, _utils.warn)(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`);
62
62
  } else if ((0, _utils.isObject)(child)) {
63
63
  const {
64
64
  format,
@@ -69,10 +69,10 @@ const nodesToString = (children, i18nOptions) => {
69
69
  const value = format ? `${keys[0]}, ${format}` : keys[0];
70
70
  stringNode += `{{${value}}}`;
71
71
  } else {
72
- (0, _utils.warn)(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
72
+ (0, _utils.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);
73
73
  }
74
74
  } else {
75
- (0, _utils.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);
75
+ (0, _utils.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);
76
76
  }
77
77
  });
78
78
  return stringNode;
@@ -217,7 +217,7 @@ const generateObjectComponents = (components, translation) => {
217
217
  });
218
218
  return componentMap;
219
219
  };
220
- const generateComponents = (components, translation) => {
220
+ const generateComponents = (components, translation, i18n) => {
221
221
  if (!components) return null;
222
222
  if (Array.isArray(components)) {
223
223
  return generateArrayComponents(components, translation);
@@ -225,7 +225,7 @@ const generateComponents = (components, translation) => {
225
225
  if ((0, _utils.isObject)(components)) {
226
226
  return generateObjectComponents(components, translation);
227
227
  }
228
- (0, _utils.warnOnce)('<Trans /> component prop expects an object or an array');
228
+ (0, _utils.warnOnce)(i18n, '<Trans /> component prop expects an object or an array');
229
229
  return null;
230
230
  };
231
231
  function Trans(_ref) {
@@ -247,7 +247,7 @@ function Trans(_ref) {
247
247
  } = _ref;
248
248
  const i18n = i18nFromProps || (0, _i18nInstance.getI18n)();
249
249
  if (!i18n) {
250
- (0, _utils.warnOnce)('You will need to pass in an i18next instance by using i18nextReactModule');
250
+ (0, _utils.warnOnce)(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule');
251
251
  return children;
252
252
  }
253
253
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
@@ -257,7 +257,7 @@ function Trans(_ref) {
257
257
  };
258
258
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
259
259
  namespaces = (0, _utils.isString)(namespaces) ? [namespaces] : namespaces || ['translation'];
260
- const nodeAsString = nodesToString(children, reactI18nextOptions);
260
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
261
261
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
262
262
  const {
263
263
  hashTransKey
@@ -288,7 +288,7 @@ function Trans(_ref) {
288
288
  ns: namespaces
289
289
  };
290
290
  const translation = key ? t(key, combinedTOpts) : defaultValue;
291
- const generatedComponents = generateComponents(components, translation);
291
+ const generatedComponents = generateComponents(components, translation, i18n);
292
292
  const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
293
293
  const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
294
294
  return useAsParent ? (0, _react.createElement)(useAsParent, additionalProps, content) : content;
@@ -28,7 +28,7 @@ const useTranslation = function (ns) {
28
28
  const i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)();
29
29
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new _context.ReportNamespaces();
30
30
  if (!i18n) {
31
- (0, _utils.warnOnce)('You will need to pass in an i18next instance by using initReactI18next');
31
+ (0, _utils.warnOnce)(i18n, 'You will need to pass in an i18next instance by using initReactI18next');
32
32
  const notReadyT = (k, optsOrDefaultValue) => {
33
33
  if ((0, _utils.isString)(optsOrDefaultValue)) return optsOrDefaultValue;
34
34
  if ((0, _utils.isObject)(optsOrDefaultValue) && (0, _utils.isString)(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
@@ -40,7 +40,7 @@ const useTranslation = function (ns) {
40
40
  retNotReady.ready = false;
41
41
  return retNotReady;
42
42
  }
43
- 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.');
43
+ if (i18n.options.react?.wait) (0, _utils.warnOnce)(i18n, 'It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
44
44
  const i18nOptions = {
45
45
  ...(0, _context.getDefaults)(),
46
46
  ...i18n.options.react,
@@ -4,24 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.warnOnce = exports.warn = exports.loadNamespaces = exports.loadLanguages = exports.isString = exports.isObject = exports.hasLoadedNamespace = exports.getDisplayName = void 0;
7
- const warn = function () {
8
- if (console?.warn) {
9
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
- args[_key] = arguments[_key];
11
- }
7
+ const warn = function (i18n) {
8
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
9
+ args[_key - 1] = arguments[_key];
10
+ }
11
+ if (i18n?.services?.logger?.forward) {
12
+ i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
13
+ } else if (i18n?.services?.logger?.warn) {
14
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
15
+ i18n.services.logger.warn(...args);
16
+ } else if (console?.warn) {
12
17
  if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
13
18
  console.warn(...args);
14
19
  }
15
20
  };
16
21
  exports.warn = warn;
17
22
  const alreadyWarned = {};
18
- const warnOnce = function () {
19
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
20
- args[_key2] = arguments[_key2];
23
+ const warnOnce = function (i18n) {
24
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
25
+ args[_key2 - 1] = arguments[_key2];
21
26
  }
22
27
  if (isString(args[0]) && alreadyWarned[args[0]]) return;
23
28
  if (isString(args[0])) alreadyWarned[args[0]] = new Date();
24
- warn(...args);
29
+ warn(i18n, ...args);
25
30
  };
26
31
  exports.warnOnce = warnOnce;
27
32
  const loadedClb = (i18n, cb) => () => {
@@ -53,7 +58,7 @@ exports.loadLanguages = loadLanguages;
53
58
  const hasLoadedNamespace = function (ns, i18n) {
54
59
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
55
60
  if (!i18n.languages || !i18n.languages.length) {
56
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
61
+ warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages);
57
62
  return true;
58
63
  }
59
64
  return i18n.hasLoadedNamespace(ns, {
@@ -23,7 +23,7 @@ const mergeProps = (source, target) => {
23
23
  newTarget.props = Object.assign(source.props, target.props);
24
24
  return newTarget;
25
25
  };
26
- export const nodesToString = (children, i18nOptions) => {
26
+ export const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
27
27
  if (!children) return '';
28
28
  let stringNode = '';
29
29
  const childrenArray = getAsArray(children);
@@ -46,11 +46,11 @@ export const nodesToString = (children, i18nOptions) => {
46
46
  } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
47
47
  stringNode += `<${type}>${childChildren}</${type}>`;
48
48
  } else {
49
- const content = nodesToString(childChildren, i18nOptions);
49
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
50
50
  stringNode += `<${childIndex}>${content}</${childIndex}>`;
51
51
  }
52
52
  } else if (child === null) {
53
- warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
53
+ warn(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`);
54
54
  } else if (isObject(child)) {
55
55
  const {
56
56
  format,
@@ -61,10 +61,10 @@ export const nodesToString = (children, i18nOptions) => {
61
61
  const value = format ? `${keys[0]}, ${format}` : keys[0];
62
62
  stringNode += `{{${value}}}`;
63
63
  } else {
64
- warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
64
+ 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);
65
65
  }
66
66
  } else {
67
- 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);
67
+ 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);
68
68
  }
69
69
  });
70
70
  return stringNode;
@@ -208,7 +208,7 @@ const generateObjectComponents = (components, translation) => {
208
208
  });
209
209
  return componentMap;
210
210
  };
211
- const generateComponents = (components, translation) => {
211
+ const generateComponents = (components, translation, i18n) => {
212
212
  if (!components) return null;
213
213
  if (Array.isArray(components)) {
214
214
  return generateArrayComponents(components, translation);
@@ -216,7 +216,7 @@ const generateComponents = (components, translation) => {
216
216
  if (isObject(components)) {
217
217
  return generateObjectComponents(components, translation);
218
218
  }
219
- warnOnce('<Trans /> component prop expects an object or an array');
219
+ warnOnce(i18n, '<Trans /> component prop expects an object or an array');
220
220
  return null;
221
221
  };
222
222
  export function Trans({
@@ -237,7 +237,7 @@ export function Trans({
237
237
  }) {
238
238
  const i18n = i18nFromProps || getI18n();
239
239
  if (!i18n) {
240
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
240
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule');
241
241
  return children;
242
242
  }
243
243
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
@@ -247,7 +247,7 @@ export function Trans({
247
247
  };
248
248
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
249
249
  namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
250
- const nodeAsString = nodesToString(children, reactI18nextOptions);
250
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
251
251
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
252
252
  const {
253
253
  hashTransKey
@@ -278,7 +278,7 @@ export function Trans({
278
278
  ns: namespaces
279
279
  };
280
280
  const translation = key ? t(key, combinedTOpts) : defaultValue;
281
- const generatedComponents = generateComponents(components, translation);
281
+ const generatedComponents = generateComponents(components, translation, i18n);
282
282
  const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
283
283
  const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
284
284
  return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
@@ -1 +1 @@
1
- {"type":"module","version":"15.2.0"}
1
+ {"type":"module","version":"15.3.0"}
@@ -21,7 +21,7 @@ export const useTranslation = (ns, props = {}) => {
21
21
  const i18n = i18nFromProps || i18nFromContext || getI18n();
22
22
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
23
23
  if (!i18n) {
24
- warnOnce('You will need to pass in an i18next instance by using initReactI18next');
24
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using initReactI18next');
25
25
  const notReadyT = (k, optsOrDefaultValue) => {
26
26
  if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
27
27
  if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
@@ -33,7 +33,7 @@ export const useTranslation = (ns, props = {}) => {
33
33
  retNotReady.ready = false;
34
34
  return retNotReady;
35
35
  }
36
- if (i18n.options.react?.wait) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
36
+ 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.');
37
37
  const i18nOptions = {
38
38
  ...getDefaults(),
39
39
  ...i18n.options.react,
package/dist/es/utils.js CHANGED
@@ -1,14 +1,19 @@
1
- export const warn = (...args) => {
2
- if (console?.warn) {
1
+ export const warn = (i18n, ...args) => {
2
+ if (i18n?.services?.logger?.forward) {
3
+ i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
4
+ } else if (i18n?.services?.logger?.warn) {
5
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
6
+ i18n.services.logger.warn(...args);
7
+ } else if (console?.warn) {
3
8
  if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
4
9
  console.warn(...args);
5
10
  }
6
11
  };
7
12
  const alreadyWarned = {};
8
- export const warnOnce = (...args) => {
13
+ export const warnOnce = (i18n, ...args) => {
9
14
  if (isString(args[0]) && alreadyWarned[args[0]]) return;
10
15
  if (isString(args[0])) alreadyWarned[args[0]] = new Date();
11
- warn(...args);
16
+ warn(i18n, ...args);
12
17
  };
13
18
  const loadedClb = (i18n, cb) => () => {
14
19
  if (i18n.isInitialized) {
@@ -36,7 +41,7 @@ export const loadLanguages = (i18n, lng, ns, cb) => {
36
41
  };
37
42
  export const hasLoadedNamespace = (ns, i18n, options = {}) => {
38
43
  if (!i18n.languages || !i18n.languages.length) {
39
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
44
+ warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages);
40
45
  return true;
41
46
  }
42
47
  return i18n.hasLoadedNamespace(ns, {
@@ -118,23 +118,28 @@
118
118
  }
119
119
  };
120
120
 
121
- const warn = function () {
122
- if (console?.warn) {
123
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
124
- args[_key] = arguments[_key];
125
- }
121
+ const warn = function (i18n) {
122
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
123
+ args[_key - 1] = arguments[_key];
124
+ }
125
+ if (i18n?.services?.logger?.forward) {
126
+ i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
127
+ } else if (i18n?.services?.logger?.warn) {
128
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
129
+ i18n.services.logger.warn(...args);
130
+ } else if (console?.warn) {
126
131
  if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
127
132
  console.warn(...args);
128
133
  }
129
134
  };
130
135
  const alreadyWarned = {};
131
- const warnOnce = function () {
132
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
133
- args[_key2] = arguments[_key2];
136
+ const warnOnce = function (i18n) {
137
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
138
+ args[_key2 - 1] = arguments[_key2];
134
139
  }
135
140
  if (isString(args[0]) && alreadyWarned[args[0]]) return;
136
141
  if (isString(args[0])) alreadyWarned[args[0]] = new Date();
137
- warn(...args);
142
+ warn(i18n, ...args);
138
143
  };
139
144
  const loadedClb = (i18n, cb) => () => {
140
145
  if (i18n.isInitialized) {
@@ -163,7 +168,7 @@
163
168
  const hasLoadedNamespace = function (ns, i18n) {
164
169
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
165
170
  if (!i18n.languages || !i18n.languages.length) {
166
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
171
+ warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages);
167
172
  return true;
168
173
  }
169
174
  return i18n.hasLoadedNamespace(ns, {
@@ -248,7 +253,7 @@
248
253
  newTarget.props = Object.assign(source.props, target.props);
249
254
  return newTarget;
250
255
  };
251
- const nodesToString = (children, i18nOptions) => {
256
+ const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
252
257
  if (!children) return '';
253
258
  let stringNode = '';
254
259
  const childrenArray = getAsArray(children);
@@ -271,11 +276,11 @@
271
276
  } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
272
277
  stringNode += `<${type}>${childChildren}</${type}>`;
273
278
  } else {
274
- const content = nodesToString(childChildren, i18nOptions);
279
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
275
280
  stringNode += `<${childIndex}>${content}</${childIndex}>`;
276
281
  }
277
282
  } else if (child === null) {
278
- warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
283
+ warn(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`);
279
284
  } else if (isObject(child)) {
280
285
  const {
281
286
  format,
@@ -286,10 +291,10 @@
286
291
  const value = format ? `${keys[0]}, ${format}` : keys[0];
287
292
  stringNode += `{{${value}}}`;
288
293
  } else {
289
- warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
294
+ 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);
290
295
  }
291
296
  } else {
292
- 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);
297
+ 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);
293
298
  }
294
299
  });
295
300
  return stringNode;
@@ -433,7 +438,7 @@
433
438
  });
434
439
  return componentMap;
435
440
  };
436
- const generateComponents = (components, translation) => {
441
+ const generateComponents = (components, translation, i18n) => {
437
442
  if (!components) return null;
438
443
  if (Array.isArray(components)) {
439
444
  return generateArrayComponents(components, translation);
@@ -441,7 +446,7 @@
441
446
  if (isObject(components)) {
442
447
  return generateObjectComponents(components, translation);
443
448
  }
444
- warnOnce('<Trans /> component prop expects an object or an array');
449
+ warnOnce(i18n, '<Trans /> component prop expects an object or an array');
445
450
  return null;
446
451
  };
447
452
  function Trans$1(_ref) {
@@ -463,7 +468,7 @@
463
468
  } = _ref;
464
469
  const i18n = i18nFromProps || getI18n();
465
470
  if (!i18n) {
466
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
471
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule');
467
472
  return children;
468
473
  }
469
474
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
@@ -473,7 +478,7 @@
473
478
  };
474
479
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
475
480
  namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
476
- const nodeAsString = nodesToString(children, reactI18nextOptions);
481
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
477
482
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
478
483
  const {
479
484
  hashTransKey
@@ -504,7 +509,7 @@
504
509
  ns: namespaces
505
510
  };
506
511
  const translation = key ? t(key, combinedTOpts) : defaultValue;
507
- const generatedComponents = generateComponents(components, translation);
512
+ const generatedComponents = generateComponents(components, translation, i18n);
508
513
  const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
509
514
  const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
510
515
  return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
@@ -618,7 +623,7 @@
618
623
  const i18n = i18nFromProps || i18nFromContext || getI18n();
619
624
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
620
625
  if (!i18n) {
621
- warnOnce('You will need to pass in an i18next instance by using initReactI18next');
626
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using initReactI18next');
622
627
  const notReadyT = (k, optsOrDefaultValue) => {
623
628
  if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
624
629
  if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
@@ -630,7 +635,7 @@
630
635
  retNotReady.ready = false;
631
636
  return retNotReady;
632
637
  }
633
- if (i18n.options.react?.wait) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
638
+ 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.');
634
639
  const i18nOptions = {
635
640
  ...getDefaults(),
636
641
  ...i18n.options.react,
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),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!--"),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<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)}},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={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},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}></${a}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}</${r}>`;else{const e=T(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(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}</0>`),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}</${i.name}>`)}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("<Trans /> 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}}}));
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!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=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;s<n;s++)t[s-1]=arguments[s];e?.services?.logger?.forward?e.services.logger.forward(t,"warn","react-i18next::",!0):e?.services?.logger?.warn?(y(t[0])&&(t[0]=`react-i18next:: ${t[0]}`),e.services.logger.warn(...t)):console?.warn&&(y(t[0])&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t))},p={},d=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),s=1;s<n;s++)t[s-1]=arguments[s];y(t[0])&&p[t[0]]||(y(t[0])&&(p[t[0]]=new Date),u(e,...t))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},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}></${i}>`;else if(u&&1===c&&y(p))r+=`<${l}>${p}</${l}>`;else{const e=T(p,t,s,a);r+=`<${i}>${e}</${i}>`}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}</0>`),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}</${r.name}>`)}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,"<Trans /> 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}}}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-i18next",
3
- "version": "15.2.0",
3
+ "version": "15.3.0",
4
4
  "description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
5
5
  "main": "dist/commonjs/index.js",
6
6
  "types": "./index.d.mts",
package/react-i18next.js CHANGED
@@ -118,23 +118,28 @@
118
118
  }
119
119
  };
120
120
 
121
- const warn = function () {
122
- if (console?.warn) {
123
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
124
- args[_key] = arguments[_key];
125
- }
121
+ const warn = function (i18n) {
122
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
123
+ args[_key - 1] = arguments[_key];
124
+ }
125
+ if (i18n?.services?.logger?.forward) {
126
+ i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
127
+ } else if (i18n?.services?.logger?.warn) {
128
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
129
+ i18n.services.logger.warn(...args);
130
+ } else if (console?.warn) {
126
131
  if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
127
132
  console.warn(...args);
128
133
  }
129
134
  };
130
135
  const alreadyWarned = {};
131
- const warnOnce = function () {
132
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
133
- args[_key2] = arguments[_key2];
136
+ const warnOnce = function (i18n) {
137
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
138
+ args[_key2 - 1] = arguments[_key2];
134
139
  }
135
140
  if (isString(args[0]) && alreadyWarned[args[0]]) return;
136
141
  if (isString(args[0])) alreadyWarned[args[0]] = new Date();
137
- warn(...args);
142
+ warn(i18n, ...args);
138
143
  };
139
144
  const loadedClb = (i18n, cb) => () => {
140
145
  if (i18n.isInitialized) {
@@ -163,7 +168,7 @@
163
168
  const hasLoadedNamespace = function (ns, i18n) {
164
169
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
165
170
  if (!i18n.languages || !i18n.languages.length) {
166
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
171
+ warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages);
167
172
  return true;
168
173
  }
169
174
  return i18n.hasLoadedNamespace(ns, {
@@ -248,7 +253,7 @@
248
253
  newTarget.props = Object.assign(source.props, target.props);
249
254
  return newTarget;
250
255
  };
251
- const nodesToString = (children, i18nOptions) => {
256
+ const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
252
257
  if (!children) return '';
253
258
  let stringNode = '';
254
259
  const childrenArray = getAsArray(children);
@@ -271,11 +276,11 @@
271
276
  } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
272
277
  stringNode += `<${type}>${childChildren}</${type}>`;
273
278
  } else {
274
- const content = nodesToString(childChildren, i18nOptions);
279
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
275
280
  stringNode += `<${childIndex}>${content}</${childIndex}>`;
276
281
  }
277
282
  } else if (child === null) {
278
- warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
283
+ warn(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`);
279
284
  } else if (isObject(child)) {
280
285
  const {
281
286
  format,
@@ -286,10 +291,10 @@
286
291
  const value = format ? `${keys[0]}, ${format}` : keys[0];
287
292
  stringNode += `{{${value}}}`;
288
293
  } else {
289
- warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
294
+ 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);
290
295
  }
291
296
  } else {
292
- 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);
297
+ 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);
293
298
  }
294
299
  });
295
300
  return stringNode;
@@ -433,7 +438,7 @@
433
438
  });
434
439
  return componentMap;
435
440
  };
436
- const generateComponents = (components, translation) => {
441
+ const generateComponents = (components, translation, i18n) => {
437
442
  if (!components) return null;
438
443
  if (Array.isArray(components)) {
439
444
  return generateArrayComponents(components, translation);
@@ -441,7 +446,7 @@
441
446
  if (isObject(components)) {
442
447
  return generateObjectComponents(components, translation);
443
448
  }
444
- warnOnce('<Trans /> component prop expects an object or an array');
449
+ warnOnce(i18n, '<Trans /> component prop expects an object or an array');
445
450
  return null;
446
451
  };
447
452
  function Trans$1(_ref) {
@@ -463,7 +468,7 @@
463
468
  } = _ref;
464
469
  const i18n = i18nFromProps || getI18n();
465
470
  if (!i18n) {
466
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
471
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule');
467
472
  return children;
468
473
  }
469
474
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
@@ -473,7 +478,7 @@
473
478
  };
474
479
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
475
480
  namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
476
- const nodeAsString = nodesToString(children, reactI18nextOptions);
481
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
477
482
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
478
483
  const {
479
484
  hashTransKey
@@ -504,7 +509,7 @@
504
509
  ns: namespaces
505
510
  };
506
511
  const translation = key ? t(key, combinedTOpts) : defaultValue;
507
- const generatedComponents = generateComponents(components, translation);
512
+ const generatedComponents = generateComponents(components, translation, i18n);
508
513
  const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
509
514
  const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
510
515
  return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
@@ -618,7 +623,7 @@
618
623
  const i18n = i18nFromProps || i18nFromContext || getI18n();
619
624
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
620
625
  if (!i18n) {
621
- warnOnce('You will need to pass in an i18next instance by using initReactI18next');
626
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using initReactI18next');
622
627
  const notReadyT = (k, optsOrDefaultValue) => {
623
628
  if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
624
629
  if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
@@ -630,7 +635,7 @@
630
635
  retNotReady.ready = false;
631
636
  return retNotReady;
632
637
  }
633
- if (i18n.options.react?.wait) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
638
+ 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.');
634
639
  const i18nOptions = {
635
640
  ...getDefaults(),
636
641
  ...i18n.options.react,
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),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!--"),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<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)}},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={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},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}></${a}>`;else if(l&&1===o&&y(c))s+=`<${r}>${c}</${r}>`;else{const e=T(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(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}</0>`),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}</${i.name}>`)}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("<Trans /> 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}}}));
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!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=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;s<n;s++)t[s-1]=arguments[s];e?.services?.logger?.forward?e.services.logger.forward(t,"warn","react-i18next::",!0):e?.services?.logger?.warn?(y(t[0])&&(t[0]=`react-i18next:: ${t[0]}`),e.services.logger.warn(...t)):console?.warn&&(y(t[0])&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t))},p={},d=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),s=1;s<n;s++)t[s-1]=arguments[s];y(t[0])&&p[t[0]]||(y(t[0])&&(p[t[0]]=new Date),u(e,...t))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},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}></${i}>`;else if(u&&1===c&&y(p))r+=`<${l}>${p}</${l}>`;else{const e=T(p,t,s,a);r+=`<${i}>${e}</${i}>`}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}</0>`),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}</${r.name}>`)}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,"<Trans /> 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}}}));
@@ -29,7 +29,7 @@ const mergeProps = (source, target) => {
29
29
  return newTarget;
30
30
  };
31
31
 
32
- export const nodesToString = (children, i18nOptions) => {
32
+ export const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
33
33
  if (!children) return '';
34
34
  let stringNode = '';
35
35
 
@@ -72,11 +72,11 @@ export const nodesToString = (children, i18nOptions) => {
72
72
  stringNode += `<${type}>${childChildren}</${type}>`;
73
73
  } else {
74
74
  // regular case mapping the inner children
75
- const content = nodesToString(childChildren, i18nOptions);
75
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
76
76
  stringNode += `<${childIndex}>${content}</${childIndex}>`;
77
77
  }
78
78
  } else if (child === null) {
79
- warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
79
+ warn(i18n, `Trans: the passed in value is invalid - seems you passed in a null child.`);
80
80
  } else if (isObject(child)) {
81
81
  // e.g. lorem {{ value, format }} ipsum
82
82
  const { format, ...clone } = child;
@@ -88,14 +88,18 @@ export const nodesToString = (children, i18nOptions) => {
88
88
  } else {
89
89
  // not a valid interpolation object (can only contain one value plus format)
90
90
  warn(
91
+ i18n,
91
92
  `react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`,
92
93
  child,
94
+ i18nKey,
93
95
  );
94
96
  }
95
97
  } else {
96
98
  warn(
99
+ i18n,
97
100
  `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}}.`,
98
101
  child,
102
+ i18nKey,
99
103
  );
100
104
  }
101
105
  });
@@ -332,7 +336,7 @@ const generateObjectComponents = (components, translation) => {
332
336
  return componentMap;
333
337
  };
334
338
 
335
- const generateComponents = (components, translation) => {
339
+ const generateComponents = (components, translation, i18n) => {
336
340
  if (!components) return null;
337
341
 
338
342
  // components could be either an array or an object
@@ -347,7 +351,7 @@ const generateComponents = (components, translation) => {
347
351
 
348
352
  // if components is not an array or an object, warn the user
349
353
  // and return null
350
- warnOnce('<Trans /> component prop expects an object or an array');
354
+ warnOnce(i18n, '<Trans /> component prop expects an object or an array');
351
355
  return null;
352
356
  };
353
357
 
@@ -370,7 +374,7 @@ export function Trans({
370
374
  const i18n = i18nFromProps || getI18n();
371
375
 
372
376
  if (!i18n) {
373
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
377
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using i18nextReactModule');
374
378
  return children;
375
379
  }
376
380
 
@@ -382,7 +386,7 @@ export function Trans({
382
386
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
383
387
  namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
384
388
 
385
- const nodeAsString = nodesToString(children, reactI18nextOptions);
389
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
386
390
  const defaultValue =
387
391
  defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
388
392
  const { hashTransKey } = reactI18nextOptions;
@@ -413,7 +417,7 @@ export function Trans({
413
417
  };
414
418
  const translation = key ? t(key, combinedTOpts) : defaultValue;
415
419
 
416
- const generatedComponents = generateComponents(components, translation);
420
+ const generatedComponents = generateComponents(components, translation, i18n);
417
421
 
418
422
  const content = renderNodes(
419
423
  generatedComponents || children,
@@ -35,7 +35,7 @@ export const useTranslation = (ns, props = {}) => {
35
35
  const i18n = i18nFromProps || i18nFromContext || getI18n();
36
36
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
37
37
  if (!i18n) {
38
- warnOnce('You will need to pass in an i18next instance by using initReactI18next');
38
+ warnOnce(i18n, 'You will need to pass in an i18next instance by using initReactI18next');
39
39
  const notReadyT = (k, optsOrDefaultValue) => {
40
40
  if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
41
41
  if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue))
@@ -51,6 +51,7 @@ export const useTranslation = (ns, props = {}) => {
51
51
 
52
52
  if (i18n.options.react?.wait)
53
53
  warnOnce(
54
+ i18n,
54
55
  'It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.',
55
56
  );
56
57
 
package/src/utils.js CHANGED
@@ -1,23 +1,28 @@
1
- export const warn = (...args) => {
2
- if (console?.warn) {
1
+ export const warn = (i18n, ...args) => {
2
+ if (i18n?.services?.logger?.forward) {
3
+ i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
4
+ } else if (i18n?.services?.logger?.warn) {
5
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
6
+ i18n.services.logger.warn(...args);
7
+ } else if (console?.warn) {
3
8
  if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
4
9
  console.warn(...args);
5
10
  }
6
11
  };
7
12
 
8
13
  const alreadyWarned = {};
9
- export const warnOnce = (...args) => {
14
+ export const warnOnce = (i18n, ...args) => {
10
15
  if (isString(args[0]) && alreadyWarned[args[0]]) return;
11
16
  if (isString(args[0])) alreadyWarned[args[0]] = new Date();
12
- warn(...args);
17
+ warn(i18n, ...args);
13
18
  };
14
19
 
15
20
  // not needed right now
16
21
  //
17
- // export const deprecated = (...args) => {
22
+ // export const deprecated = (i18n, ...args) => {
18
23
  // if (process && process.env && (!process.env.NODE_ENV || process.env.NODE_ENV === 'development')) {
19
24
  // if (isString(args[0])) args[0] = `deprecation warning -> ${args[0]}`;
20
- // warnOnce(...args);
25
+ // warnOnce(i18n, ...args);
21
26
  // }
22
27
  // }
23
28
 
@@ -55,7 +60,7 @@ export const loadLanguages = (i18n, lng, ns, cb) => {
55
60
 
56
61
  export const hasLoadedNamespace = (ns, i18n, options = {}) => {
57
62
  if (!i18n.languages || !i18n.languages.length) {
58
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
63
+ warnOnce(i18n, 'i18n.languages were undefined or empty', i18n.languages);
59
64
  return true;
60
65
  }
61
66