@team-monolith/cds 1.129.2-alpha.2 → 1.129.3-alpha
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/dist/CdsProvider.js +180 -180
- package/dist/components/AlertDialog/AlertDialogTitle.js +15 -15
- package/dist/components/Banner.js +28 -28
- package/dist/components/FileTypeAlertDialog.js +16 -16
- package/dist/components/Pagination.js +22 -22
- package/dist/emotion.d.ts +185 -0
- package/dist/i18n/i18n.js +14 -14
- package/dist/index.d.ts +8 -1
- package/dist/node_modules/.pnpm/html-parse-stringify@3.0.1/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js +78 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/I18nextProvider.js +12 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/Trans.js +26 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/TransWithoutContext.js +174 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/context.js +20 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/defaults.js +24 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/i18nInstance.js +6 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/initReactI18next.js +11 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/unescape.js +25 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/useTranslation.js +69 -0
- package/dist/node_modules/.pnpm/react-i18next@15.7.3_i18next@25.5.2_typescript@5.5.4__react-dom@18.2.0_react@18.2.0__react@18.2.0_typescript@5.5.4/node_modules/react-i18next/dist/es/utils.js +35 -0
- package/dist/patterns/LexicalEditor/Plugins.js +64 -64
- package/dist/patterns/LexicalEditor/components/FileSelectInput.js +19 -19
- package/dist/patterns/LexicalEditor/components/InsertImageDialog/ImagePreview.js +6 -6
- package/dist/patterns/LexicalEditor/components/InsertImageDialog/InsertImageDialog.js +34 -34
- package/dist/patterns/LexicalEditor/components/UploadFileDialog/UploadFileDialog.js +14 -14
- package/dist/patterns/LexicalEditor/nodes/FileNode/FileDownloadButton.js +17 -17
- package/dist/patterns/LexicalEditor/nodes/ImageNode/ImageComponent.js +62 -62
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/InputComponent.js +25 -25
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/SettingForm/FormPlaceholder.js +7 -7
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/SettingForm/FormSolution.js +24 -23
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/SettingForm/SettingForm.js +48 -47
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/SettingForm/TextTypeDropdown.js +11 -11
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectBox/SelectBoxView.js +15 -15
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectComponent.js +28 -28
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SettingForm/FormSelection.js +30 -30
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SettingForm/SettingForm.js +35 -35
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/Evaluation/SettingForm/FormIconAndLabel/FormIconAndLabel.js +21 -21
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/Evaluation/SettingForm/FormIconAndLabel/FormLabel.js +15 -15
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/Evaluation/SettingForm/FormQuestion.js +17 -17
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/Evaluation/SettingForm/SettingForm.js +30 -30
- package/dist/patterns/LexicalEditor/nodes/SelfEvaluationNode/EvaluationComponent/EvaluationComponent.js +20 -20
- package/dist/patterns/LexicalEditor/nodes/SheetInputNode/InputComponent.js +24 -24
- package/dist/patterns/LexicalEditor/nodes/SheetInputNode/SettingForm.js +28 -28
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SelectBox/SelectBoxView.js +11 -11
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SelectComponent.js +26 -26
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SettingForm/FormAllowMultipleAnswers.js +8 -8
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SettingForm/FormSelection.js +27 -27
- package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SettingForm/SettingForm.js +33 -33
- package/dist/patterns/LexicalEditor/nodes/VideoNode/VideoComponent.js +21 -21
- package/dist/patterns/LexicalEditor/plugins/ComponentAdderPlugin/ComponentAdderPlugin.js +99 -99
- package/dist/patterns/LexicalEditor/plugins/ComponentAdderPlugin/useContextMenuOptions.js +50 -50
- package/dist/patterns/LexicalEditor/plugins/ComponentPickerMenuPlugin/ComponentPickerMenuPlugin.js +85 -85
- package/dist/patterns/LexicalEditor/plugins/DragDropPastePlugin/index.js +13 -13
- package/dist/patterns/LexicalEditor/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +48 -48
- package/dist/patterns/LexicalEditor/plugins/ImagesPlugin/useImageNodeTransform.js +16 -16
- package/dist/patterns/ToggleButtonGroup/ToggleButton.js +17 -17
- package/package.json +15 -18
- package/@types/emotion.d.ts +0 -197
- package/node_modules/react-i18next/.eslintrc.json +0 -74
- package/node_modules/react-i18next/.husky/pre-commit +0 -1
- package/node_modules/react-i18next/.prettierignore +0 -4
- package/node_modules/react-i18next/CHANGELOG.md +0 -1433
- package/node_modules/react-i18next/LICENSE +0 -22
- package/node_modules/react-i18next/README.md +0 -181
- package/node_modules/react-i18next/TransWithoutContext.d.mts +0 -1
- package/node_modules/react-i18next/TransWithoutContext.d.ts +0 -129
- package/node_modules/react-i18next/dist/amd/react-i18next.js +0 -867
- package/node_modules/react-i18next/dist/amd/react-i18next.min.js +0 -1
- package/node_modules/react-i18next/dist/commonjs/I18nextProvider.js +0 -21
- package/node_modules/react-i18next/dist/commonjs/Trans.js +0 -54
- package/node_modules/react-i18next/dist/commonjs/TransWithoutContext.js +0 -330
- package/node_modules/react-i18next/dist/commonjs/Translation.js +0 -19
- package/node_modules/react-i18next/dist/commonjs/context.js +0 -81
- package/node_modules/react-i18next/dist/commonjs/defaults.js +0 -26
- package/node_modules/react-i18next/dist/commonjs/i18nInstance.js +0 -13
- package/node_modules/react-i18next/dist/commonjs/index.js +0 -128
- package/node_modules/react-i18next/dist/commonjs/initReactI18next.js +0 -15
- package/node_modules/react-i18next/dist/commonjs/unescape.js +0 -32
- package/node_modules/react-i18next/dist/commonjs/useSSR.js +0 -34
- package/node_modules/react-i18next/dist/commonjs/useTranslation.js +0 -114
- package/node_modules/react-i18next/dist/commonjs/utils.js +0 -76
- package/node_modules/react-i18next/dist/commonjs/withSSR.js +0 -27
- package/node_modules/react-i18next/dist/commonjs/withTranslation.js +0 -39
- package/node_modules/react-i18next/dist/es/I18nextProvider.js +0 -15
- package/node_modules/react-i18next/dist/es/Trans.js +0 -43
- package/node_modules/react-i18next/dist/es/TransWithoutContext.js +0 -321
- package/node_modules/react-i18next/dist/es/Translation.js +0 -12
- package/node_modules/react-i18next/dist/es/context.js +0 -42
- package/node_modules/react-i18next/dist/es/defaults.js +0 -18
- package/node_modules/react-i18next/dist/es/i18nInstance.js +0 -5
- package/node_modules/react-i18next/dist/es/index.js +0 -18
- package/node_modules/react-i18next/dist/es/initReactI18next.js +0 -9
- package/node_modules/react-i18next/dist/es/package.json +0 -1
- package/node_modules/react-i18next/dist/es/unescape.js +0 -25
- package/node_modules/react-i18next/dist/es/useSSR.js +0 -27
- package/node_modules/react-i18next/dist/es/useTranslation.js +0 -107
- package/node_modules/react-i18next/dist/es/utils.js +0 -62
- package/node_modules/react-i18next/dist/es/withSSR.js +0 -20
- package/node_modules/react-i18next/dist/es/withTranslation.js +0 -32
- package/node_modules/react-i18next/dist/umd/react-i18next.js +0 -871
- package/node_modules/react-i18next/dist/umd/react-i18next.min.js +0 -1
- package/node_modules/react-i18next/helpers.d.ts +0 -3
- package/node_modules/react-i18next/icu.macro.d.mts +0 -1
- package/node_modules/react-i18next/icu.macro.d.ts +0 -103
- package/node_modules/react-i18next/icu.macro.js +0 -729
- package/node_modules/react-i18next/index.d.mts +0 -1
- package/node_modules/react-i18next/index.d.ts +0 -209
- package/node_modules/react-i18next/initReactI18next.d.mts +0 -1
- package/node_modules/react-i18next/initReactI18next.d.ts +0 -3
- package/node_modules/react-i18next/lint-staged.config.mjs +0 -4
- package/node_modules/react-i18next/package.json +0 -167
- package/node_modules/react-i18next/react-i18next.js +0 -871
- package/node_modules/react-i18next/react-i18next.min.js +0 -1
- package/node_modules/react-i18next/src/I18nextProvider.js +0 -7
- package/node_modules/react-i18next/src/Trans.js +0 -45
- package/node_modules/react-i18next/src/TransWithoutContext.js +0 -479
- package/node_modules/react-i18next/src/Translation.js +0 -14
- package/node_modules/react-i18next/src/context.js +0 -54
- package/node_modules/react-i18next/src/defaults.js +0 -20
- package/node_modules/react-i18next/src/i18nInstance.js +0 -7
- package/node_modules/react-i18next/src/index.js +0 -22
- package/node_modules/react-i18next/src/initReactI18next.js +0 -11
- package/node_modules/react-i18next/src/unescape.js +0 -31
- package/node_modules/react-i18next/src/useSSR.js +0 -33
- package/node_modules/react-i18next/src/useTranslation.js +0 -171
- package/node_modules/react-i18next/src/utils.js +0 -93
- package/node_modules/react-i18next/src/withSSR.js +0 -21
- package/node_modules/react-i18next/src/withTranslation.js +0 -35
- package/node_modules/react-i18next/vitest.workspace.typescript.mts +0 -52
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { Fragment, isValidElement, cloneElement, createElement, Children } from 'react';
|
|
2
|
-
import HTML from 'html-parse-stringify';
|
|
3
|
-
import { isObject, isString, warn, warnOnce } from './utils.js';
|
|
4
|
-
import { getDefaults } from './defaults.js';
|
|
5
|
-
import { getI18n } from './i18nInstance.js';
|
|
6
|
-
const hasChildren = (node, checkLength) => {
|
|
7
|
-
if (!node) return false;
|
|
8
|
-
const base = node.props?.children ?? node.children;
|
|
9
|
-
if (checkLength) return base.length > 0;
|
|
10
|
-
return !!base;
|
|
11
|
-
};
|
|
12
|
-
const getChildren = node => {
|
|
13
|
-
if (!node) return [];
|
|
14
|
-
const children = node.props?.children ?? node.children;
|
|
15
|
-
return node.props?.i18nIsDynamicList ? getAsArray(children) : children;
|
|
16
|
-
};
|
|
17
|
-
const hasValidReactChildren = children => Array.isArray(children) && children.every(isValidElement);
|
|
18
|
-
const getAsArray = data => Array.isArray(data) ? data : [data];
|
|
19
|
-
const mergeProps = (source, target) => {
|
|
20
|
-
const newTarget = {
|
|
21
|
-
...target
|
|
22
|
-
};
|
|
23
|
-
newTarget.props = Object.assign(source.props, target.props);
|
|
24
|
-
return newTarget;
|
|
25
|
-
};
|
|
26
|
-
export const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
|
|
27
|
-
if (!children) return '';
|
|
28
|
-
let stringNode = '';
|
|
29
|
-
const childrenArray = getAsArray(children);
|
|
30
|
-
const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : [];
|
|
31
|
-
childrenArray.forEach((child, childIndex) => {
|
|
32
|
-
if (isString(child)) {
|
|
33
|
-
stringNode += `${child}`;
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (isValidElement(child)) {
|
|
37
|
-
const {
|
|
38
|
-
props,
|
|
39
|
-
type
|
|
40
|
-
} = child;
|
|
41
|
-
const childPropsCount = Object.keys(props).length;
|
|
42
|
-
const shouldKeepChild = keepArray.indexOf(type) > -1;
|
|
43
|
-
const childChildren = props.children;
|
|
44
|
-
if (!childChildren && shouldKeepChild && !childPropsCount) {
|
|
45
|
-
stringNode += `<${type}/>`;
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
|
|
49
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
|
|
53
|
-
stringNode += `<${type}>${childChildren}</${type}>`;
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
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)) {
|
|
67
|
-
const {
|
|
68
|
-
format,
|
|
69
|
-
...clone
|
|
70
|
-
} = child;
|
|
71
|
-
const keys = Object.keys(clone);
|
|
72
|
-
if (keys.length === 1) {
|
|
73
|
-
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
74
|
-
stringNode += `{{${value}}}`;
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
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;
|
|
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
|
-
});
|
|
87
|
-
});
|
|
88
|
-
return stringNode;
|
|
89
|
-
};
|
|
90
|
-
const renderNodes = (children, knownComponentsMap, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
91
|
-
if (targetString === '') return [];
|
|
92
|
-
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
93
|
-
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
|
|
94
|
-
if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
95
|
-
const data = knownComponentsMap ?? {};
|
|
96
|
-
const getData = childs => {
|
|
97
|
-
const childrenArray = getAsArray(childs);
|
|
98
|
-
childrenArray.forEach(child => {
|
|
99
|
-
if (isString(child)) return;
|
|
100
|
-
if (hasChildren(child)) getData(getChildren(child));else if (isObject(child) && !isValidElement(child)) Object.assign(data, child);
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
getData(children);
|
|
104
|
-
const ast = HTML.parse(`<0>${targetString}</0>`);
|
|
105
|
-
const opts = {
|
|
106
|
-
...data,
|
|
107
|
-
...combinedTOpts
|
|
108
|
-
};
|
|
109
|
-
const renderInner = (child, node, rootReactNode) => {
|
|
110
|
-
const childs = getChildren(child);
|
|
111
|
-
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
112
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren;
|
|
113
|
-
};
|
|
114
|
-
const pushTranslatedJSX = (child, inner, mem, i, isVoid) => {
|
|
115
|
-
if (child.dummy) {
|
|
116
|
-
child.children = inner;
|
|
117
|
-
mem.push(cloneElement(child, {
|
|
118
|
-
key: i
|
|
119
|
-
}, isVoid ? undefined : inner));
|
|
120
|
-
} else {
|
|
121
|
-
mem.push(...Children.map([child], c => {
|
|
122
|
-
const props = {
|
|
123
|
-
...c.props
|
|
124
|
-
};
|
|
125
|
-
delete props.i18nIsDynamicList;
|
|
126
|
-
return createElement(c.type, {
|
|
127
|
-
...props,
|
|
128
|
-
key: i,
|
|
129
|
-
ref: c.props.ref ?? c.ref
|
|
130
|
-
}, isVoid ? null : inner);
|
|
131
|
-
}));
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const mapAST = (reactNode, astNode, rootReactNode) => {
|
|
135
|
-
const reactNodes = getAsArray(reactNode);
|
|
136
|
-
const astNodes = getAsArray(astNode);
|
|
137
|
-
return astNodes.reduce((mem, node, i) => {
|
|
138
|
-
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
139
|
-
if (node.type === 'tag') {
|
|
140
|
-
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
141
|
-
if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
|
|
142
|
-
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
143
|
-
if (!tmp) tmp = {};
|
|
144
|
-
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
145
|
-
props: node.attrs
|
|
146
|
-
}, tmp) : tmp;
|
|
147
|
-
const isElement = isValidElement(child);
|
|
148
|
-
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
149
|
-
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
|
|
150
|
-
const isKnownComponent = isObject(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
|
|
151
|
-
if (isString(child)) {
|
|
152
|
-
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
153
|
-
mem.push(value);
|
|
154
|
-
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
155
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
156
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
157
|
-
} else if (isEmptyTransWithHTML) {
|
|
158
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
159
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
160
|
-
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
161
|
-
if (isKnownComponent) {
|
|
162
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
163
|
-
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
164
|
-
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
165
|
-
if (node.voidElement) {
|
|
166
|
-
mem.push(createElement(node.name, {
|
|
167
|
-
key: `${node.name}-${i}`
|
|
168
|
-
}));
|
|
169
|
-
} else {
|
|
170
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
171
|
-
mem.push(createElement(node.name, {
|
|
172
|
-
key: `${node.name}-${i}`
|
|
173
|
-
}, inner));
|
|
174
|
-
}
|
|
175
|
-
} else if (node.voidElement) {
|
|
176
|
-
mem.push(`<${node.name} />`);
|
|
177
|
-
} else {
|
|
178
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
179
|
-
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
180
|
-
}
|
|
181
|
-
} else if (isObject(child) && !isElement) {
|
|
182
|
-
const content = node.children[0] ? translationContent : null;
|
|
183
|
-
if (content) mem.push(content);
|
|
184
|
-
} else {
|
|
185
|
-
pushTranslatedJSX(child, translationContent, mem, i, node.children.length !== 1 || !translationContent);
|
|
186
|
-
}
|
|
187
|
-
} else if (node.type === 'text') {
|
|
188
|
-
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
189
|
-
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
190
|
-
if (wrapTextNodes) {
|
|
191
|
-
mem.push(createElement(wrapTextNodes, {
|
|
192
|
-
key: `${node.name}-${i}`
|
|
193
|
-
}, content));
|
|
194
|
-
} else {
|
|
195
|
-
mem.push(content);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return mem;
|
|
199
|
-
}, []);
|
|
200
|
-
};
|
|
201
|
-
const result = mapAST([{
|
|
202
|
-
dummy: true,
|
|
203
|
-
children: children || []
|
|
204
|
-
}], ast, getAsArray(children || []));
|
|
205
|
-
return getChildren(result[0]);
|
|
206
|
-
};
|
|
207
|
-
const fixComponentProps = (component, index, translation) => {
|
|
208
|
-
const componentKey = component.key || index;
|
|
209
|
-
const comp = cloneElement(component, {
|
|
210
|
-
key: componentKey
|
|
211
|
-
});
|
|
212
|
-
if (!comp.props || !comp.props.children || translation.indexOf(`${index}/>`) < 0 && translation.indexOf(`${index} />`) < 0) {
|
|
213
|
-
return comp;
|
|
214
|
-
}
|
|
215
|
-
function Componentized() {
|
|
216
|
-
return createElement(Fragment, null, comp);
|
|
217
|
-
}
|
|
218
|
-
return createElement(Componentized, {
|
|
219
|
-
key: componentKey
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
const generateArrayComponents = (components, translation) => components.map((c, index) => fixComponentProps(c, index, translation));
|
|
223
|
-
const generateObjectComponents = (components, translation) => {
|
|
224
|
-
const componentMap = {};
|
|
225
|
-
Object.keys(components).forEach(c => {
|
|
226
|
-
Object.assign(componentMap, {
|
|
227
|
-
[c]: fixComponentProps(components[c], c, translation)
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
return componentMap;
|
|
231
|
-
};
|
|
232
|
-
const generateComponents = (components, translation, i18n, i18nKey) => {
|
|
233
|
-
if (!components) return null;
|
|
234
|
-
if (Array.isArray(components)) {
|
|
235
|
-
return generateArrayComponents(components, translation);
|
|
236
|
-
}
|
|
237
|
-
if (isObject(components)) {
|
|
238
|
-
return generateObjectComponents(components, translation);
|
|
239
|
-
}
|
|
240
|
-
warnOnce(i18n, 'TRANS_INVALID_COMPONENTS', `<Trans /> "components" prop expects an object or array`, {
|
|
241
|
-
i18nKey
|
|
242
|
-
});
|
|
243
|
-
return null;
|
|
244
|
-
};
|
|
245
|
-
const isComponentsMap = object => {
|
|
246
|
-
if (!isObject(object)) return false;
|
|
247
|
-
if (Array.isArray(object)) return false;
|
|
248
|
-
return Object.keys(object).reduce((acc, key) => acc && Number.isNaN(Number.parseFloat(key)), true);
|
|
249
|
-
};
|
|
250
|
-
export function Trans({
|
|
251
|
-
children,
|
|
252
|
-
count,
|
|
253
|
-
parent,
|
|
254
|
-
i18nKey,
|
|
255
|
-
context,
|
|
256
|
-
tOptions = {},
|
|
257
|
-
values,
|
|
258
|
-
defaults,
|
|
259
|
-
components,
|
|
260
|
-
ns,
|
|
261
|
-
i18n: i18nFromProps,
|
|
262
|
-
t: tFromProps,
|
|
263
|
-
shouldUnescape,
|
|
264
|
-
...additionalProps
|
|
265
|
-
}) {
|
|
266
|
-
const i18n = i18nFromProps || getI18n();
|
|
267
|
-
if (!i18n) {
|
|
268
|
-
warnOnce(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
|
|
269
|
-
i18nKey
|
|
270
|
-
});
|
|
271
|
-
return children;
|
|
272
|
-
}
|
|
273
|
-
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
|
|
274
|
-
const reactI18nextOptions = {
|
|
275
|
-
...getDefaults(),
|
|
276
|
-
...i18n.options?.react
|
|
277
|
-
};
|
|
278
|
-
let namespaces = ns || t.ns || i18n.options?.defaultNS;
|
|
279
|
-
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
|
|
280
|
-
const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
|
|
281
|
-
const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
282
|
-
const {
|
|
283
|
-
hashTransKey
|
|
284
|
-
} = reactI18nextOptions;
|
|
285
|
-
const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue);
|
|
286
|
-
if (i18n.options?.interpolation?.defaultVariables) {
|
|
287
|
-
values = values && Object.keys(values).length > 0 ? {
|
|
288
|
-
...values,
|
|
289
|
-
...i18n.options.interpolation.defaultVariables
|
|
290
|
-
} : {
|
|
291
|
-
...i18n.options.interpolation.defaultVariables
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
const interpolationOverride = values || count !== undefined && !i18n.options?.interpolation?.alwaysFormat || !children ? tOptions.interpolation : {
|
|
295
|
-
interpolation: {
|
|
296
|
-
...tOptions.interpolation,
|
|
297
|
-
prefix: '#$?',
|
|
298
|
-
suffix: '?$#'
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
const combinedTOpts = {
|
|
302
|
-
...tOptions,
|
|
303
|
-
context: context || tOptions.context,
|
|
304
|
-
count,
|
|
305
|
-
...values,
|
|
306
|
-
...interpolationOverride,
|
|
307
|
-
defaultValue,
|
|
308
|
-
ns: namespaces
|
|
309
|
-
};
|
|
310
|
-
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
311
|
-
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
312
|
-
let indexedChildren = generatedComponents || children;
|
|
313
|
-
let componentsMap = null;
|
|
314
|
-
if (isComponentsMap(generatedComponents)) {
|
|
315
|
-
componentsMap = generatedComponents;
|
|
316
|
-
indexedChildren = children;
|
|
317
|
-
}
|
|
318
|
-
const content = renderNodes(indexedChildren, componentsMap, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
319
|
-
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
|
|
320
|
-
return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
|
|
321
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
import { getDefaults, setDefaults } from './defaults.js';
|
|
3
|
-
import { getI18n, setI18n } from './i18nInstance.js';
|
|
4
|
-
import { initReactI18next } from './initReactI18next.js';
|
|
5
|
-
export { getDefaults, setDefaults, getI18n, setI18n, initReactI18next };
|
|
6
|
-
export const I18nContext = createContext();
|
|
7
|
-
export class ReportNamespaces {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.usedNamespaces = {};
|
|
10
|
-
}
|
|
11
|
-
addUsedNamespaces(namespaces) {
|
|
12
|
-
namespaces.forEach(ns => {
|
|
13
|
-
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
getUsedNamespaces() {
|
|
17
|
-
return Object.keys(this.usedNamespaces);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export const composeInitialProps = ForComponent => async ctx => {
|
|
21
|
-
const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {};
|
|
22
|
-
const i18nInitialProps = getInitialProps();
|
|
23
|
-
return {
|
|
24
|
-
...componentsInitialProps,
|
|
25
|
-
...i18nInitialProps
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export const getInitialProps = () => {
|
|
29
|
-
const i18n = getI18n();
|
|
30
|
-
const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? [];
|
|
31
|
-
const ret = {};
|
|
32
|
-
const initialI18nStore = {};
|
|
33
|
-
i18n.languages.forEach(l => {
|
|
34
|
-
initialI18nStore[l] = {};
|
|
35
|
-
namespaces.forEach(ns => {
|
|
36
|
-
initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
ret.initialI18nStore = initialI18nStore;
|
|
40
|
-
ret.initialLanguage = i18n.language;
|
|
41
|
-
return ret;
|
|
42
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { unescape } from './unescape.js';
|
|
2
|
-
let defaultOptions = {
|
|
3
|
-
bindI18n: 'languageChanged',
|
|
4
|
-
bindI18nStore: '',
|
|
5
|
-
transEmptyNodeValue: '',
|
|
6
|
-
transSupportBasicHtmlNodes: true,
|
|
7
|
-
transWrapTextNodes: '',
|
|
8
|
-
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
9
|
-
useSuspense: true,
|
|
10
|
-
unescape
|
|
11
|
-
};
|
|
12
|
-
export const setDefaults = (options = {}) => {
|
|
13
|
-
defaultOptions = {
|
|
14
|
-
...defaultOptions,
|
|
15
|
-
...options
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export const getDefaults = () => defaultOptions;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export { Trans } from './Trans.js';
|
|
2
|
-
export { Trans as TransWithoutContext } from './TransWithoutContext.js';
|
|
3
|
-
export { useTranslation } from './useTranslation.js';
|
|
4
|
-
export { withTranslation } from './withTranslation.js';
|
|
5
|
-
export { Translation } from './Translation.js';
|
|
6
|
-
export { I18nextProvider } from './I18nextProvider.js';
|
|
7
|
-
export { withSSR } from './withSSR.js';
|
|
8
|
-
export { useSSR } from './useSSR.js';
|
|
9
|
-
export { initReactI18next } from './initReactI18next.js';
|
|
10
|
-
export { setDefaults, getDefaults } from './defaults.js';
|
|
11
|
-
export { setI18n, getI18n } from './i18nInstance.js';
|
|
12
|
-
export { I18nContext, composeInitialProps, getInitialProps } from './context.js';
|
|
13
|
-
export const date = () => '';
|
|
14
|
-
export const time = () => '';
|
|
15
|
-
export const number = () => '';
|
|
16
|
-
export const select = () => '';
|
|
17
|
-
export const plural = () => '';
|
|
18
|
-
export const selectOrdinal = () => '';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module","version":"15.7.3"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
2
|
-
const htmlEntities = {
|
|
3
|
-
'&': '&',
|
|
4
|
-
'&': '&',
|
|
5
|
-
'<': '<',
|
|
6
|
-
'<': '<',
|
|
7
|
-
'>': '>',
|
|
8
|
-
'>': '>',
|
|
9
|
-
''': "'",
|
|
10
|
-
''': "'",
|
|
11
|
-
'"': '"',
|
|
12
|
-
'"': '"',
|
|
13
|
-
' ': ' ',
|
|
14
|
-
' ': ' ',
|
|
15
|
-
'©': '©',
|
|
16
|
-
'©': '©',
|
|
17
|
-
'®': '®',
|
|
18
|
-
'®': '®',
|
|
19
|
-
'…': '…',
|
|
20
|
-
'…': '…',
|
|
21
|
-
'/': '/',
|
|
22
|
-
'/': '/'
|
|
23
|
-
};
|
|
24
|
-
const unescapeHtmlEntity = m => htmlEntities[m];
|
|
25
|
-
export const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
import { getI18n, I18nContext } from './context.js';
|
|
3
|
-
export const useSSR = (initialI18nStore, initialLanguage, props = {}) => {
|
|
4
|
-
const {
|
|
5
|
-
i18n: i18nFromProps
|
|
6
|
-
} = props;
|
|
7
|
-
const {
|
|
8
|
-
i18n: i18nFromContext
|
|
9
|
-
} = useContext(I18nContext) || {};
|
|
10
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
11
|
-
if (i18n.options?.isClone) return;
|
|
12
|
-
if (initialI18nStore && !i18n.initializedStoreOnce) {
|
|
13
|
-
i18n.services.resourceStore.data = initialI18nStore;
|
|
14
|
-
i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
|
|
15
|
-
Object.keys(lngResources).forEach(ns => {
|
|
16
|
-
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
17
|
-
});
|
|
18
|
-
return mem;
|
|
19
|
-
}, i18n.options.ns);
|
|
20
|
-
i18n.initializedStoreOnce = true;
|
|
21
|
-
i18n.isInitialized = true;
|
|
22
|
-
}
|
|
23
|
-
if (initialLanguage && !i18n.initializedLanguageOnce) {
|
|
24
|
-
i18n.changeLanguage(initialLanguage);
|
|
25
|
-
i18n.initializedLanguageOnce = true;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useContext, useRef, useCallback } from 'react';
|
|
2
|
-
import { getI18n, getDefaults, ReportNamespaces, I18nContext } from './context.js';
|
|
3
|
-
import { warnOnce, loadNamespaces, loadLanguages, hasLoadedNamespace, isString, isObject } from './utils.js';
|
|
4
|
-
const usePrevious = (value, ignore) => {
|
|
5
|
-
const ref = useRef();
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
ref.current = ignore ? ref.current : value;
|
|
8
|
-
}, [value, ignore]);
|
|
9
|
-
return ref.current;
|
|
10
|
-
};
|
|
11
|
-
const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
|
|
12
|
-
const useMemoizedT = (i18n, language, namespace, keyPrefix) => useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
|
|
13
|
-
export const useTranslation = (ns, props = {}) => {
|
|
14
|
-
const {
|
|
15
|
-
i18n: i18nFromProps
|
|
16
|
-
} = props;
|
|
17
|
-
const {
|
|
18
|
-
i18n: i18nFromContext,
|
|
19
|
-
defaultNS: defaultNSFromContext
|
|
20
|
-
} = useContext(I18nContext) || {};
|
|
21
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
22
|
-
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
|
|
23
|
-
if (!i18n) {
|
|
24
|
-
warnOnce(i18n, 'NO_I18NEXT_INSTANCE', 'useTranslation: You will need to pass in an i18next instance by using initReactI18next');
|
|
25
|
-
const notReadyT = (k, optsOrDefaultValue) => {
|
|
26
|
-
if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
|
|
27
|
-
if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
|
|
28
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
29
|
-
};
|
|
30
|
-
const retNotReady = [notReadyT, {}, false];
|
|
31
|
-
retNotReady.t = notReadyT;
|
|
32
|
-
retNotReady.i18n = {};
|
|
33
|
-
retNotReady.ready = false;
|
|
34
|
-
return retNotReady;
|
|
35
|
-
}
|
|
36
|
-
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.');
|
|
37
|
-
const i18nOptions = {
|
|
38
|
-
...getDefaults(),
|
|
39
|
-
...i18n.options.react,
|
|
40
|
-
...props
|
|
41
|
-
};
|
|
42
|
-
const {
|
|
43
|
-
useSuspense,
|
|
44
|
-
keyPrefix
|
|
45
|
-
} = i18nOptions;
|
|
46
|
-
let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS;
|
|
47
|
-
namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
|
|
48
|
-
i18n.reportNamespaces.addUsedNamespaces?.(namespaces);
|
|
49
|
-
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
|
|
50
|
-
const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
51
|
-
const getT = () => memoGetT;
|
|
52
|
-
const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
53
|
-
const [t, setT] = useState(getT);
|
|
54
|
-
let joinedNS = namespaces.join();
|
|
55
|
-
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
|
|
56
|
-
const previousJoinedNS = usePrevious(joinedNS);
|
|
57
|
-
const isMounted = useRef(true);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
const {
|
|
60
|
-
bindI18n,
|
|
61
|
-
bindI18nStore
|
|
62
|
-
} = i18nOptions;
|
|
63
|
-
isMounted.current = true;
|
|
64
|
-
if (!ready && !useSuspense) {
|
|
65
|
-
if (props.lng) {
|
|
66
|
-
loadLanguages(i18n, props.lng, namespaces, () => {
|
|
67
|
-
if (isMounted.current) setT(getNewT);
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
loadNamespaces(i18n, namespaces, () => {
|
|
71
|
-
if (isMounted.current) setT(getNewT);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
76
|
-
setT(getNewT);
|
|
77
|
-
}
|
|
78
|
-
const boundReset = () => {
|
|
79
|
-
if (isMounted.current) setT(getNewT);
|
|
80
|
-
};
|
|
81
|
-
if (bindI18n) i18n?.on(bindI18n, boundReset);
|
|
82
|
-
if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset);
|
|
83
|
-
return () => {
|
|
84
|
-
isMounted.current = false;
|
|
85
|
-
if (i18n && bindI18n) bindI18n?.split(' ').forEach(e => i18n.off(e, boundReset));
|
|
86
|
-
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
|
|
87
|
-
};
|
|
88
|
-
}, [i18n, joinedNS]);
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
if (isMounted.current && ready) {
|
|
91
|
-
setT(getT);
|
|
92
|
-
}
|
|
93
|
-
}, [i18n, keyPrefix, ready]);
|
|
94
|
-
const ret = [t, i18n, ready];
|
|
95
|
-
ret.t = t;
|
|
96
|
-
ret.i18n = i18n;
|
|
97
|
-
ret.ready = ready;
|
|
98
|
-
if (ready) return ret;
|
|
99
|
-
if (!ready && !useSuspense) return ret;
|
|
100
|
-
throw new Promise(resolve => {
|
|
101
|
-
if (props.lng) {
|
|
102
|
-
loadLanguages(i18n, props.lng, namespaces, () => resolve());
|
|
103
|
-
} else {
|
|
104
|
-
loadNamespaces(i18n, namespaces, () => resolve());
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export const warn = (i18n, code, msg, rest) => {
|
|
2
|
-
const args = [msg, {
|
|
3
|
-
code,
|
|
4
|
-
...(rest || {})
|
|
5
|
-
}];
|
|
6
|
-
if (i18n?.services?.logger?.forward) {
|
|
7
|
-
return i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
|
|
8
|
-
}
|
|
9
|
-
if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
|
|
10
|
-
if (i18n?.services?.logger?.warn) {
|
|
11
|
-
i18n.services.logger.warn(...args);
|
|
12
|
-
} else if (console?.warn) {
|
|
13
|
-
console.warn(...args);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const alreadyWarned = {};
|
|
17
|
-
export const warnOnce = (i18n, code, msg, rest) => {
|
|
18
|
-
if (isString(msg) && alreadyWarned[msg]) return;
|
|
19
|
-
if (isString(msg)) alreadyWarned[msg] = new Date();
|
|
20
|
-
warn(i18n, code, msg, rest);
|
|
21
|
-
};
|
|
22
|
-
const loadedClb = (i18n, cb) => () => {
|
|
23
|
-
if (i18n.isInitialized) {
|
|
24
|
-
cb();
|
|
25
|
-
} else {
|
|
26
|
-
const initialized = () => {
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
i18n.off('initialized', initialized);
|
|
29
|
-
}, 0);
|
|
30
|
-
cb();
|
|
31
|
-
};
|
|
32
|
-
i18n.on('initialized', initialized);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
export const loadNamespaces = (i18n, ns, cb) => {
|
|
36
|
-
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
37
|
-
};
|
|
38
|
-
export const loadLanguages = (i18n, lng, ns, cb) => {
|
|
39
|
-
if (isString(ns)) ns = [ns];
|
|
40
|
-
if (i18n.options.preload && i18n.options.preload.indexOf(lng) > -1) return loadNamespaces(i18n, ns, cb);
|
|
41
|
-
ns.forEach(n => {
|
|
42
|
-
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
43
|
-
});
|
|
44
|
-
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
45
|
-
};
|
|
46
|
-
export const hasLoadedNamespace = (ns, i18n, options = {}) => {
|
|
47
|
-
if (!i18n.languages || !i18n.languages.length) {
|
|
48
|
-
warnOnce(i18n, 'NO_LANGUAGES', 'i18n.languages were undefined or empty', {
|
|
49
|
-
languages: i18n.languages
|
|
50
|
-
});
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
return i18n.hasLoadedNamespace(ns, {
|
|
54
|
-
lng: options.lng,
|
|
55
|
-
precheck: (i18nInstance, loadNotPending) => {
|
|
56
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
export const getDisplayName = Component => Component.displayName || Component.name || (isString(Component) && Component.length > 0 ? Component : 'Unknown');
|
|
61
|
-
export const isString = obj => typeof obj === 'string';
|
|
62
|
-
export const isObject = obj => typeof obj === 'object' && obj !== null;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
2
|
-
import { useSSR } from './useSSR.js';
|
|
3
|
-
import { composeInitialProps } from './context.js';
|
|
4
|
-
import { getDisplayName } from './utils.js';
|
|
5
|
-
export const withSSR = () => function Extend(WrappedComponent) {
|
|
6
|
-
function I18nextWithSSR({
|
|
7
|
-
initialI18nStore,
|
|
8
|
-
initialLanguage,
|
|
9
|
-
...rest
|
|
10
|
-
}) {
|
|
11
|
-
useSSR(initialI18nStore, initialLanguage);
|
|
12
|
-
return createElement(WrappedComponent, {
|
|
13
|
-
...rest
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
|
|
17
|
-
I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`;
|
|
18
|
-
I18nextWithSSR.WrappedComponent = WrappedComponent;
|
|
19
|
-
return I18nextWithSSR;
|
|
20
|
-
};
|