|
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 | 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 | 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 | 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 | 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 | 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);
|
440 | 445 | }
|
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 | 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 | 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 | 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 | 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 | 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,
|
|
0 commit comments