@localazy/strapi-plugin 1.0.4 → 1.0.9
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/_chunks/FetchIdentity-4kkW9N7Y.js +981 -0
- package/dist/_chunks/FetchIdentity-BWSQAXt-.mjs +983 -0
- package/dist/_chunks/{LanguagesSelector-CeB7tVcb.mjs → LanguagesSelector-DwAGgpcR.mjs} +4 -2
- package/dist/_chunks/{LanguagesSelector-Bd8VFHib.js → LanguagesSelector-yWC_Yb_S.js} +12 -10
- package/dist/_chunks/{App-NRmSxuW3.js → LocalazyApp-DnaA768k.js} +136 -117
- package/dist/_chunks/{App-CtS6CrNn.mjs → LocalazyApp-zySanVTu.mjs} +32 -13
- package/dist/_chunks/{ContentTransferSetup-CeKXlzw_.mjs → LocalazyContentTransferSetup-C7qVIeix.mjs} +49 -456
- package/dist/_chunks/{ContentTransferSetup-DGs8MZPj.js → LocalazyContentTransferSetup-CeOM6bYA.js} +113 -520
- package/dist/_chunks/{GlobalSettings-rOwd0Y0E.mjs → LocalazyGlobalSettings-QvuLdsLe.mjs} +17 -8
- package/dist/_chunks/{GlobalSettings-CRMPRA3Y.js → LocalazyGlobalSettings-ewETL3oG.js} +61 -52
- package/dist/_chunks/LocalazyPanel-BXVLvFgD.js +83 -0
- package/dist/_chunks/LocalazyPanel-BotUsX-y.mjs +83 -0
- package/dist/_chunks/LocalazyStatusColumn-C81HewMg.mjs +51 -0
- package/dist/_chunks/LocalazyStatusColumn-Dt96YcGQ.js +51 -0
- package/dist/_chunks/{isEqual-CC-cEPwY.mjs → RequireLocalazyAuth-CDuyGCrT.mjs} +22 -1
- package/dist/_chunks/{isEqual-0M0aSdTT.js → RequireLocalazyAuth-CWBWETzC.js} +50 -29
- package/dist/_chunks/_commonjsHelpers-Bc2YnDe1.js +7 -0
- package/dist/_chunks/_commonjsHelpers-DWwsNxpa.mjs +8 -0
- package/dist/_chunks/en-CMWcM0nM.js +10 -0
- package/dist/_chunks/en-RX915msK.mjs +10 -0
- package/dist/_chunks/entry-exclusion-service-BVPICve2.mjs +60 -0
- package/dist/_chunks/entry-exclusion-service-CGV6iOkB.js +60 -0
- package/dist/_chunks/{has-model-changed-gNSOSMBa.js → has-model-changed-DVYRxVhM.js} +33 -32
- package/dist/_chunks/{has-model-changed-DViUIQHk.mjs → has-model-changed-DZL36gWh.mjs} +3 -2
- package/dist/_chunks/i18n-0dV2P-Hm.js +2378 -0
- package/dist/_chunks/i18n-RoETLXdU.mjs +2378 -0
- package/dist/_chunks/index-1he9s_bs.js +430 -0
- package/dist/_chunks/index-BIbKC7-V.mjs +432 -0
- package/dist/_chunks/index-CCxXsn7Z.js +254 -0
- package/dist/_chunks/{set-Cbi1yYuW.js → index-CaY3BYnQ.js} +878 -4379
- package/dist/_chunks/{set-Dnhh_SyE.mjs → index-CgI_aKe_.mjs} +906 -4408
- package/dist/_chunks/index-DsrYI6aB.mjs +231 -0
- package/dist/_chunks/initReactI18next-B0H8_DlW.js +60 -0
- package/dist/_chunks/initReactI18next-MHHxeg_9.mjs +61 -0
- package/dist/_chunks/{index-Dj68Ixl2.mjs → strapi-api-base-BE8VMlaA.js} +7 -234
- package/dist/_chunks/{index-Bbwk3kp3.js → strapi-api-base-DjeKGUw7.mjs} +15 -242
- package/dist/_chunks/useTranslation-BdIl-aLe.js +188 -0
- package/dist/_chunks/useTranslation-CZQ4lU1m.mjs +189 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/LocalazyPanel.d.ts +4 -0
- package/dist/admin/src/components/LocalazyStatusColumn.d.ts +3 -0
- package/dist/admin/src/components/RequireLocalazyAuth.d.ts +6 -0
- package/dist/admin/src/index.d.ts +1 -0
- package/dist/admin/src/modules/entry-exclusion/services/entry-exclusion-service.d.ts +18 -0
- package/dist/admin/src/modules/plugin-settings/locale/en.d.ts +8 -0
- package/dist/admin/src/pages/LocalazyApp.d.ts +2 -0
- package/dist/admin/src/pages/LocalazyContentTransferSetup.d.ts +2 -0
- package/dist/admin/src/pages/LocalazyGlobalSettings.d.ts +2 -0
- package/dist/server/index.js +202 -35
- package/dist/server/index.mjs +202 -35
- package/dist/server/src/controllers/entry-exclusion-controller.d.ts +21 -0
- package/dist/server/src/controllers/index.d.ts +7 -0
- package/dist/server/src/core/index.d.ts +6 -0
- package/dist/server/src/index.d.ts +15 -0
- package/dist/server/src/routes/entry-exclusion-routes.d.ts +9 -0
- package/dist/server/src/services/entry-exclusion-service.d.ts +23 -0
- package/dist/server/src/services/index.d.ts +8 -0
- package/package.json +2 -2
- package/dist/_chunks/en-BTf8goGM.mjs +0 -8
- package/dist/_chunks/en-CRtsEFtl.js +0 -8
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const _commonjsHelpers = require("./_commonjsHelpers-Bc2YnDe1.js");
|
|
5
|
+
const useTranslation = require("./useTranslation-BdIl-aLe.js");
|
|
6
|
+
const initReactI18next = require("./initReactI18next-B0H8_DlW.js");
|
|
7
|
+
var voidElements = {
|
|
8
|
+
"area": true,
|
|
9
|
+
"base": true,
|
|
10
|
+
"br": true,
|
|
11
|
+
"col": true,
|
|
12
|
+
"embed": true,
|
|
13
|
+
"hr": true,
|
|
14
|
+
"img": true,
|
|
15
|
+
"input": true,
|
|
16
|
+
"link": true,
|
|
17
|
+
"meta": true,
|
|
18
|
+
"param": true,
|
|
19
|
+
"source": true,
|
|
20
|
+
"track": true,
|
|
21
|
+
"wbr": true
|
|
22
|
+
};
|
|
23
|
+
const e = /* @__PURE__ */ _commonjsHelpers.getDefaultExportFromCjs(voidElements);
|
|
24
|
+
var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
|
|
25
|
+
function n(n2) {
|
|
26
|
+
var r2 = { type: "tag", name: "", voidElement: false, attrs: {}, children: [] }, i2 = n2.match(/<\/?([^\s]+?)[/\s>]/);
|
|
27
|
+
if (i2 && (r2.name = i2[1], (e[i2[1]] || "/" === n2.charAt(n2.length - 2)) && (r2.voidElement = true), r2.name.startsWith("!--"))) {
|
|
28
|
+
var s2 = n2.indexOf("-->");
|
|
29
|
+
return { type: "comment", comment: -1 !== s2 ? n2.slice(4, s2) : "" };
|
|
30
|
+
}
|
|
31
|
+
for (var a2 = new RegExp(t), c2 = null; null !== (c2 = a2.exec(n2)); ) if (c2[0].trim()) if (c2[1]) {
|
|
32
|
+
var o = c2[1].trim(), l = [o, ""];
|
|
33
|
+
o.indexOf("=") > -1 && (l = o.split("=")), r2.attrs[l[0]] = l[1], a2.lastIndex--;
|
|
34
|
+
} else c2[2] && (r2.attrs[c2[2]] = c2[3].trim().substring(1, c2[3].length - 1));
|
|
35
|
+
return r2;
|
|
36
|
+
}
|
|
37
|
+
var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g, i = /^\s*$/, s = /* @__PURE__ */ Object.create(null);
|
|
38
|
+
function a(e2, t2) {
|
|
39
|
+
switch (t2.type) {
|
|
40
|
+
case "text":
|
|
41
|
+
return e2 + t2.content;
|
|
42
|
+
case "tag":
|
|
43
|
+
return e2 += "<" + t2.name + (t2.attrs ? function(e3) {
|
|
44
|
+
var t3 = [];
|
|
45
|
+
for (var n2 in e3) t3.push(n2 + '="' + e3[n2] + '"');
|
|
46
|
+
return t3.length ? " " + t3.join(" ") : "";
|
|
47
|
+
}(t2.attrs) : "") + (t2.voidElement ? "/>" : ">"), t2.voidElement ? e2 : e2 + t2.children.reduce(a, "") + "</" + t2.name + ">";
|
|
48
|
+
case "comment":
|
|
49
|
+
return e2 + "<!--" + t2.comment + "-->";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
var c = { parse: function(e2, t2) {
|
|
53
|
+
t2 || (t2 = {}), t2.components || (t2.components = s);
|
|
54
|
+
var a2, c2 = [], o = [], l = -1, m = false;
|
|
55
|
+
if (0 !== e2.indexOf("<")) {
|
|
56
|
+
var u = e2.indexOf("<");
|
|
57
|
+
c2.push({ type: "text", content: -1 === u ? e2 : e2.substring(0, u) });
|
|
58
|
+
}
|
|
59
|
+
return e2.replace(r, function(r2, s2) {
|
|
60
|
+
if (m) {
|
|
61
|
+
if (r2 !== "</" + a2.name + ">") return;
|
|
62
|
+
m = false;
|
|
63
|
+
}
|
|
64
|
+
var u2, f = "/" !== r2.charAt(1), h = r2.startsWith("<!--"), p = s2 + r2.length, d = e2.charAt(p);
|
|
65
|
+
if (h) {
|
|
66
|
+
var v = n(r2);
|
|
67
|
+
return l < 0 ? (c2.push(v), c2) : ((u2 = o[l]).children.push(v), c2);
|
|
68
|
+
}
|
|
69
|
+
if (f && (l++, "tag" === (a2 = n(r2)).type && t2.components[a2.name] && (a2.type = "component", m = true), a2.voidElement || m || !d || "<" === d || a2.children.push({ type: "text", content: e2.slice(p, e2.indexOf("<", p)) }), 0 === l && c2.push(a2), (u2 = o[l - 1]) && u2.children.push(a2), o[l] = a2), (!f || a2.voidElement) && (l > -1 && (a2.voidElement || a2.name === r2.slice(2, -1)) && (l--, a2 = -1 === l ? c2 : o[l]), !m && "<" !== d && d)) {
|
|
70
|
+
u2 = -1 === l ? c2 : o[l].children;
|
|
71
|
+
var x = e2.indexOf("<", p), g = e2.slice(p, -1 === x ? void 0 : x);
|
|
72
|
+
i.test(g) && (g = " "), (x > -1 && l + u2.length >= 0 || " " !== g) && u2.push({ type: "text", content: g });
|
|
73
|
+
}
|
|
74
|
+
}), c2;
|
|
75
|
+
}, stringify: function(e2) {
|
|
76
|
+
return e2.reduce(function(e3, t2) {
|
|
77
|
+
return e3 + a("", t2);
|
|
78
|
+
}, "");
|
|
79
|
+
} };
|
|
80
|
+
const hasChildren = (node, checkLength) => {
|
|
81
|
+
if (!node) return false;
|
|
82
|
+
const base = node.props?.children ?? node.children;
|
|
83
|
+
if (checkLength) return base.length > 0;
|
|
84
|
+
return !!base;
|
|
85
|
+
};
|
|
86
|
+
const getChildren = (node) => {
|
|
87
|
+
if (!node) return [];
|
|
88
|
+
const children = node.props?.children ?? node.children;
|
|
89
|
+
return node.props?.i18nIsDynamicList ? getAsArray(children) : children;
|
|
90
|
+
};
|
|
91
|
+
const hasValidReactChildren = (children) => Array.isArray(children) && children.every(React.isValidElement);
|
|
92
|
+
const getAsArray = (data) => Array.isArray(data) ? data : [data];
|
|
93
|
+
const mergeProps = (source, target) => {
|
|
94
|
+
const newTarget = {
|
|
95
|
+
...target
|
|
96
|
+
};
|
|
97
|
+
newTarget.props = Object.assign(source.props, target.props);
|
|
98
|
+
return newTarget;
|
|
99
|
+
};
|
|
100
|
+
const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
|
|
101
|
+
if (!children) return "";
|
|
102
|
+
let stringNode = "";
|
|
103
|
+
const childrenArray = getAsArray(children);
|
|
104
|
+
const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : [];
|
|
105
|
+
childrenArray.forEach((child, childIndex) => {
|
|
106
|
+
if (useTranslation.isString(child)) {
|
|
107
|
+
stringNode += `${child}`;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (React.isValidElement(child)) {
|
|
111
|
+
const {
|
|
112
|
+
props,
|
|
113
|
+
type
|
|
114
|
+
} = child;
|
|
115
|
+
const childPropsCount = Object.keys(props).length;
|
|
116
|
+
const shouldKeepChild = keepArray.indexOf(type) > -1;
|
|
117
|
+
const childChildren = props.children;
|
|
118
|
+
if (!childChildren && shouldKeepChild && !childPropsCount) {
|
|
119
|
+
stringNode += `<${type}/>`;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
|
|
123
|
+
stringNode += `<${childIndex}></${childIndex}>`;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (shouldKeepChild && childPropsCount === 1 && useTranslation.isString(childChildren)) {
|
|
127
|
+
stringNode += `<${type}>${childChildren}</${type}>`;
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
|
|
131
|
+
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (child === null) {
|
|
135
|
+
useTranslation.warn(i18n, "TRANS_NULL_VALUE", `Passed in a null value as child`, {
|
|
136
|
+
i18nKey
|
|
137
|
+
});
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (useTranslation.isObject(child)) {
|
|
141
|
+
const {
|
|
142
|
+
format,
|
|
143
|
+
...clone
|
|
144
|
+
} = child;
|
|
145
|
+
const keys = Object.keys(clone);
|
|
146
|
+
if (keys.length === 1) {
|
|
147
|
+
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
148
|
+
stringNode += `{{${value}}}`;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
useTranslation.warn(i18n, "TRANS_INVALID_OBJ", `Invalid child - Object should only have keys {{ value, format }} (format is optional).`, {
|
|
152
|
+
i18nKey,
|
|
153
|
+
child
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
useTranslation.warn(i18n, "TRANS_INVALID_VAR", `Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`, {
|
|
158
|
+
i18nKey,
|
|
159
|
+
child
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
return stringNode;
|
|
163
|
+
};
|
|
164
|
+
const renderNodes = (children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
|
|
165
|
+
if (targetString === "") return [];
|
|
166
|
+
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
167
|
+
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map((keep) => `<${keep}`).join("|")).test(targetString);
|
|
168
|
+
if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
|
|
169
|
+
const data = {};
|
|
170
|
+
const getData = (childs) => {
|
|
171
|
+
const childrenArray = getAsArray(childs);
|
|
172
|
+
childrenArray.forEach((child) => {
|
|
173
|
+
if (useTranslation.isString(child)) return;
|
|
174
|
+
if (hasChildren(child)) getData(getChildren(child));
|
|
175
|
+
else if (useTranslation.isObject(child) && !React.isValidElement(child)) Object.assign(data, child);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
getData(children);
|
|
179
|
+
const ast = c.parse(`<0>${targetString}</0>`);
|
|
180
|
+
const opts = {
|
|
181
|
+
...data,
|
|
182
|
+
...combinedTOpts
|
|
183
|
+
};
|
|
184
|
+
const renderInner = (child, node, rootReactNode) => {
|
|
185
|
+
const childs = getChildren(child);
|
|
186
|
+
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
187
|
+
return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren;
|
|
188
|
+
};
|
|
189
|
+
const pushTranslatedJSX = (child, inner, mem, i2, isVoid) => {
|
|
190
|
+
if (child.dummy) {
|
|
191
|
+
child.children = inner;
|
|
192
|
+
mem.push(React.cloneElement(child, {
|
|
193
|
+
key: i2
|
|
194
|
+
}, isVoid ? void 0 : inner));
|
|
195
|
+
} else {
|
|
196
|
+
mem.push(...React.Children.map([child], (c2) => {
|
|
197
|
+
const props = {
|
|
198
|
+
...c2.props
|
|
199
|
+
};
|
|
200
|
+
delete props.i18nIsDynamicList;
|
|
201
|
+
return React.createElement(c2.type, {
|
|
202
|
+
...props,
|
|
203
|
+
key: i2,
|
|
204
|
+
ref: c2.ref
|
|
205
|
+
}, isVoid ? null : inner);
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
const mapAST = (reactNode, astNode, rootReactNode) => {
|
|
210
|
+
const reactNodes = getAsArray(reactNode);
|
|
211
|
+
const astNodes = getAsArray(astNode);
|
|
212
|
+
return astNodes.reduce((mem, node, i2) => {
|
|
213
|
+
const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
214
|
+
if (node.type === "tag") {
|
|
215
|
+
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
216
|
+
if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
|
|
217
|
+
if (!tmp) tmp = {};
|
|
218
|
+
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
219
|
+
props: node.attrs
|
|
220
|
+
}, tmp) : tmp;
|
|
221
|
+
const isElement = React.isValidElement(child);
|
|
222
|
+
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
223
|
+
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && useTranslation.isObject(child) && child.dummy && !isElement;
|
|
224
|
+
const isKnownComponent = useTranslation.isObject(children) && Object.hasOwnProperty.call(children, node.name);
|
|
225
|
+
if (useTranslation.isString(child)) {
|
|
226
|
+
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
227
|
+
mem.push(value);
|
|
228
|
+
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
229
|
+
const inner = renderInner(child, node, rootReactNode);
|
|
230
|
+
pushTranslatedJSX(child, inner, mem, i2);
|
|
231
|
+
} else if (isEmptyTransWithHTML) {
|
|
232
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
233
|
+
pushTranslatedJSX(child, inner, mem, i2);
|
|
234
|
+
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
235
|
+
if (isKnownComponent) {
|
|
236
|
+
const inner = renderInner(child, node, rootReactNode);
|
|
237
|
+
pushTranslatedJSX(child, inner, mem, i2, node.voidElement);
|
|
238
|
+
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
239
|
+
if (node.voidElement) {
|
|
240
|
+
mem.push(React.createElement(node.name, {
|
|
241
|
+
key: `${node.name}-${i2}`
|
|
242
|
+
}));
|
|
243
|
+
} else {
|
|
244
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
245
|
+
mem.push(React.createElement(node.name, {
|
|
246
|
+
key: `${node.name}-${i2}`
|
|
247
|
+
}, inner));
|
|
248
|
+
}
|
|
249
|
+
} else if (node.voidElement) {
|
|
250
|
+
mem.push(`<${node.name} />`);
|
|
251
|
+
} else {
|
|
252
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
253
|
+
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
254
|
+
}
|
|
255
|
+
} else if (useTranslation.isObject(child) && !isElement) {
|
|
256
|
+
const content = node.children[0] ? translationContent : null;
|
|
257
|
+
if (content) mem.push(content);
|
|
258
|
+
} else {
|
|
259
|
+
pushTranslatedJSX(child, translationContent, mem, i2, node.children.length !== 1 || !translationContent);
|
|
260
|
+
}
|
|
261
|
+
} else if (node.type === "text") {
|
|
262
|
+
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
263
|
+
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
264
|
+
if (wrapTextNodes) {
|
|
265
|
+
mem.push(React.createElement(wrapTextNodes, {
|
|
266
|
+
key: `${node.name}-${i2}`
|
|
267
|
+
}, content));
|
|
268
|
+
} else {
|
|
269
|
+
mem.push(content);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return mem;
|
|
273
|
+
}, []);
|
|
274
|
+
};
|
|
275
|
+
const result = mapAST([{
|
|
276
|
+
dummy: true,
|
|
277
|
+
children: children || []
|
|
278
|
+
}], ast, getAsArray(children || []));
|
|
279
|
+
return getChildren(result[0]);
|
|
280
|
+
};
|
|
281
|
+
const fixComponentProps = (component, index, translation) => {
|
|
282
|
+
const componentKey = component.key || index;
|
|
283
|
+
const comp = React.cloneElement(component, {
|
|
284
|
+
key: componentKey
|
|
285
|
+
});
|
|
286
|
+
if (!comp.props || !comp.props.children || translation.indexOf(`${index}/>`) < 0 && translation.indexOf(`${index} />`) < 0) {
|
|
287
|
+
return comp;
|
|
288
|
+
}
|
|
289
|
+
function Componentized() {
|
|
290
|
+
return React.createElement(React.Fragment, null, comp);
|
|
291
|
+
}
|
|
292
|
+
return React.createElement(Componentized);
|
|
293
|
+
};
|
|
294
|
+
const generateArrayComponents = (components, translation) => components.map((c2, index) => fixComponentProps(c2, index, translation));
|
|
295
|
+
const generateObjectComponents = (components, translation) => {
|
|
296
|
+
const componentMap = {};
|
|
297
|
+
Object.keys(components).forEach((c2) => {
|
|
298
|
+
Object.assign(componentMap, {
|
|
299
|
+
[c2]: fixComponentProps(components[c2], c2, translation)
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
return componentMap;
|
|
303
|
+
};
|
|
304
|
+
const generateComponents = (components, translation, i18n, i18nKey) => {
|
|
305
|
+
if (!components) return null;
|
|
306
|
+
if (Array.isArray(components)) {
|
|
307
|
+
return generateArrayComponents(components, translation);
|
|
308
|
+
}
|
|
309
|
+
if (useTranslation.isObject(components)) {
|
|
310
|
+
return generateObjectComponents(components, translation);
|
|
311
|
+
}
|
|
312
|
+
useTranslation.warnOnce(i18n, "TRANS_INVALID_COMPONENTS", `<Trans /> "components" prop expects an object or array`, {
|
|
313
|
+
i18nKey
|
|
314
|
+
});
|
|
315
|
+
return null;
|
|
316
|
+
};
|
|
317
|
+
function Trans$1({
|
|
318
|
+
children,
|
|
319
|
+
count,
|
|
320
|
+
parent,
|
|
321
|
+
i18nKey,
|
|
322
|
+
context,
|
|
323
|
+
tOptions = {},
|
|
324
|
+
values,
|
|
325
|
+
defaults,
|
|
326
|
+
components,
|
|
327
|
+
ns,
|
|
328
|
+
i18n: i18nFromProps,
|
|
329
|
+
t: tFromProps,
|
|
330
|
+
shouldUnescape,
|
|
331
|
+
...additionalProps
|
|
332
|
+
}) {
|
|
333
|
+
const i18n = i18nFromProps || initReactI18next.getI18n();
|
|
334
|
+
if (!i18n) {
|
|
335
|
+
useTranslation.warnOnce(i18n, "NO_I18NEXT_INSTANCE", `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
|
|
336
|
+
i18nKey
|
|
337
|
+
});
|
|
338
|
+
return children;
|
|
339
|
+
}
|
|
340
|
+
const t2 = tFromProps || i18n.t.bind(i18n) || ((k) => k);
|
|
341
|
+
const reactI18nextOptions = {
|
|
342
|
+
...initReactI18next.getDefaults(),
|
|
343
|
+
...i18n.options?.react
|
|
344
|
+
};
|
|
345
|
+
let namespaces = ns || t2.ns || i18n.options?.defaultNS;
|
|
346
|
+
namespaces = useTranslation.isString(namespaces) ? [namespaces] : namespaces || ["translation"];
|
|
347
|
+
const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
|
|
348
|
+
const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
349
|
+
const {
|
|
350
|
+
hashTransKey
|
|
351
|
+
} = reactI18nextOptions;
|
|
352
|
+
const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue);
|
|
353
|
+
if (i18n.options?.interpolation?.defaultVariables) {
|
|
354
|
+
values = values && Object.keys(values).length > 0 ? {
|
|
355
|
+
...values,
|
|
356
|
+
...i18n.options.interpolation.defaultVariables
|
|
357
|
+
} : {
|
|
358
|
+
...i18n.options.interpolation.defaultVariables
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
const interpolationOverride = values || count !== void 0 && !i18n.options?.interpolation?.alwaysFormat || !children ? tOptions.interpolation : {
|
|
362
|
+
interpolation: {
|
|
363
|
+
...tOptions.interpolation,
|
|
364
|
+
prefix: "#$?",
|
|
365
|
+
suffix: "?$#"
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const combinedTOpts = {
|
|
369
|
+
...tOptions,
|
|
370
|
+
context: context || tOptions.context,
|
|
371
|
+
count,
|
|
372
|
+
...values,
|
|
373
|
+
...interpolationOverride,
|
|
374
|
+
defaultValue,
|
|
375
|
+
ns: namespaces
|
|
376
|
+
};
|
|
377
|
+
const translation = key ? t2(key, combinedTOpts) : defaultValue;
|
|
378
|
+
const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
|
|
379
|
+
const content = renderNodes(generatedComponents || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
380
|
+
const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
|
|
381
|
+
return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content;
|
|
382
|
+
}
|
|
383
|
+
function Trans({
|
|
384
|
+
children,
|
|
385
|
+
count,
|
|
386
|
+
parent,
|
|
387
|
+
i18nKey,
|
|
388
|
+
context,
|
|
389
|
+
tOptions = {},
|
|
390
|
+
values,
|
|
391
|
+
defaults,
|
|
392
|
+
components,
|
|
393
|
+
ns,
|
|
394
|
+
i18n: i18nFromProps,
|
|
395
|
+
t: tFromProps,
|
|
396
|
+
shouldUnescape,
|
|
397
|
+
...additionalProps
|
|
398
|
+
}) {
|
|
399
|
+
const {
|
|
400
|
+
i18n: i18nFromContext,
|
|
401
|
+
defaultNS: defaultNSFromContext
|
|
402
|
+
} = React.useContext(useTranslation.I18nContext) || {};
|
|
403
|
+
const i18n = i18nFromProps || i18nFromContext || initReactI18next.getI18n();
|
|
404
|
+
const t2 = tFromProps || i18n?.t.bind(i18n);
|
|
405
|
+
return Trans$1({
|
|
406
|
+
children,
|
|
407
|
+
count,
|
|
408
|
+
parent,
|
|
409
|
+
i18nKey,
|
|
410
|
+
context,
|
|
411
|
+
tOptions,
|
|
412
|
+
values,
|
|
413
|
+
defaults,
|
|
414
|
+
components,
|
|
415
|
+
ns: ns || t2?.ns || defaultNSFromContext || i18n?.options?.defaultNS,
|
|
416
|
+
i18n,
|
|
417
|
+
t: tFromProps,
|
|
418
|
+
shouldUnescape,
|
|
419
|
+
...additionalProps
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
exports.I18nContext = useTranslation.I18nContext;
|
|
423
|
+
exports.useTranslation = useTranslation.useTranslation;
|
|
424
|
+
exports.getDefaults = initReactI18next.getDefaults;
|
|
425
|
+
exports.getI18n = initReactI18next.getI18n;
|
|
426
|
+
exports.initReactI18next = initReactI18next.initReactI18next;
|
|
427
|
+
exports.setDefaults = initReactI18next.setDefaults;
|
|
428
|
+
exports.setI18n = initReactI18next.setI18n;
|
|
429
|
+
exports.Trans = Trans;
|
|
430
|
+
exports.TransWithoutContext = Trans$1;
|