react-i18next 14.1.1 → 14.1.3
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 +13 -0
- package/README.md +0 -2
- package/dist/amd/react-i18next.js +112 -126
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/TransWithoutContext.js +51 -45
- package/dist/commonjs/context.js +15 -23
- package/dist/commonjs/defaults.js +6 -7
- package/dist/commonjs/i18nInstance.js +6 -7
- package/dist/commonjs/useSSR.js +4 -3
- package/dist/commonjs/useTranslation.js +11 -14
- package/dist/commonjs/utils.js +22 -19
- package/dist/commonjs/withSSR.js +19 -20
- package/dist/commonjs/withTranslation.js +4 -3
- package/dist/es/TransWithoutContext.js +50 -45
- package/dist/es/context.js +11 -20
- package/dist/es/defaults.js +3 -5
- package/dist/es/i18nInstance.js +3 -5
- package/dist/es/package.json +1 -1
- package/dist/es/useSSR.js +2 -2
- package/dist/es/useTranslation.js +10 -14
- package/dist/es/utils.js +15 -15
- package/dist/es/withSSR.js +17 -19
- package/dist/es/withTranslation.js +2 -2
- package/dist/umd/react-i18next.js +112 -126
- package/dist/umd/react-i18next.min.js +1 -1
- package/package.json +2 -2
- package/react-i18next.js +112 -126
- package/react-i18next.min.js +1 -1
- package/src/TransWithoutContext.js +49 -47
- package/src/context.js +13 -34
- package/src/defaults.js +3 -5
- package/src/i18nInstance.js +3 -5
- package/src/useSSR.js +2 -2
- package/src/useTranslation.js +19 -18
- package/src/utils.js +23 -20
- package/src/withSSR.js +2 -3
- package/src/withTranslation.js +2 -3
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
124
124
|
args[_key] = arguments[_key];
|
|
125
125
|
}
|
|
126
|
-
if (
|
|
126
|
+
if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
|
|
127
127
|
console.warn(...args);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -132,8 +132,8 @@
|
|
|
132
132
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
133
133
|
args[_key2] = arguments[_key2];
|
|
134
134
|
}
|
|
135
|
-
if (
|
|
136
|
-
if (
|
|
135
|
+
if (isString(args[0]) && alreadyWarned[args[0]]) return;
|
|
136
|
+
if (isString(args[0])) alreadyWarned[args[0]] = new Date();
|
|
137
137
|
warn(...args);
|
|
138
138
|
}
|
|
139
139
|
const loadedClb = (i18n, cb) => () => {
|
|
@@ -149,17 +149,17 @@
|
|
|
149
149
|
i18n.on('initialized', initialized);
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
|
-
|
|
152
|
+
const loadNamespaces = (i18n, ns, cb) => {
|
|
153
153
|
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (
|
|
154
|
+
};
|
|
155
|
+
const loadLanguages = (i18n, lng, ns, cb) => {
|
|
156
|
+
if (isString(ns)) ns = [ns];
|
|
157
157
|
ns.forEach(n => {
|
|
158
158
|
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
159
159
|
});
|
|
160
160
|
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
161
|
-
}
|
|
162
|
-
function
|
|
161
|
+
};
|
|
162
|
+
const oldI18nextHasLoadedNamespace = function (ns, i18n) {
|
|
163
163
|
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
164
164
|
const lng = i18n.languages[0];
|
|
165
165
|
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
@@ -174,8 +174,8 @@
|
|
|
174
174
|
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
|
|
175
175
|
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
176
176
|
return false;
|
|
177
|
-
}
|
|
178
|
-
function
|
|
177
|
+
};
|
|
178
|
+
const hasLoadedNamespace = function (ns, i18n) {
|
|
179
179
|
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
180
180
|
if (!i18n.languages || !i18n.languages.length) {
|
|
181
181
|
warnOnce('i18n.languages were undefined or empty', i18n.languages);
|
|
@@ -191,10 +191,10 @@
|
|
|
191
191
|
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
};
|
|
195
|
+
const getDisplayName = Component => Component.displayName || Component.name || (isString(Component) && Component.length > 0 ? Component : 'Unknown');
|
|
196
|
+
const isString = obj => typeof obj === 'string';
|
|
197
|
+
const isObject = obj => typeof obj === 'object' && obj !== null;
|
|
198
198
|
|
|
199
199
|
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
200
200
|
const htmlEntities = {
|
|
@@ -232,77 +232,70 @@
|
|
|
232
232
|
useSuspense: true,
|
|
233
233
|
unescape
|
|
234
234
|
};
|
|
235
|
-
function
|
|
235
|
+
const setDefaults = function () {
|
|
236
236
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
237
237
|
defaultOptions = {
|
|
238
238
|
...defaultOptions,
|
|
239
239
|
...options
|
|
240
240
|
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return defaultOptions;
|
|
244
|
-
}
|
|
241
|
+
};
|
|
242
|
+
const getDefaults = () => defaultOptions;
|
|
245
243
|
|
|
246
244
|
let i18nInstance;
|
|
247
|
-
|
|
245
|
+
const setI18n = instance => {
|
|
248
246
|
i18nInstance = instance;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return i18nInstance;
|
|
252
|
-
}
|
|
247
|
+
};
|
|
248
|
+
const getI18n = () => i18nInstance;
|
|
253
249
|
|
|
254
|
-
|
|
250
|
+
const hasChildren = (node, checkLength) => {
|
|
255
251
|
if (!node) return false;
|
|
256
252
|
const base = node.props ? node.props.children : node.children;
|
|
257
253
|
if (checkLength) return base.length > 0;
|
|
258
254
|
return !!base;
|
|
259
|
-
}
|
|
260
|
-
|
|
255
|
+
};
|
|
256
|
+
const getChildren = node => {
|
|
261
257
|
if (!node) return [];
|
|
262
258
|
const children = node.props ? node.props.children : node.children;
|
|
263
259
|
return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
function getAsArray(data) {
|
|
270
|
-
return Array.isArray(data) ? data : [data];
|
|
271
|
-
}
|
|
272
|
-
function mergeProps(source, target) {
|
|
260
|
+
};
|
|
261
|
+
const hasValidReactChildren = children => Array.isArray(children) && children.every(react.isValidElement);
|
|
262
|
+
const getAsArray = data => Array.isArray(data) ? data : [data];
|
|
263
|
+
const mergeProps = (source, target) => {
|
|
273
264
|
const newTarget = {
|
|
274
265
|
...target
|
|
275
266
|
};
|
|
276
267
|
newTarget.props = Object.assign(source.props, target.props);
|
|
277
268
|
return newTarget;
|
|
278
|
-
}
|
|
279
|
-
|
|
269
|
+
};
|
|
270
|
+
const nodesToString = (children, i18nOptions) => {
|
|
280
271
|
if (!children) return '';
|
|
281
272
|
let stringNode = '';
|
|
282
273
|
const childrenArray = getAsArray(children);
|
|
283
274
|
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
284
275
|
childrenArray.forEach((child, childIndex) => {
|
|
285
|
-
if (
|
|
276
|
+
if (isString(child)) {
|
|
286
277
|
stringNode += `${child}`;
|
|
287
278
|
} else if (react.isValidElement(child)) {
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
279
|
+
const {
|
|
280
|
+
props,
|
|
281
|
+
type
|
|
282
|
+
} = child;
|
|
283
|
+
const childPropsCount = Object.keys(props).length;
|
|
284
|
+
const shouldKeepChild = keepArray.indexOf(type) > -1;
|
|
285
|
+
const childChildren = props.children;
|
|
286
|
+
if (!childChildren && shouldKeepChild && !childPropsCount) {
|
|
287
|
+
stringNode += `<${type}/>`;
|
|
288
|
+
} else if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
|
|
296
289
|
stringNode += `<${childIndex}></${childIndex}>`;
|
|
297
|
-
} else if (shouldKeepChild && childPropsCount === 1 &&
|
|
298
|
-
stringNode += `<${
|
|
290
|
+
} else if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
|
|
291
|
+
stringNode += `<${type}>${childChildren}</${type}>`;
|
|
299
292
|
} else {
|
|
300
293
|
const content = nodesToString(childChildren, i18nOptions);
|
|
301
294
|
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
302
295
|
}
|
|
303
296
|
} else if (child === null) {
|
|
304
297
|
warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
|
|
305
|
-
} else if (
|
|
298
|
+
} else if (isObject(child)) {
|
|
306
299
|
const {
|
|
307
300
|
format,
|
|
308
301
|
...clone
|
|
@@ -319,32 +312,32 @@
|
|
|
319
312
|
}
|
|
320
313
|
});
|
|
321
314
|
return stringNode;
|
|
322
|
-
}
|
|
323
|
-
|
|
315
|
+
};
|
|
316
|
+
const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
324
317
|
if (targetString === '') return [];
|
|
325
318
|
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
326
319
|
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
|
|
327
320
|
if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
328
321
|
const data = {};
|
|
329
|
-
|
|
322
|
+
const getData = childs => {
|
|
330
323
|
const childrenArray = getAsArray(childs);
|
|
331
324
|
childrenArray.forEach(child => {
|
|
332
|
-
if (
|
|
333
|
-
if (hasChildren(child)) getData(getChildren(child));else if (
|
|
325
|
+
if (isString(child)) return;
|
|
326
|
+
if (hasChildren(child)) getData(getChildren(child));else if (isObject(child) && !react.isValidElement(child)) Object.assign(data, child);
|
|
334
327
|
});
|
|
335
|
-
}
|
|
328
|
+
};
|
|
336
329
|
getData(children);
|
|
337
330
|
const ast = c.parse(`<0>${targetString}</0>`);
|
|
338
331
|
const opts = {
|
|
339
332
|
...data,
|
|
340
333
|
...combinedTOpts
|
|
341
334
|
};
|
|
342
|
-
|
|
335
|
+
const renderInner = (child, node, rootReactNode) => {
|
|
343
336
|
const childs = getChildren(child);
|
|
344
337
|
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
345
338
|
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren;
|
|
346
|
-
}
|
|
347
|
-
|
|
339
|
+
};
|
|
340
|
+
const pushTranslatedJSX = (child, inner, mem, i, isVoid) => {
|
|
348
341
|
if (child.dummy) {
|
|
349
342
|
child.children = inner;
|
|
350
343
|
mem.push(react.cloneElement(child, {
|
|
@@ -363,8 +356,8 @@
|
|
|
363
356
|
}, isVoid ? null : inner);
|
|
364
357
|
}));
|
|
365
358
|
}
|
|
366
|
-
}
|
|
367
|
-
|
|
359
|
+
};
|
|
360
|
+
const mapAST = (reactNode, astNode, rootReactNode) => {
|
|
368
361
|
const reactNodes = getAsArray(reactNode);
|
|
369
362
|
const astNodes = getAsArray(astNode);
|
|
370
363
|
return astNodes.reduce((mem, node, i) => {
|
|
@@ -378,9 +371,9 @@
|
|
|
378
371
|
}, tmp) : tmp;
|
|
379
372
|
const isElement = react.isValidElement(child);
|
|
380
373
|
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
381
|
-
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling &&
|
|
382
|
-
const isKnownComponent =
|
|
383
|
-
if (
|
|
374
|
+
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
|
|
375
|
+
const isKnownComponent = isObject(children) && Object.hasOwnProperty.call(children, node.name);
|
|
376
|
+
if (isString(child)) {
|
|
384
377
|
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
385
378
|
mem.push(value);
|
|
386
379
|
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
@@ -410,7 +403,7 @@
|
|
|
410
403
|
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
411
404
|
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
412
405
|
}
|
|
413
|
-
} else if (
|
|
406
|
+
} else if (isObject(child) && !isElement) {
|
|
414
407
|
const content = node.children[0] ? translationContent : null;
|
|
415
408
|
if (content) mem.push(content);
|
|
416
409
|
} else {
|
|
@@ -429,13 +422,13 @@
|
|
|
429
422
|
}
|
|
430
423
|
return mem;
|
|
431
424
|
}, []);
|
|
432
|
-
}
|
|
425
|
+
};
|
|
433
426
|
const result = mapAST([{
|
|
434
427
|
dummy: true,
|
|
435
428
|
children: children || []
|
|
436
429
|
}], ast, getAsArray(children || []));
|
|
437
430
|
return getChildren(result[0]);
|
|
438
|
-
}
|
|
431
|
+
};
|
|
439
432
|
function Trans$1(_ref) {
|
|
440
433
|
let {
|
|
441
434
|
children,
|
|
@@ -464,7 +457,7 @@
|
|
|
464
457
|
...(i18n.options && i18n.options.react)
|
|
465
458
|
};
|
|
466
459
|
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
|
|
467
|
-
namespaces =
|
|
460
|
+
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
|
|
468
461
|
const nodeAsString = nodesToString(children, reactI18nextOptions);
|
|
469
462
|
const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
470
463
|
const {
|
|
@@ -479,11 +472,19 @@
|
|
|
479
472
|
...i18n.options.interpolation.defaultVariables
|
|
480
473
|
};
|
|
481
474
|
}
|
|
475
|
+
const interpolationOverride = values || count !== undefined || !children ? tOptions.interpolation : {
|
|
476
|
+
interpolation: {
|
|
477
|
+
...tOptions.interpolation,
|
|
478
|
+
prefix: '#$?',
|
|
479
|
+
suffix: '?$#'
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
482
|
const combinedTOpts = {
|
|
483
483
|
...tOptions,
|
|
484
484
|
context: context || tOptions.context,
|
|
485
485
|
count,
|
|
486
486
|
...values,
|
|
487
|
+
...interpolationOverride,
|
|
487
488
|
defaultValue,
|
|
488
489
|
ns: namespaces
|
|
489
490
|
};
|
|
@@ -521,26 +522,17 @@
|
|
|
521
522
|
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
522
523
|
});
|
|
523
524
|
}
|
|
524
|
-
getUsedNamespaces()
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
return
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
...i18nInitialProps
|
|
536
|
-
});
|
|
537
|
-
});
|
|
538
|
-
} else {
|
|
539
|
-
resolve(i18nInitialProps);
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
function getInitialProps() {
|
|
525
|
+
getUsedNamespaces = () => Object.keys(this.usedNamespaces);
|
|
526
|
+
}
|
|
527
|
+
const composeInitialProps = ForComponent => async ctx => {
|
|
528
|
+
const componentsInitialProps = ForComponent.getInitialProps ? await ForComponent.getInitialProps(ctx) : {};
|
|
529
|
+
const i18nInitialProps = getInitialProps();
|
|
530
|
+
return {
|
|
531
|
+
...componentsInitialProps,
|
|
532
|
+
...i18nInitialProps
|
|
533
|
+
};
|
|
534
|
+
};
|
|
535
|
+
const getInitialProps = () => {
|
|
544
536
|
const i18n = getI18n();
|
|
545
537
|
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
|
|
546
538
|
const ret = {};
|
|
@@ -554,7 +546,7 @@
|
|
|
554
546
|
ret.initialI18nStore = initialI18nStore;
|
|
555
547
|
ret.initialLanguage = i18n.language;
|
|
556
548
|
return ret;
|
|
557
|
-
}
|
|
549
|
+
};
|
|
558
550
|
|
|
559
551
|
function Trans(_ref) {
|
|
560
552
|
let {
|
|
@@ -604,13 +596,9 @@
|
|
|
604
596
|
}, [value, ignore]);
|
|
605
597
|
return ref.current;
|
|
606
598
|
};
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
function useMemoizedT(i18n, language, namespace, keyPrefix) {
|
|
611
|
-
return react.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
|
|
612
|
-
}
|
|
613
|
-
function useTranslation(ns) {
|
|
599
|
+
const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
|
|
600
|
+
const useMemoizedT = (i18n, language, namespace, keyPrefix) => react.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
|
|
601
|
+
const useTranslation = function (ns) {
|
|
614
602
|
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
615
603
|
const {
|
|
616
604
|
i18n: i18nFromProps
|
|
@@ -624,8 +612,8 @@
|
|
|
624
612
|
if (!i18n) {
|
|
625
613
|
warnOnce('You will need to pass in an i18next instance by using initReactI18next');
|
|
626
614
|
const notReadyT = (k, optsOrDefaultValue) => {
|
|
627
|
-
if (
|
|
628
|
-
if (optsOrDefaultValue &&
|
|
615
|
+
if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
|
|
616
|
+
if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
|
|
629
617
|
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
630
618
|
};
|
|
631
619
|
const retNotReady = [notReadyT, {}, false];
|
|
@@ -645,7 +633,7 @@
|
|
|
645
633
|
keyPrefix
|
|
646
634
|
} = i18nOptions;
|
|
647
635
|
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
648
|
-
namespaces =
|
|
636
|
+
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
|
|
649
637
|
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
650
638
|
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
|
|
651
639
|
const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
@@ -676,9 +664,9 @@
|
|
|
676
664
|
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
677
665
|
setT(getNewT);
|
|
678
666
|
}
|
|
679
|
-
|
|
667
|
+
const boundReset = () => {
|
|
680
668
|
if (isMounted.current) setT(getNewT);
|
|
681
|
-
}
|
|
669
|
+
};
|
|
682
670
|
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
683
671
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
684
672
|
return () => {
|
|
@@ -705,9 +693,9 @@
|
|
|
705
693
|
loadNamespaces(i18n, namespaces, () => resolve());
|
|
706
694
|
}
|
|
707
695
|
});
|
|
708
|
-
}
|
|
696
|
+
};
|
|
709
697
|
|
|
710
|
-
function
|
|
698
|
+
const withTranslation = function (ns) {
|
|
711
699
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
712
700
|
return function Extend(WrappedComponent) {
|
|
713
701
|
function I18nextWithTranslation(_ref) {
|
|
@@ -739,7 +727,7 @@
|
|
|
739
727
|
}));
|
|
740
728
|
return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
|
|
741
729
|
};
|
|
742
|
-
}
|
|
730
|
+
};
|
|
743
731
|
|
|
744
732
|
function Translation(props) {
|
|
745
733
|
const {
|
|
@@ -769,7 +757,7 @@
|
|
|
769
757
|
}, children);
|
|
770
758
|
}
|
|
771
759
|
|
|
772
|
-
function
|
|
760
|
+
const useSSR = function (initialI18nStore, initialLanguage) {
|
|
773
761
|
let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
774
762
|
const {
|
|
775
763
|
i18n: i18nFromProps
|
|
@@ -794,27 +782,25 @@
|
|
|
794
782
|
i18n.changeLanguage(initialLanguage);
|
|
795
783
|
i18n.initializedLanguageOnce = true;
|
|
796
784
|
}
|
|
797
|
-
}
|
|
785
|
+
};
|
|
798
786
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
};
|
|
817
|
-
}
|
|
787
|
+
const withSSR = () => function Extend(WrappedComponent) {
|
|
788
|
+
function I18nextWithSSR(_ref) {
|
|
789
|
+
let {
|
|
790
|
+
initialI18nStore,
|
|
791
|
+
initialLanguage,
|
|
792
|
+
...rest
|
|
793
|
+
} = _ref;
|
|
794
|
+
useSSR(initialI18nStore, initialLanguage);
|
|
795
|
+
return react.createElement(WrappedComponent, {
|
|
796
|
+
...rest
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
|
|
800
|
+
I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`;
|
|
801
|
+
I18nextWithSSR.WrappedComponent = WrappedComponent;
|
|
802
|
+
return I18nextWithSSR;
|
|
803
|
+
};
|
|
818
804
|
|
|
819
805
|
const date = () => '';
|
|
820
806
|
const time = () => '';
|
|
@@ -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}),i=/\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 o=new RegExp(i),a=null;null!==(a=o.exec(e));)if(a[0].trim())if(a[1]){var c=a[1].trim(),l=[c,""];c.indexOf("=")>-1&&(l=c.split("=")),n.attrs[l[0]]=l[1],o.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var o=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,a=/^\s*$/,c=Object.create(null);function l(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(l,"")+"</"+n.name+">";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var u={parse:function(e,n){n||(n={}),n.components||(n.components=c);var t,s=[],i=[],l=-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(o,(function(o,c){if(u){if(o!=="</"+t.name+">")return;u=!1}var p,d="/"!==o.charAt(1),f=o.startsWith("\x3c!--"),g=c+o.length,h=e.charAt(g);if(f){var m=r(o);return l<0?(s.push(m),s):((p=i[l]).children.push(m),s)}if(d&&(l++,"tag"===(t=r(o)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===l&&s.push(t),(p=i[l-1])&&p.children.push(t),i[l]=t),(!d||t.voidElement)&&(l>-1&&(t.voidElement||t.name===o.slice(2,-1))&&(l--,t=-1===l?s:i[l]),!u&&"<"!==h&&h)){p=-1===l?s:i[l].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);a.test(b)&&(b=" "),(y>-1&&l+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+l("",n)}),"")}};function p(){if(console&&console.warn){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&(n[0]=`react-i18next:: ${n[0]}`),console.warn(...n)}}const d={};function f(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&d[n[0]]||("string"==typeof n[0]&&(d[n[0]]=new Date),p(...n))}const g=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}};function h(e,n,t){e.loadNamespaces(n,g(e,t))}function m(e,n,t,s){"string"==typeof t&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,g(e,s))}function y(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}const b=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,v={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},x=e=>v[e];let E,N={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(b,x)};function O(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N={...N,...e}}function $(){return N}function w(e){E=e}function k(){return E}function I(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function S(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?j(n):n}function j(e){return Array.isArray(e)?e:[e]}function C(e,t){if(!e)return"";let s="";const i=j(e),r=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return i.forEach(((e,i)=>{if("string"==typeof e)s+=`${e}`;else if(n.isValidElement(e)){const n=Object.keys(e.props).length,o=r.indexOf(e.type)>-1,a=e.props.children;if(!a&&o&&0===n)s+=`<${e.type}/>`;else if(a||o&&0===n)if(e.props.i18nIsDynamicList)s+=`<${i}></${i}>`;else if(o&&1===n&&"string"==typeof a)s+=`<${e.type}>${a}</${e.type}>`;else{const e=C(a,t);s+=`<${i}>${e}</${i}>`}else s+=`<${i}></${i}>`}else if(null===e)p("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"==typeof e){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];s+=`{{${e}}}`}else p("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else p("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}function R(e,t,s,i,r,o){if(""===t)return[];const a=i.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(a.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!c&&!o)return[t];const l={};!function e(t){j(t).forEach((t=>{"string"!=typeof t&&(I(t)?e(S(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))}))}(e);const p=u.parse(`<0>${t}</0>`),d={...l,...r};function f(e,t,s){const i=S(e),r=h(i,t.children,s);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((e=>n.isValidElement(e)))}(i)&&0===r.length||e.props&&e.props.i18nIsDynamicList?i:r}function g(e,t,s,i,r){e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:i},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:i,ref:e.ref},r?null:t)})))}function h(t,r,l){const u=j(t);return j(r).reduce(((t,r,p)=>{const m=r.children&&r.children[0]&&r.children[0].content&&s.services.interpolator.interpolate(r.children[0].content,d,s.language);if("tag"===r.type){let o=u[parseInt(r.name,10)];1!==l.length||o||(o=l[0][r.name]),o||(o={});const y=0!==Object.keys(r.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:r.attrs},o):o,b=n.isValidElement(y),v=b&&I(r,!0)&&!r.voidElement,x=c&&"object"==typeof y&&y.dummy&&!b,E="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,r.name);if("string"==typeof y){const e=s.services.interpolator.interpolate(y,d,s.language);t.push(e)}else if(I(y)||v){g(y,f(y,r,l),t,p)}else if(x){g(y,h(u,r.children,l),t,p)}else if(Number.isNaN(parseFloat(r.name)))if(E){g(y,f(y,r,l),t,p,r.voidElement)}else if(i.transSupportBasicHtmlNodes&&a.indexOf(r.name)>-1)if(r.voidElement)t.push(n.createElement(r.name,{key:`${r.name}-${p}`}));else{const e=h(u,r.children,l);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,l);t.push(`<${r.name}>${e}</${r.name}>`)}else if("object"!=typeof y||b)g(y,m,t,p,1!==r.children.length||!m);else{const e=r.children[0]?m:null;e&&t.push(e)}}else if("text"===r.type){const e=i.transWrapTextNodes,a=o?i.unescape(s.services.interpolator.interpolate(r.content,d,s.language)):s.services.interpolator.interpolate(r.content,d,s.language);e?t.push(n.createElement(e,{key:`${r.name}-${p}`},a)):t.push(a)}return t}),[])}return S(h([{dummy:!0,children:e||[]}],p,j(e||[]))[0])}function T(e){let{children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:d,t:g,shouldUnescape:h,...m}=e;const y=d||k();if(!y)return f("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=g||y.t.bind(y)||(e=>e),v={...$(),...y.options&&y.options.react};let x=p||b.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const E=C(t,v),N=l||E||v.transEmptyNodeValue||r,{hashTransKey:O}=v,w=r||(O?O(E||N):E||N);y.options&&y.options.interpolation&&y.options.interpolation.defaultVariables&&(c=c&&Object.keys(c).length>0?{...c,...y.options.interpolation.defaultVariables}:{...y.options.interpolation.defaultVariables});const I={...a,context:o||a.context,count:s,...c,defaultValue:N,ns:x},S=w?b(w,I):N;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||S.indexOf(`${e}/>`)<0&&S.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const j=R(u||t,S,y,v,I,h),T=void 0!==i?i:v.defaultTransParent;return T?n.createElement(T,m,j):j}const L={type:"3rdParty",init(e){O(e.options.react),w(e)}},P=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function z(e){return n=>new Promise((t=>{const s=A();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function A(){const e=k(),n=e.reportNamespaces?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 B=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e,n,t,s){return e.getFixedT(n,t,s)}function U(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:r}=n.useContext(P)||{},o=s||i||k();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new V),!o){f("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>"string"==typeof n?n:n&&"object"==typeof n&&"string"==typeof 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}o.options.react&&void 0!==o.options.react.wait&&f("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...$(),...o.options.react,...t},{useSuspense:c,keyPrefix:l}=a;let u=e||r||o.options&&o.options.defaultNS;u="string"==typeof u?[u]:u||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(u);const p=(o.isInitialized||o.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?void 0!==n.options.ignoreJSONStructure?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=n.languages[0],i=!!n.options&&n.options.fallbackLng,r=n.languages[n.languages.length-1];if("cimode"===s.toLowerCase())return!0;const o=(e,t)=>{const s=n.services.backendConnector.state[`${e}|${t}`];return-1===s||2===s};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e)||!n.hasResourceBundle(s,e)&&n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages)&&(!o(s,e)||i&&!o(r,e)))}(e,n,t):(f("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a))),d=function(e,t,s,i){return n.useCallback(F(e,t,s,i),[e,t,s,i])}(o,t.lng||null,"fallback"===a.nsMode?u:u[0],l),g=()=>d,y=()=>F(o,t.lng||null,"fallback"===a.nsMode?u:u[0],l),[b,v]=n.useState(g);let x=u.join();t.lng&&(x=`${t.lng}${x}`);const E=B(x),N=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){N.current&&v(y)}return N.current=!0,p||c||(t.lng?m(o,t.lng,u,(()=>{N.current&&v(y)})):h(o,u,(()=>{N.current&&v(y)}))),p&&E&&E!==x&&N.current&&v(y),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{N.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,x]),n.useEffect((()=>{N.current&&p&&v(g)}),[o,l,p]);const O=[b,o,p];if(O.t=b,O.i18n=o,O.ready=p,p)return O;if(!p&&!c)return O;throw new Promise((e=>{t.lng?m(o,t.lng,u,(()=>e())):h(o,u,(()=>e()))}))}function K(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:i}=s,{i18n:r}=n.useContext(P)||{},o=i||r||k();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=P,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:i}=e;const r=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(P.Provider,{value:r},i)},e.Trans=function(e){let{children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(P)||{},b=d||m||k(),v=f||b&&b.t.bind(b);return T({children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a,values:c,defaults:l,components:u,ns:p||v&&v.ns||y||b&&b.options&&b.options.defaultNS,i18n:b,t:f,shouldUnescape:g,...h})},e.TransWithoutContext=T,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,r,o]=U(n,s);return t(i,{i18n:r,lng:r.language},o)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=k,e.getInitialProps=A,e.initReactI18next=L,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=K,e.useTranslation=U,e.withSSR=function(){return function(e){function t(t){let{initialI18nStore:s,initialLanguage:i,...r}=t;return K(s,i),n.createElement(e,{...r})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${y(e)})`,t.WrappedComponent=e,t}},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function i(i){let{forwardedRef:r,...o}=i;const[a,c,l]=U(e,{...o,keyPrefix:t.keyPrefix}),u={...o,t:a,i18n:c,tReady:l};return t.withRef&&r?u.ref=r:!t.withRef&&r&&(u.forwardedRef=r),n.createElement(s,u)}i.displayName=`withI18nextTranslation(${y(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}}));
|
|
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}),i=/\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 o=new RegExp(i),r=null;null!==(r=o.exec(e));)if(r[0].trim())if(r[1]){var l=r[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],o.lastIndex--}else r[2]&&(n.attrs[r[2]]=r[3].trim().substring(1,r[3].length-1));return n}var o=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,r=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],i=[],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(o,(function(o,l){if(u){if(o!=="</"+t.name+">")return;u=!1}var p,d="/"!==o.charAt(1),f=o.startsWith("\x3c!--"),g=l+o.length,h=e.charAt(g);if(f){var m=a(o);return c<0?(s.push(m),s):((p=i[c]).children.push(m),s)}if(d&&(c++,"tag"===(t=a(o)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===c&&s.push(t),(p=i[c-1])&&p.children.push(t),i[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===o.slice(2,-1))&&(c--,t=-1===c?s:i[c]),!u&&"<"!==h&&h)){p=-1===c?s:i[c].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);r.test(b)&&(b=" "),(y>-1&&c+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s};function u(){if(console&&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)}}const p={};function d(){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))}const 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))},h=(e,n,t,s)=>{y(t)&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},m=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,b=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,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},E=e=>x[e];let N={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,E)};const O=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N={...N,...e}},$=()=>N;let k;const w=e=>{k=e},I=()=>k,S=(e,n)=>{if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t},C=e=>{if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],j=(e,t)=>{if(!e)return"";let s="";const i=R(e),a=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return i.forEach(((e,i)=>{if(y(e))s+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:o}=e,r=Object.keys(n).length,l=a.indexOf(o)>-1,c=n.children;if(c||!l||r)if(!c&&(!l||r)||n.i18nIsDynamicList)s+=`<${i}></${i}>`;else if(l&&1===r&&y(c))s+=`<${o}>${c}</${o}>`;else{const e=j(c,t);s+=`<${i}>${e}</${i}>`}else s+=`<${o}/>`}else if(null===e)u("Trans: the passed in value is invalid - seems you passed in a null child.");else if(b(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[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},T=(e,t,s,i,a,o)=>{if(""===t)return[];const r=i.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(r.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!o)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(S(e)?p(C(e)):b(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},g=(e,t,s)=>{const i=C(e),a=m(i,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(i)&&0===a.length||e.props&&e.props.i18nIsDynamicList?i:a},h=(e,t,s,i,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:i},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:i,ref:e.ref},a?null:t)})))},m=(t,a,c)=>{const u=R(t);return R(a).reduce(((t,a,p)=>{const d=a.children&&a.children[0]&&a.children[0].content&&s.services.interpolator.interpolate(a.children[0].content,f,s.language);if("tag"===a.type){let o=u[parseInt(a.name,10)];1!==c.length||o||(o=c[0][a.name]),o||(o={});const v=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},o):o,x=n.isValidElement(v),E=x&&S(a,!0)&&!a.voidElement,N=l&&b(v)&&v.dummy&&!x,O=b(e)&&Object.hasOwnProperty.call(e,a.name);if(y(v)){const e=s.services.interpolator.interpolate(v,f,s.language);t.push(e)}else if(S(v)||E){const e=g(v,a,c);h(v,e,t,p)}else if(N){const e=m(u,a.children,c);h(v,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(O){const e=g(v,a,c);h(v,e,t,p,a.voidElement)}else if(i.transSupportBasicHtmlNodes&&r.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=m(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=m(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(b(v)&&!x){const e=a.children[0]?d:null;e&&t.push(e)}else h(v,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=i.transWrapTextNodes,r=o?i.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}`},r)):t.push(r)}return t}),[])},v=m([{dummy:!0,children:e||[]}],d,R(e||[]));return C(v[0])};function L(e){let{children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r={},values:l,defaults:c,components:u,ns:p,i18n:f,t:g,shouldUnescape:h,...m}=e;const b=f||I();if(!b)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const v=g||b.t.bind(b)||(e=>e),x={...$(),...b.options&&b.options.react};let E=p||v.ns||b.options&&b.options.defaultNS;E=y(E)?[E]:E||["translation"];const N=j(t,x),O=c||N||x.transEmptyNodeValue||a,{hashTransKey:k}=x,w=a||(k?k(N||O):N||O);b.options&&b.options.interpolation&&b.options.interpolation.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...b.options.interpolation.defaultVariables}:{...b.options.interpolation.defaultVariables});const S=l||void 0!==s||!t?r.interpolation:{interpolation:{...r.interpolation,prefix:"#$?",suffix:"?$#"}},C={...r,context:o||r.context,count:s,...l,...S,defaultValue:O,ns:E},R=w?v(w,C):O;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||R.indexOf(`${e}/>`)<0&&R.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const L=T(u||t,R,b,x,C,h),P=void 0!==i?i:x.defaultTransParent;return P?n.createElement(P,m,L):L}const P={type:"3rdParty",init(e){O(e.options.react),w(e)}},A=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces=()=>Object.keys(this.usedNamespaces)}const z=e=>async n=>({...e.getInitialProps?await e.getInitialProps(n):{},...B()}),B=()=>{const e=I(),n=e.reportNamespaces?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 F=(e,n,t,s)=>e.getFixedT(n,t,s),U=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:a}=n.useContext(A)||{},o=s||i||I();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new V),!o){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:b(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}o.options.react&&void 0!==o.options.react.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const r={...$(),...o.options.react,...t},{useSuspense:l,keyPrefix:c}=r;let u=e||a||o.options&&o.options.defaultNS;u=y(u)?[u]:u||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(u);const p=(o.isInitialized||o.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?void 0!==n.options.ignoreJSONStructure?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=n.languages[n.languages.length-1];if("cimode"===s.toLowerCase())return!0;const o=(e,t)=>{const s=n.services.backendConnector.state[`${e}|${t}`];return-1===s||2===s};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e)||!n.hasResourceBundle(s,e)&&n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages)&&(!o(s,e)||i&&!o(a,e)))}(e,n,t):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,o,r))),f=((e,t,s,i)=>n.useCallback(F(e,t,s,i),[e,t,s,i]))(o,t.lng||null,"fallback"===r.nsMode?u:u[0],c),m=()=>f,v=()=>F(o,t.lng||null,"fallback"===r.nsMode?u:u[0],c),[x,E]=n.useState(m);let N=u.join();t.lng&&(N=`${t.lng}${N}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current})(N),k=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=r;k.current=!0,p||l||(t.lng?h(o,t.lng,u,(()=>{k.current&&E(v)})):g(o,u,(()=>{k.current&&E(v)}))),p&&O&&O!==N&&k.current&&E(v);const s=()=>{k.current&&E(v)};return e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{k.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,N]),n.useEffect((()=>{k.current&&p&&E(m)}),[o,c,p]);const w=[x,o,p];if(w.t=x,w.i18n=o,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?h(o,t.lng,u,(()=>e())):g(o,u,(()=>e()))}))};const K=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:i}=s,{i18n:a}=n.useContext(A)||{},o=i||a||I();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))};e.I18nContext=A,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:i}=e;const a=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(A.Provider,{value:a},i)},e.Trans=function(e){let{children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(A)||{},b=d||m||I(),v=f||b&&b.t.bind(b);return L({children:t,count:s,parent:i,i18nKey:a,context:o,tOptions:r,values:l,defaults:c,components:u,ns:p||v&&v.ns||y||b&&b.options&&b.options.defaultNS,i18n:b,t:f,shouldUnescape:g,...h})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,a,o]=U(n,s);return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=I,e.getInitialProps=B,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=K,e.useTranslation=U,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:i,...a}=t;return K(s,i),n.createElement(e,{...a})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${m(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function i(i){let{forwardedRef:a,...o}=i;const[r,l,c]=U(e,{...o,keyPrefix:t.keyPrefix}),u={...o,t:r,i18n:l,tReady:c};return t.withRef&&a?u.ref=a:!t.withRef&&a&&(u.forwardedRef=a),n.createElement(s,u)}i.displayName=`withI18nextTranslation(${m(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-i18next",
|
|
3
|
-
"version": "14.1.
|
|
3
|
+
"version": "14.1.3",
|
|
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",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"eslint-plugin-testing-library": "^5.11.0",
|
|
107
107
|
"happy-dom": "^12.10.3",
|
|
108
108
|
"husky": "^8.0.3",
|
|
109
|
-
"i18next": "^23.
|
|
109
|
+
"i18next": "^23.11.5",
|
|
110
110
|
"lint-staged": "^8.1.3",
|
|
111
111
|
"mkdirp": "^1.0.4",
|
|
112
112
|
"prettier": "2.8.8",
|