react-i18next 15.2.0 → 15.4.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,11 @@
1
+ ### 15.4.0
2
+
3
+ feat: add meta with codes on warnings to allow conditional logging [1826](https://github.com/i18next/react-i18next/pull/1826)
4
+
5
+ ### 15.3.0
6
+
7
+ 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
8
+
1
9
  ### 15.2.0
2
10
 
3
11
  This version may be breaking if you still use React < v18 with TypeScript.
@@ -35,3 +35,39 @@ export function Trans<
35
35
  TOpt extends TOptions & { context?: TContext } = { context: TContext },
36
36
  E = React.HTMLProps<HTMLDivElement>,
37
37
  >(props: TransProps<Key, Ns, KPrefix, TContext, TOpt, E>): React.ReactElement;
38
+
39
+ export type ErrorCode =
40
+ | 'NO_I18NEXT_INSTANCE'
41
+ | 'NO_LANGUAGES'
42
+ | 'DEPRECATED_OPTION'
43
+ | 'TRANS_NULL_VALUE'
44
+ | 'TRANS_INVALID_OBJ'
45
+ | 'TRANS_INVALID_VAR'
46
+ | 'TRANS_INVALID_COMPONENTS';
47
+
48
+ export type ErrorMeta = {
49
+ code: ErrorCode;
50
+ i18nKey?: string;
51
+ [x: string]: any;
52
+ };
53
+
54
+ /**
55
+ * Use to type the logger arguments
56
+ * @example
57
+ * ```
58
+ * import type { ErrorArgs } from 'react-i18next';
59
+ *
60
+ * const logger = {
61
+ * // ....
62
+ * warn: function (...args: ErrorArgs) {
63
+ * if (args[1]?.code === 'TRANS_INVALID_OBJ') {
64
+ * const [msg, { i18nKey, ...rest }] = args;
65
+ * return log(i18nKey, msg, rest);
66
+ * }
67
+ * log(...args);
68
+ * }
69
+ * }
70
+ * i18n.use(logger).use(i18nReactPlugin).init({...});
71
+ * ```
72
+ */
73
+ export type ErrorArgs = readonly [string, ErrorMeta | undefined, ...any[]];
@@ -114,23 +114,26 @@ 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
- }
122
- if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
117
+ const warn = (i18n, code, msg, rest) => {
118
+ const args = [msg, {
119
+ code,
120
+ ...(rest || {})
121
+ }];
122
+ if (i18n?.services?.logger?.forward) {
123
+ return i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
124
+ }
125
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
126
+ if (i18n?.services?.logger?.warn) {
127
+ i18n.services.logger.warn(...args);
128
+ } else if (console?.warn) {
123
129
  console.warn(...args);
124
130
  }
125
131
  };
126
132
  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];
130
- }
131
- if (isString(args[0]) && alreadyWarned[args[0]]) return;
132
- if (isString(args[0])) alreadyWarned[args[0]] = new Date();
133
- warn(...args);
133
+ const warnOnce = (i18n, code, msg, rest) => {
134
+ if (isString(msg) && alreadyWarned[msg]) return;
135
+ if (isString(msg)) alreadyWarned[msg] = new Date();
136
+ warn(i18n, code, msg, rest);
134
137
  };
135
138
  const loadedClb = (i18n, cb) => () => {
136
139
  if (i18n.isInitialized) {
@@ -159,7 +162,9 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
159
162
  const hasLoadedNamespace = function (ns, i18n) {
160
163
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
161
164
  if (!i18n.languages || !i18n.languages.length) {
162
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
165
+ warnOnce(i18n, 'NO_LANGUAGES', 'i18n.languages were undefined or empty', {
166
+ languages: i18n.languages
167
+ });
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);
@@ -252,7 +257,9 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
252
257
  childrenArray.forEach((child, childIndex) => {
253
258
  if (isString(child)) {
254
259
  stringNode += `${child}`;
255
- } else if (react.isValidElement(child)) {
260
+ return;
261
+ }
262
+ if (react.isValidElement(child)) {
256
263
  const {
257
264
  props,
258
265
  type
@@ -262,17 +269,27 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
262
269
  const childChildren = props.children;
263
270
  if (!childChildren && shouldKeepChild && !childPropsCount) {
264
271
  stringNode += `<${type}/>`;
265
- } else if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
272
+ return;
273
+ }
274
+ if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
266
275
  stringNode += `<${childIndex}></${childIndex}>`;
267
- } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
276
+ return;
277
+ }
278
+ if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
268
279
  stringNode += `<${type}>${childChildren}</${type}>`;
269
- } else {
270
- const content = nodesToString(childChildren, i18nOptions);
271
- stringNode += `<${childIndex}>${content}</${childIndex}>`;
280
+ return;
272
281
  }
273
- } else if (child === null) {
274
- warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
275
- } else if (isObject(child)) {
282
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
283
+ stringNode += `<${childIndex}>${content}</${childIndex}>`;
284
+ return;
285
+ }
286
+ if (child === null) {
287
+ warn(i18n, 'TRANS_NULL_VALUE', `Passed in a null value as child`, {
288
+ i18nKey
289
+ });
290
+ return;
291
+ }
292
+ if (isObject(child)) {
276
293
  const {
277
294
  format,
278
295
  ...clone
@@ -281,12 +298,18 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
281
298
  if (keys.length === 1) {
282
299
  const value = format ? `${keys[0]}, ${format}` : keys[0];
283
300
  stringNode += `{{${value}}}`;
284
- } 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);
301
+ return;
286
302
  }
287
- } 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);
303
+ warn(i18n, 'TRANS_INVALID_OBJ', `Invalid child - Object should only have keys {{ value, format }} (format is optional).`, {
304
+ i18nKey,
305
+ child
306
+ });
307
+ return;
289
308
  }
309
+ warn(i18n, 'TRANS_INVALID_VAR', `Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`, {
310
+ i18nKey,
311
+ child
312
+ });
290
313
  });
291
314
  return stringNode;
292
315
  };
@@ -429,7 +452,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
429
452
  });
430
453
  return componentMap;
431
454
  };
432
- const generateComponents = (components, translation) => {
455
+ const generateComponents = (components, translation, i18n, i18nKey) => {
433
456
  if (!components) return null;
434
457
  if (Array.isArray(components)) {
435
458
  return generateArrayComponents(components, translation);
@@ -437,7 +460,9 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
437
460
  if (isObject(components)) {
438
461
  return generateObjectComponents(components, translation);
439
462
  }
440
- warnOnce('<Trans /> component prop expects an object or an array');
463
+ warnOnce(i18n, 'TRANS_INVALID_COMPONENTS', `<Trans /> "components" prop expects an object or array`, {
464
+ i18nKey
465
+ });
441
466
  return null;
442
467
  };
443
468
  function Trans$1(_ref) {
@@ -459,7 +484,9 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
459
484
  } = _ref;
460
485
  const i18n = i18nFromProps || getI18n();
461
486
  if (!i18n) {
462
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
487
+ warnOnce(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
488
+ i18nKey
489
+ });
463
490
  return children;
464
491
  }
465
492
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
@@ -469,7 +496,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
469
496
  };
470
497
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
471
498
  namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
472
- const nodeAsString = nodesToString(children, reactI18nextOptions);
499
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
473
500
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
474
501
  const {
475
502
  hashTransKey
@@ -500,7 +527,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
500
527
  ns: namespaces
501
528
  };
502
529
  const translation = key ? t(key, combinedTOpts) : defaultValue;
503
- const generatedComponents = generateComponents(components, translation);
530
+ const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
504
531
  const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
505
532
  const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
506
533
  return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
@@ -614,7 +641,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
614
641
  const i18n = i18nFromProps || i18nFromContext || getI18n();
615
642
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
616
643
  if (!i18n) {
617
- warnOnce('You will need to pass in an i18next instance by using initReactI18next');
644
+ warnOnce(i18n, 'NO_I18NEXT_INSTANCE', 'useTranslation: You will need to pass in an i18next instance by using initReactI18next');
618
645
  const notReadyT = (k, optsOrDefaultValue) => {
619
646
  if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
620
647
  if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
@@ -626,7 +653,7 @@ define(['exports', 'react'], (function (exports, react) { 'use strict';
626
653
  retNotReady.ready = false;
627
654
  return retNotReady;
628
655
  }
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.');
656
+ if (i18n.options.react?.wait) warnOnce(i18n, 'DEPRECATED_OPTION', 'useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
630
657
  const i18nOptions = {
631
658
  ...getDefaults(),
632
659
  ...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}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),g=l+i.length,m=e.charAt(g);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!m||"<"===m||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==m&&m)){p=-1===c?s:r[c].children;var y=e.indexOf("<",g),v=e.slice(g,-1===y?void 0:y);o.test(v)&&(v=" "),(y>-1&&c+p.length>=0||" "!==v)&&p.push({type:"text",content:v})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},g=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},m=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return g(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,v=e=>"object"==typeof e&&null!==e,N=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},E=e=>x[e];let b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(N,E)};const O=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b={...b,...e}},I=()=>b;let S;const w=e=>{S=e},$=()=>S,k=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},T=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?A(n):n},A=e=>Array.isArray(e)?e:[e],R=(e,t,s,r)=>{if(!e)return"";let a="";const i=A(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=R(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(v(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i)=>{if(""===t)return[];const o=r.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!i)return[t];const u={},p=e=>{A(e).forEach((e=>{y(e)||(k(e)?p(T(e)):v(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},g=(e,t,s)=>{const r=T(e),a=h(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},m=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.ref},a?null:t)})))},h=(t,a,c)=>{const u=A(t);return A(a).reduce(((t,a,p)=>{const d=a.children?.[0]?.content&&s.services.interpolator.interpolate(a.children[0].content,f,s.language);if("tag"===a.type){let i=u[parseInt(a.name,10)];1!==c.length||i||(i=c[0][a.name]),i||(i={});const N=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},i):i,x=n.isValidElement(N),E=x&&k(a,!0)&&!a.voidElement,b=l&&v(N)&&N.dummy&&!x,O=v(e)&&Object.hasOwnProperty.call(e,a.name);if(y(N)){const e=s.services.interpolator.interpolate(N,f,s.language);t.push(e)}else if(k(N)||E){const e=g(N,a,c);m(N,e,t,p)}else if(b){const e=h(u,a.children,c);m(N,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(O){const e=g(N,a,c);m(N,e,t,p,a.voidElement)}else if(r.transSupportBasicHtmlNodes&&o.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=h(u,a.children,c);t.push(n.createElement(a.name,{key:`${a.name}-${p}`},e))}else if(a.voidElement)t.push(`<${a.name} />`);else{const e=h(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(v(N)&&!x){const e=a.children[0]?d:null;e&&t.push(e)}else m(N,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=r.transWrapTextNodes,o=i?r.unescape(s.services.interpolator.interpolate(a.content,f,s.language)):s.services.interpolator.interpolate(a.content,f,s.language);e?t.push(n.createElement(e,{key:`${a.name}-${p}`},o)):t.push(o)}return t}),[])},N=h([{dummy:!0,children:e||[]}],d,A(e||[]));return T(N[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}))},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):v(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null;function P(e){let{children:t,count:s,parent:r,i18nKey:a,context:i,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:g,shouldUnescape:m,...h}=e;const v=f||$();if(!v)return d(v,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:a}),t;const N=g||v.t.bind(v)||(e=>e),x={...I(),...v.options?.react};let E=p||N.ns||v.options?.defaultNS;E=y(E)?[E]:E||["translation"];const b=R(t,x,v,a),O=c||b||x.transEmptyNodeValue||a,{hashTransKey:S}=x,w=a||(S?S(b||O):b||O);v.options?.interpolation?.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...v.options.interpolation.defaultVariables}:{...v.options.interpolation.defaultVariables});const k=l||void 0!==s&&!v.options?.interpolation?.alwaysFormat||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},T={...o,context:i||o.context,count:s,...l,...k,defaultValue:O,ns:E},A=w?N(w,T):O,C=L(u,A,v,a),P=j(C||t,A,v,x,T,m),V=r??x.defaultTransParent;return V?n.createElement(V,h,P):P}const V={type:"3rdParty",init(e){O(e.options.react),w(e)}},_=n.createContext();class D{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const K=e=>async n=>({...await(e.getInitialProps?.(n))??{},...z()}),z=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),F=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(_)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new D),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n: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,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0)}(e,i,o))),f=((e,t,s,r)=>n.useCallback(U(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,N=()=>U(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[x,E]=n.useState(h);let b=u.join();t.lng&&(b=`${t.lng}${b}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(b),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?m(i,t.lng,u,(()=>{S.current&&E(N)})):g(i,u,(()=>{S.current&&E(N)}))),p&&O&&O!==b&&S.current&&E(N);const s=()=>{S.current&&E(N)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,b]),n.useEffect((()=>{S.current&&p&&E(h)}),[i,c,p]);const w=[x,i,p];if(w.t=x,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?m(i,t.lng,u,(()=>e())):g(i,u,(()=>e()))}))};const B=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:r}=s,{i18n:a}=n.useContext(_)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=_,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:r}=e;const a=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(_.Provider,{value:a},r)},e.Trans=function(e){let{children:t,count:s,parent:r,i18nKey:a,context:i,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...m}=e;const{i18n:h,defaultNS:y}=n.useContext(_)||{},v=d||h||$(),N=f||v?.t.bind(v);return P({children:t,count:s,parent:r,i18nKey:a,context:i,tOptions:o,values:l,defaults:c,components:u,ns:p||N?.ns||y||v?.options?.defaultNS,i18n:v,t:f,shouldUnescape:g,...m})},e.TransWithoutContext=P,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[r,a,i]=F(n,s);return t(r,{i18n:a,lng:a.language},i)},e.composeInitialProps=K,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=z,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=B,e.useTranslation=F,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:r,...a}=t;return B(s,r),n.createElement(e,{...a})}return t.getInitialProps=K(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function r(r){let{forwardedRef:a,...i}=r;const[o,l,c]=F(e,{...i,keyPrefix:t.keyPrefix}),u={...i,t:o,i18n:l,tReady:c};return t.withRef&&a?u.ref=a:!t.withRef&&a&&(u.forwardedRef=a),n.createElement(s,u)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}}));
@@ -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);
@@ -39,7 +39,9 @@ const nodesToString = (children, i18nOptions) => {
39
39
  childrenArray.forEach((child, childIndex) => {
40
40
  if ((0, _utils.isString)(child)) {
41
41
  stringNode += `${child}`;
42
- } else if ((0, _react.isValidElement)(child)) {
42
+ return;
43
+ }
44
+ if ((0, _react.isValidElement)(child)) {
43
45
  const {
44
46
  props,
45
47
  type
@@ -49,17 +51,27 @@ const nodesToString = (children, i18nOptions) => {
49
51
  const childChildren = props.children;
50
52
  if (!childChildren && shouldKeepChild && !childPropsCount) {
51
53
  stringNode += `<${type}/>`;
52
- } else if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
54
+ return;
55
+ }
56
+ if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
53
57
  stringNode += `<${childIndex}></${childIndex}>`;
54
- } else if (shouldKeepChild && childPropsCount === 1 && (0, _utils.isString)(childChildren)) {
58
+ return;
59
+ }
60
+ if (shouldKeepChild && childPropsCount === 1 && (0, _utils.isString)(childChildren)) {
55
61
  stringNode += `<${type}>${childChildren}</${type}>`;
56
- } else {
57
- const content = nodesToString(childChildren, i18nOptions);
58
- stringNode += `<${childIndex}>${content}</${childIndex}>`;
62
+ return;
59
63
  }
60
- } else if (child === null) {
61
- (0, _utils.warn)(`Trans: the passed in value is invalid - seems you passed in a null child.`);
62
- } else if ((0, _utils.isObject)(child)) {
64
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
65
+ stringNode += `<${childIndex}>${content}</${childIndex}>`;
66
+ return;
67
+ }
68
+ if (child === null) {
69
+ (0, _utils.warn)(i18n, 'TRANS_NULL_VALUE', `Passed in a null value as child`, {
70
+ i18nKey
71
+ });
72
+ return;
73
+ }
74
+ if ((0, _utils.isObject)(child)) {
63
75
  const {
64
76
  format,
65
77
  ...clone
@@ -68,12 +80,18 @@ const nodesToString = (children, i18nOptions) => {
68
80
  if (keys.length === 1) {
69
81
  const value = format ? `${keys[0]}, ${format}` : keys[0];
70
82
  stringNode += `{{${value}}}`;
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);
83
+ return;
73
84
  }
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);
85
+ (0, _utils.warn)(i18n, 'TRANS_INVALID_OBJ', `Invalid child - Object should only have keys {{ value, format }} (format is optional).`, {
86
+ i18nKey,
87
+ child
88
+ });
89
+ return;
76
90
  }
91
+ (0, _utils.warn)(i18n, 'TRANS_INVALID_VAR', `Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`, {
92
+ i18nKey,
93
+ child
94
+ });
77
95
  });
78
96
  return stringNode;
79
97
  };
@@ -217,7 +235,7 @@ const generateObjectComponents = (components, translation) => {
217
235
  });
218
236
  return componentMap;
219
237
  };
220
- const generateComponents = (components, translation) => {
238
+ const generateComponents = (components, translation, i18n, i18nKey) => {
221
239
  if (!components) return null;
222
240
  if (Array.isArray(components)) {
223
241
  return generateArrayComponents(components, translation);
@@ -225,7 +243,9 @@ const generateComponents = (components, translation) => {
225
243
  if ((0, _utils.isObject)(components)) {
226
244
  return generateObjectComponents(components, translation);
227
245
  }
228
- (0, _utils.warnOnce)('<Trans /> component prop expects an object or an array');
246
+ (0, _utils.warnOnce)(i18n, 'TRANS_INVALID_COMPONENTS', `<Trans /> "components" prop expects an object or array`, {
247
+ i18nKey
248
+ });
229
249
  return null;
230
250
  };
231
251
  function Trans(_ref) {
@@ -247,7 +267,9 @@ function Trans(_ref) {
247
267
  } = _ref;
248
268
  const i18n = i18nFromProps || (0, _i18nInstance.getI18n)();
249
269
  if (!i18n) {
250
- (0, _utils.warnOnce)('You will need to pass in an i18next instance by using i18nextReactModule');
270
+ (0, _utils.warnOnce)(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
271
+ i18nKey
272
+ });
251
273
  return children;
252
274
  }
253
275
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
@@ -257,7 +279,7 @@ function Trans(_ref) {
257
279
  };
258
280
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
259
281
  namespaces = (0, _utils.isString)(namespaces) ? [namespaces] : namespaces || ['translation'];
260
- const nodeAsString = nodesToString(children, reactI18nextOptions);
282
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
261
283
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
262
284
  const {
263
285
  hashTransKey
@@ -288,7 +310,7 @@ function Trans(_ref) {
288
310
  ns: namespaces
289
311
  };
290
312
  const translation = key ? t(key, combinedTOpts) : defaultValue;
291
- const generatedComponents = generateComponents(components, translation);
313
+ const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
292
314
  const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
293
315
  const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
294
316
  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, 'NO_I18NEXT_INSTANCE', 'useTranslation: 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, 'DEPRECATED_OPTION', 'useTranslation: 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,27 @@ 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
- }
12
- if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
7
+ const warn = (i18n, code, msg, rest) => {
8
+ const args = [msg, {
9
+ code,
10
+ ...(rest || {})
11
+ }];
12
+ if (i18n?.services?.logger?.forward) {
13
+ return i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
14
+ }
15
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
16
+ if (i18n?.services?.logger?.warn) {
17
+ i18n.services.logger.warn(...args);
18
+ } else if (console?.warn) {
13
19
  console.warn(...args);
14
20
  }
15
21
  };
16
22
  exports.warn = warn;
17
23
  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];
21
- }
22
- if (isString(args[0]) && alreadyWarned[args[0]]) return;
23
- if (isString(args[0])) alreadyWarned[args[0]] = new Date();
24
- warn(...args);
24
+ const warnOnce = (i18n, code, msg, rest) => {
25
+ if (isString(msg) && alreadyWarned[msg]) return;
26
+ if (isString(msg)) alreadyWarned[msg] = new Date();
27
+ warn(i18n, code, msg, rest);
25
28
  };
26
29
  exports.warnOnce = warnOnce;
27
30
  const loadedClb = (i18n, cb) => () => {
@@ -53,7 +56,9 @@ exports.loadLanguages = loadLanguages;
53
56
  const hasLoadedNamespace = function (ns, i18n) {
54
57
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
55
58
  if (!i18n.languages || !i18n.languages.length) {
56
- warnOnce('i18n.languages were undefined or empty', i18n.languages);
59
+ warnOnce(i18n, 'NO_LANGUAGES', 'i18n.languages were undefined or empty', {
60
+ languages: i18n.languages
61
+ });
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);
@@ -31,7 +31,9 @@ export const nodesToString = (children, i18nOptions) => {
31
31
  childrenArray.forEach((child, childIndex) => {
32
32
  if (isString(child)) {
33
33
  stringNode += `${child}`;
34
- } else if (isValidElement(child)) {
34
+ return;
35
+ }
36
+ if (isValidElement(child)) {
35
37
  const {
36
38
  props,
37
39
  type
@@ -41,17 +43,27 @@ export const nodesToString = (children, i18nOptions) => {
41
43
  const childChildren = props.children;
42
44
  if (!childChildren && shouldKeepChild && !childPropsCount) {
43
45
  stringNode += `<${type}/>`;
44
- } else if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
46
+ return;
47
+ }
48
+ if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
45
49
  stringNode += `<${childIndex}></${childIndex}>`;
46
- } else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
50
+ return;
51
+ }
52
+ if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
47
53
  stringNode += `<${type}>${childChildren}</${type}>`;
48
- } else {
49
- const content = nodesToString(childChildren, i18nOptions);
50
- stringNode += `<${childIndex}>${content}</${childIndex}>`;
54
+ return;
51
55
  }
52
- } else if (child === null) {
53
- warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
54
- } else if (isObject(child)) {
56
+ const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
57
+ stringNode += `<${childIndex}>${content}</${childIndex}>`;
58
+ return;
59
+ }
60
+ if (child === null) {
61
+ warn(i18n, 'TRANS_NULL_VALUE', `Passed in a null value as child`, {
62
+ i18nKey
63
+ });
64
+ return;
65
+ }
66
+ if (isObject(child)) {
55
67
  const {
56
68
  format,
57
69
  ...clone
@@ -60,12 +72,18 @@ export const nodesToString = (children, i18nOptions) => {
60
72
  if (keys.length === 1) {
61
73
  const value = format ? `${keys[0]}, ${format}` : keys[0];
62
74
  stringNode += `{{${value}}}`;
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);
75
+ return;
65
76
  }
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);
77
+ warn(i18n, 'TRANS_INVALID_OBJ', `Invalid child - Object should only have keys {{ value, format }} (format is optional).`, {
78
+ i18nKey,
79
+ child
80
+ });
81
+ return;
68
82
  }
83
+ warn(i18n, 'TRANS_INVALID_VAR', `Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`, {
84
+ i18nKey,
85
+ child
86
+ });
69
87
  });
70
88
  return stringNode;
71
89
  };
@@ -208,7 +226,7 @@ const generateObjectComponents = (components, translation) => {
208
226
  });
209
227
  return componentMap;
210
228
  };
211
- const generateComponents = (components, translation) => {
229
+ const generateComponents = (components, translation, i18n, i18nKey) => {
212
230
  if (!components) return null;
213
231
  if (Array.isArray(components)) {
214
232
  return generateArrayComponents(components, translation);
@@ -216,7 +234,9 @@ const generateComponents = (components, translation) => {
216
234
  if (isObject(components)) {
217
235
  return generateObjectComponents(components, translation);
218
236
  }
219
- warnOnce('<Trans /> component prop expects an object or an array');
237
+ warnOnce(i18n, 'TRANS_INVALID_COMPONENTS', `<Trans /> "components" prop expects an object or array`, {
238
+ i18nKey
239
+ });
220
240
  return null;
221
241
  };
222
242
  export function Trans({
@@ -237,7 +257,9 @@ export function Trans({
237
257
  }) {
238
258
  const i18n = i18nFromProps || getI18n();
239
259
  if (!i18n) {
240
- warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
260
+ warnOnce(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
261
+ i18nKey
262
+ });
241
263
  return children;
242
264
  }
243
265
  const t = tFromProps || i18n.t.bind(i18n) || (k => k);
@@ -247,7 +269,7 @@ export function Trans({
247
269
  };
248
270
  let namespaces = ns || t.ns || i18n.options?.defaultNS;
249
271
  namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
250
- const nodeAsString = nodesToString(children, reactI18nextOptions);
272
+ const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
251
273
  const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
252
274
  const {
253
275
  hashTransKey
@@ -278,7 +300,7 @@ export function Trans({
278
300
  ns: namespaces
279
301
  };
280
302
  const translation = key ? t(key, combinedTOpts) : defaultValue;
281
- const generatedComponents = generateComponents(components, translation);
303
+ const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
282
304
  const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
283
305
  const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
284
306
  return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
@@ -1 +1 @@
1
- {"type":"module","version":"15.2.0"}
1
+ {"type":"module","version":"15.4.0"}