@uniformdev/tms-sdk 19.154.1-alpha.26 → 19.154.1-alpha.28
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/index.d.mts +3 -10
- package/dist/index.d.ts +3 -10
- package/dist/index.esm.js +251 -57
- package/dist/index.js +253 -59
- package/dist/index.mjs +251 -57
- package/package.json +6 -7
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
33
33
|
|
|
34
34
|
// src/collectTranslationPayload.ts
|
|
35
35
|
var import_canvas2 = require("@uniformdev/canvas");
|
|
36
|
-
var
|
|
36
|
+
var import_richtext4 = require("@uniformdev/richtext");
|
|
37
37
|
|
|
38
38
|
// src/constants.ts
|
|
39
39
|
var TRANSLATION_PAYLOAD_SOURCE_KEY = "source";
|
|
@@ -44,10 +44,211 @@ var SUPPORTED_PARAM_TYPES = {
|
|
|
44
44
|
richText: "richText"
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
// src/richText/renderAsTranslatableXml.ts
|
|
48
|
+
var import_richtext = require("@uniformdev/richtext");
|
|
49
|
+
var REF_ATTRIBUTE_NAME = "ref";
|
|
50
|
+
function renderAsTranslatableXml(root) {
|
|
51
|
+
if (!root) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const result = {
|
|
55
|
+
attributes: [],
|
|
56
|
+
xmlParts: []
|
|
57
|
+
};
|
|
58
|
+
renderXmlNode(result, root);
|
|
59
|
+
const metadata = result.attributes.reduce((result2, current, index) => {
|
|
60
|
+
result2[String(index)] = {
|
|
61
|
+
attrs: current
|
|
62
|
+
};
|
|
63
|
+
return result2;
|
|
64
|
+
}, {});
|
|
65
|
+
return {
|
|
66
|
+
metadata,
|
|
67
|
+
xml: result.xmlParts.join("")
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
var IGNORE_ATTRS = ["type", "children", "text"];
|
|
71
|
+
function renderXmlNode(context, node) {
|
|
72
|
+
if (!node) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const base64Props = getPropsAsBase64(node, IGNORE_ATTRS);
|
|
76
|
+
let refKey = context.attributes.findIndex((x) => x === base64Props);
|
|
77
|
+
if (refKey == -1) {
|
|
78
|
+
context.attributes.push(base64Props);
|
|
79
|
+
refKey = context.attributes.length - 1;
|
|
80
|
+
}
|
|
81
|
+
context.xmlParts.push(`<${node.type} ${REF_ATTRIBUTE_NAME}="${refKey}"`);
|
|
82
|
+
const metaAttrsString = getNodeMetaAttributesString(node);
|
|
83
|
+
if (metaAttrsString) {
|
|
84
|
+
context.xmlParts.push(" " + metaAttrsString);
|
|
85
|
+
}
|
|
86
|
+
context.xmlParts.push(">");
|
|
87
|
+
if ((0, import_richtext.isRichTextNodeType)(node, "text")) {
|
|
88
|
+
context.xmlParts.push(node.text);
|
|
89
|
+
} else if (Array.isArray(node.children) && node.children.length) {
|
|
90
|
+
node.children.forEach((child) => {
|
|
91
|
+
renderXmlNode(context, child);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
context.xmlParts.push(`</${node.type}>`);
|
|
95
|
+
}
|
|
96
|
+
var getPropsAsBase64 = (node, ignoreProps) => {
|
|
97
|
+
const props = {};
|
|
98
|
+
Object.keys(node).forEach((key) => {
|
|
99
|
+
if (!ignoreProps.includes(key)) {
|
|
100
|
+
props[key] = node[key];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return btoa(JSON.stringify(props));
|
|
104
|
+
};
|
|
105
|
+
var getNodeMetaAttributesString = (node) => {
|
|
106
|
+
const metadata = {};
|
|
107
|
+
if ((0, import_richtext.isRichTextNodeType)(node, "text")) {
|
|
108
|
+
const formatTags = (0, import_richtext.getRichTextTagsFromTextFormat)(node.format);
|
|
109
|
+
if (formatTags.length) {
|
|
110
|
+
metadata["format"] = formatTags.join(" ");
|
|
111
|
+
}
|
|
112
|
+
} else if ((0, import_richtext.isRichTextNodeType)(node, "heading")) {
|
|
113
|
+
if (node.tag) {
|
|
114
|
+
metadata["tag"] = node.tag;
|
|
115
|
+
}
|
|
116
|
+
} else if ((0, import_richtext.isRichTextNodeType)(node, "paragraph")) {
|
|
117
|
+
if (node.format) {
|
|
118
|
+
metadata["format"] = node.format;
|
|
119
|
+
}
|
|
120
|
+
} else if ((0, import_richtext.isRichTextNodeType)(node, "list")) {
|
|
121
|
+
if (node.tag) {
|
|
122
|
+
metadata["tag"] = node.tag;
|
|
123
|
+
}
|
|
124
|
+
} else if ((0, import_richtext.isRichTextNodeType)(node, "listitem")) {
|
|
125
|
+
metadata["value"] = String(node.value);
|
|
126
|
+
}
|
|
127
|
+
if (!Object.keys(metadata).length) {
|
|
128
|
+
return "";
|
|
129
|
+
}
|
|
130
|
+
const result = [];
|
|
131
|
+
Object.entries(metadata).forEach(([key, value]) => {
|
|
132
|
+
result.push(`${key}="${value}"`);
|
|
133
|
+
});
|
|
134
|
+
return result.join(" ");
|
|
135
|
+
};
|
|
136
|
+
|
|
47
137
|
// src/translationHelpers.ts
|
|
48
138
|
var import_canvas = require("@uniformdev/canvas");
|
|
49
|
-
var
|
|
139
|
+
var import_richtext3 = require("@uniformdev/richtext");
|
|
50
140
|
var import_lite = require("dequal/lite");
|
|
141
|
+
|
|
142
|
+
// src/richText/parseTranslatableXml.ts
|
|
143
|
+
var import_richtext2 = require("@uniformdev/richtext");
|
|
144
|
+
var import_fast_xml_parser = require("fast-xml-parser");
|
|
145
|
+
var ATTR_NAME_PREFIX = "@_";
|
|
146
|
+
var ATTRIBUTES_SUBNODE_NAME = ":@";
|
|
147
|
+
var IGNORE_PROPS_PREFIX = [ATTR_NAME_PREFIX, ATTRIBUTES_SUBNODE_NAME, "#"];
|
|
148
|
+
var parseTranslatableXml = ({ xml, metadata }) => {
|
|
149
|
+
const parser = new import_fast_xml_parser.XMLParser({
|
|
150
|
+
ignoreDeclaration: true,
|
|
151
|
+
ignorePiTags: true,
|
|
152
|
+
ignoreAttributes: false,
|
|
153
|
+
preserveOrder: true,
|
|
154
|
+
trimValues: false,
|
|
155
|
+
attributeNamePrefix: ATTR_NAME_PREFIX
|
|
156
|
+
});
|
|
157
|
+
const rawObj = parser.parse(xml);
|
|
158
|
+
const result = processParseObject(rawObj, {
|
|
159
|
+
metadata,
|
|
160
|
+
nodeTypes: []
|
|
161
|
+
});
|
|
162
|
+
return result;
|
|
163
|
+
};
|
|
164
|
+
var processParseObject = (rawObj, context) => {
|
|
165
|
+
const result = visitAndTransformNode(rawObj, context);
|
|
166
|
+
const root = Array.isArray(result) ? result.at(0) : result;
|
|
167
|
+
if (root && root.type === "root") {
|
|
168
|
+
const value = { root };
|
|
169
|
+
if ((0, import_richtext2.isRichTextValue)(value)) {
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
};
|
|
175
|
+
var visitAndTransformNode = (node, context) => {
|
|
176
|
+
if (Array.isArray(node)) {
|
|
177
|
+
return node.map((x) => visitAndTransformNode(x, context)).filter((node2) => !!node2);
|
|
178
|
+
} else if (typeof node === "object" && node !== null) {
|
|
179
|
+
const type = Object.keys(node).find(
|
|
180
|
+
(key) => !IGNORE_PROPS_PREFIX.some((prefix) => key.startsWith(prefix))
|
|
181
|
+
);
|
|
182
|
+
if (!type) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const transformed = {};
|
|
186
|
+
transformed["type"] = type;
|
|
187
|
+
const propsFromRef = restorePropsFromRef(node, context);
|
|
188
|
+
Object.entries(propsFromRef).forEach(([key, value]) => {
|
|
189
|
+
transformed[key] = value;
|
|
190
|
+
});
|
|
191
|
+
if (type === "text") {
|
|
192
|
+
const nestedNode = node[type];
|
|
193
|
+
const nestedNodeAsArray = Array.isArray(nestedNode) ? nestedNode : [nestedNode];
|
|
194
|
+
const firstChild = nestedNodeAsArray.at(0);
|
|
195
|
+
const text = firstChild == null ? void 0 : firstChild["#text"];
|
|
196
|
+
transformed["text"] = typeof text === "string" && text ? text : "";
|
|
197
|
+
} else {
|
|
198
|
+
const children = [];
|
|
199
|
+
const nestedNode = node[type];
|
|
200
|
+
if (typeof nestedNode === "object" && nestedNode) {
|
|
201
|
+
const nestedNodeAsArray = Array.isArray(nestedNode) ? nestedNode : [nestedNode];
|
|
202
|
+
nestedNodeAsArray.forEach((currNode) => {
|
|
203
|
+
const transformed2 = visitAndTransformNode(currNode, context);
|
|
204
|
+
if (transformed2) {
|
|
205
|
+
children.push(transformed2);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (children.length) {
|
|
210
|
+
transformed["children"] = children;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return transformed;
|
|
214
|
+
} else {
|
|
215
|
+
return node;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
var restorePropsFromRef = (node, context) => {
|
|
219
|
+
const result = {};
|
|
220
|
+
let uniformRef = node[ATTR_NAME_PREFIX + REF_ATTRIBUTE_NAME];
|
|
221
|
+
if (!uniformRef) {
|
|
222
|
+
const attrsSubNode = node[ATTRIBUTES_SUBNODE_NAME];
|
|
223
|
+
uniformRef = attrsSubNode == null ? void 0 : attrsSubNode[ATTR_NAME_PREFIX + REF_ATTRIBUTE_NAME];
|
|
224
|
+
}
|
|
225
|
+
if (typeof uniformRef === "string" && uniformRef && context.metadata[uniformRef]) {
|
|
226
|
+
const metadata = context.metadata[uniformRef];
|
|
227
|
+
if (metadata.attrs) {
|
|
228
|
+
const decodedProps = JSON.parse(atob(metadata.attrs));
|
|
229
|
+
Object.keys(decodedProps).forEach((key) => {
|
|
230
|
+
result[key] = decodedProps[key];
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/richText/types.ts
|
|
238
|
+
var isTranslatableRichTextValue = (value) => {
|
|
239
|
+
if (typeof value !== "object" || !value) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
if (!("xml" in value) || typeof value.xml !== "string") {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
if (!("metadata" in value) || typeof value.metadata !== "object" || !value.metadata) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
return true;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// src/translationHelpers.ts
|
|
51
252
|
var MERGE_TRANSLATION_ERRORS = {
|
|
52
253
|
unknown: "Unknown error",
|
|
53
254
|
"invalid-args": "Invalid arguments",
|
|
@@ -61,7 +262,6 @@ var createErrorResult = (errorKind) => {
|
|
|
61
262
|
var processComponentTranslation = ({
|
|
62
263
|
uniformSourceLocale,
|
|
63
264
|
uniformTargetLocale,
|
|
64
|
-
overrideModifiedTargetLocale,
|
|
65
265
|
originalNode,
|
|
66
266
|
translatedComponent
|
|
67
267
|
}) => {
|
|
@@ -81,7 +281,6 @@ var processComponentTranslation = ({
|
|
|
81
281
|
const result = processParameterTranslation({
|
|
82
282
|
uniformSourceLocale,
|
|
83
283
|
uniformTargetLocale,
|
|
84
|
-
overrideModifiedTargetLocale,
|
|
85
284
|
originalParameter,
|
|
86
285
|
parameter
|
|
87
286
|
});
|
|
@@ -98,7 +297,6 @@ var processComponentTranslation = ({
|
|
|
98
297
|
const result = processOverrideTranslation({
|
|
99
298
|
uniformSourceLocale,
|
|
100
299
|
uniformTargetLocale,
|
|
101
|
-
overrideModifiedTargetLocale,
|
|
102
300
|
originalOverride,
|
|
103
301
|
override
|
|
104
302
|
});
|
|
@@ -111,7 +309,6 @@ var processComponentTranslation = ({
|
|
|
111
309
|
var processParameterTranslation = ({
|
|
112
310
|
uniformSourceLocale,
|
|
113
311
|
uniformTargetLocale,
|
|
114
|
-
overrideModifiedTargetLocale,
|
|
115
312
|
originalParameter,
|
|
116
313
|
parameter
|
|
117
314
|
}) => {
|
|
@@ -130,50 +327,48 @@ var processParameterTranslation = ({
|
|
|
130
327
|
left: originalParameter.locales[uniformSourceLocale],
|
|
131
328
|
right: sourceValue
|
|
132
329
|
});
|
|
133
|
-
const isTargetValueUntouched =
|
|
330
|
+
const isTargetValueUntouched = isSameParameterValue({
|
|
134
331
|
parameterType: originalParameter.type,
|
|
135
332
|
left: originalParameter.locales[uniformTargetLocale],
|
|
136
333
|
right: originalTargetValue
|
|
137
334
|
});
|
|
138
|
-
if (targetValue && isSourceValueUntouched && isTargetValueUntouched) {
|
|
139
|
-
|
|
140
|
-
|
|
335
|
+
if (targetValue !== void 0 && isSourceValueUntouched && isTargetValueUntouched) {
|
|
336
|
+
if (parameter.type == SUPPORTED_PARAM_TYPES.richText && isTranslatableRichTextValue(targetValue)) {
|
|
337
|
+
try {
|
|
338
|
+
const richTextValue = parseTranslatableXml(targetValue);
|
|
339
|
+
originalParameter.locales[uniformTargetLocale] = richTextValue;
|
|
340
|
+
return { updated: true };
|
|
341
|
+
} catch (e) {
|
|
342
|
+
return { updated: false };
|
|
343
|
+
}
|
|
344
|
+
} else if (parameter.type == SUPPORTED_PARAM_TYPES.text) {
|
|
345
|
+
originalParameter.locales[uniformTargetLocale] = targetValue;
|
|
346
|
+
return { updated: true };
|
|
347
|
+
}
|
|
141
348
|
}
|
|
142
349
|
return { updated: false };
|
|
143
350
|
};
|
|
144
351
|
var processOverrideTranslation = ({
|
|
145
352
|
uniformSourceLocale,
|
|
146
353
|
uniformTargetLocale,
|
|
147
|
-
overrideModifiedTargetLocale,
|
|
148
354
|
originalOverride,
|
|
149
355
|
override
|
|
150
356
|
}) => {
|
|
151
357
|
var _a, _b;
|
|
152
358
|
let updated = false;
|
|
153
359
|
Object.entries((_a = override.parameters) != null ? _a : {}).forEach(([paramKey, parameter]) => {
|
|
154
|
-
var _a2
|
|
360
|
+
var _a2;
|
|
155
361
|
const originalParameter = (_a2 = originalOverride.parameters) == null ? void 0 : _a2[paramKey];
|
|
156
|
-
if (!originalParameter
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (originalParameter.type !== parameter.type) {
|
|
362
|
+
if (!originalParameter) {
|
|
160
363
|
return;
|
|
161
364
|
}
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
left: originalParameter.locales[uniformSourceLocale],
|
|
168
|
-
right: sourceValue
|
|
169
|
-
});
|
|
170
|
-
const isTargetValueUntouched = overrideModifiedTargetLocale || isSameParameterValue({
|
|
171
|
-
parameterType: originalParameter.type,
|
|
172
|
-
left: originalParameter.locales[uniformTargetLocale],
|
|
173
|
-
right: originalTargetValue
|
|
365
|
+
const result = processParameterTranslation({
|
|
366
|
+
uniformSourceLocale,
|
|
367
|
+
uniformTargetLocale,
|
|
368
|
+
originalParameter,
|
|
369
|
+
parameter
|
|
174
370
|
});
|
|
175
|
-
if (
|
|
176
|
-
originalParameter.locales[uniformTargetLocale] = targetValue;
|
|
371
|
+
if (result.updated) {
|
|
177
372
|
updated = true;
|
|
178
373
|
}
|
|
179
374
|
});
|
|
@@ -206,7 +401,6 @@ var processOverrideTranslation = ({
|
|
|
206
401
|
const { updated: isComponentUpdated } = processComponentTranslation({
|
|
207
402
|
uniformSourceLocale,
|
|
208
403
|
uniformTargetLocale,
|
|
209
|
-
overrideModifiedTargetLocale,
|
|
210
404
|
originalNode: originalComponent,
|
|
211
405
|
translatedComponent: component
|
|
212
406
|
});
|
|
@@ -228,8 +422,12 @@ var isSameParameterValue = ({
|
|
|
228
422
|
return left === right || !left && !right;
|
|
229
423
|
break;
|
|
230
424
|
case SUPPORTED_PARAM_TYPES.richText:
|
|
231
|
-
|
|
232
|
-
|
|
425
|
+
try {
|
|
426
|
+
if ((0, import_richtext3.isRichTextValueConsideredEmpty)(left) && (0, import_richtext3.isRichTextValueConsideredEmpty)(right)) {
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
} catch (e) {
|
|
430
|
+
return false;
|
|
233
431
|
}
|
|
234
432
|
return (0, import_lite.dequal)(left, right);
|
|
235
433
|
break;
|
|
@@ -264,8 +462,7 @@ var collectTranslationPayload = ({
|
|
|
264
462
|
uniformReleaseId,
|
|
265
463
|
targetLang,
|
|
266
464
|
entity,
|
|
267
|
-
entityType
|
|
268
|
-
overrideModifiedTargetLocale
|
|
465
|
+
entityType
|
|
269
466
|
}) => {
|
|
270
467
|
if (!uniformSourceLocale || !uniformTargetLocale || !targetLang || !entity) {
|
|
271
468
|
return createErrorResult2("invalid-args");
|
|
@@ -285,8 +482,7 @@ var collectTranslationPayload = ({
|
|
|
285
482
|
entity: {
|
|
286
483
|
id: entity._id,
|
|
287
484
|
slug: entity._slug || ""
|
|
288
|
-
}
|
|
289
|
-
overrideModifiedTargetLocale
|
|
485
|
+
}
|
|
290
486
|
},
|
|
291
487
|
components: {}
|
|
292
488
|
};
|
|
@@ -298,7 +494,6 @@ var collectTranslationPayload = ({
|
|
|
298
494
|
const { _id, type, parameters, _overrides } = collectFromNode({
|
|
299
495
|
uniformSourceLocale,
|
|
300
496
|
uniformTargetLocale,
|
|
301
|
-
overrideModifiedTargetLocale,
|
|
302
497
|
node,
|
|
303
498
|
deep: false
|
|
304
499
|
});
|
|
@@ -316,7 +511,6 @@ var collectTranslationPayload = ({
|
|
|
316
511
|
var collectFromNode = ({
|
|
317
512
|
uniformSourceLocale,
|
|
318
513
|
uniformTargetLocale,
|
|
319
|
-
overrideModifiedTargetLocale,
|
|
320
514
|
node,
|
|
321
515
|
deep
|
|
322
516
|
}) => {
|
|
@@ -333,14 +527,14 @@ var collectFromNode = ({
|
|
|
333
527
|
if (!canTranslateParameterValue(param, sourceLocaleValue)) {
|
|
334
528
|
return;
|
|
335
529
|
}
|
|
336
|
-
if (!
|
|
530
|
+
if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
337
531
|
return;
|
|
338
532
|
}
|
|
339
533
|
collectedParameters[paramKey] = {
|
|
340
534
|
type: param.type,
|
|
341
535
|
locales: {
|
|
342
536
|
[TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
|
|
343
|
-
[TRANSLATION_PAYLOAD_TARGET_KEY]: sourceLocaleValue,
|
|
537
|
+
[TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
|
|
344
538
|
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
|
|
345
539
|
}
|
|
346
540
|
};
|
|
@@ -355,7 +549,6 @@ var collectFromNode = ({
|
|
|
355
549
|
const collectedNode = collectFromNode({
|
|
356
550
|
uniformSourceLocale,
|
|
357
551
|
uniformTargetLocale,
|
|
358
|
-
overrideModifiedTargetLocale,
|
|
359
552
|
node: slotComponent,
|
|
360
553
|
deep: true
|
|
361
554
|
});
|
|
@@ -376,7 +569,7 @@ var collectFromNode = ({
|
|
|
376
569
|
if (!canTranslateParameterValue(param, sourceLocaleValue)) {
|
|
377
570
|
return;
|
|
378
571
|
}
|
|
379
|
-
if (!
|
|
572
|
+
if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
380
573
|
return;
|
|
381
574
|
}
|
|
382
575
|
(_c2 = collectedOverrides[overrideKey]) != null ? _c2 : collectedOverrides[overrideKey] = {};
|
|
@@ -385,7 +578,7 @@ var collectFromNode = ({
|
|
|
385
578
|
type: param.type,
|
|
386
579
|
locales: {
|
|
387
580
|
[TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
|
|
388
|
-
[TRANSLATION_PAYLOAD_TARGET_KEY]: sourceLocaleValue,
|
|
581
|
+
[TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
|
|
389
582
|
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
|
|
390
583
|
}
|
|
391
584
|
};
|
|
@@ -399,7 +592,6 @@ var collectFromNode = ({
|
|
|
399
592
|
const collectedNode = collectFromNode({
|
|
400
593
|
uniformSourceLocale,
|
|
401
594
|
uniformTargetLocale,
|
|
402
|
-
overrideModifiedTargetLocale,
|
|
403
595
|
node: slotComponent,
|
|
404
596
|
// keep tree structure for `Slot Sections`
|
|
405
597
|
// to store whole `override` content in scope of current component
|
|
@@ -445,7 +637,7 @@ var canTranslateParameterValue = (parameter, value) => {
|
|
|
445
637
|
}
|
|
446
638
|
return true;
|
|
447
639
|
} else if (parameter.type === SUPPORTED_PARAM_TYPES.richText) {
|
|
448
|
-
return (0,
|
|
640
|
+
return (0, import_richtext4.isRichTextValue)(value) && !(0, import_richtext4.isRichTextValueConsideredEmpty)(value);
|
|
449
641
|
}
|
|
450
642
|
return false;
|
|
451
643
|
};
|
|
@@ -456,7 +648,7 @@ var isTargetLocaleUntouched = (parameterType, sourceLocaleValue, targetLocaleVal
|
|
|
456
648
|
if (parameterType === SUPPORTED_PARAM_TYPES.text && !targetLocaleValue) {
|
|
457
649
|
return true;
|
|
458
650
|
}
|
|
459
|
-
if (parameterType === SUPPORTED_PARAM_TYPES.richText && (0,
|
|
651
|
+
if (parameterType === SUPPORTED_PARAM_TYPES.richText && (0, import_richtext4.isRichTextValueConsideredEmpty)(targetLocaleValue)) {
|
|
460
652
|
return true;
|
|
461
653
|
}
|
|
462
654
|
return isSameParameterValue({
|
|
@@ -465,6 +657,16 @@ var isTargetLocaleUntouched = (parameterType, sourceLocaleValue, targetLocaleVal
|
|
|
465
657
|
right: targetLocaleValue
|
|
466
658
|
});
|
|
467
659
|
};
|
|
660
|
+
var preprocessTargetValue = (parameter, value) => {
|
|
661
|
+
if (parameter.type === SUPPORTED_PARAM_TYPES.richText) {
|
|
662
|
+
try {
|
|
663
|
+
return (0, import_richtext4.isRichTextValue)(value) ? renderAsTranslatableXml(value.root) : value;
|
|
664
|
+
} catch (e) {
|
|
665
|
+
return value;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return value;
|
|
669
|
+
};
|
|
468
670
|
|
|
469
671
|
// src/getCompositionForTranslation.ts
|
|
470
672
|
var import_canvas3 = require("@uniformdev/canvas");
|
|
@@ -524,8 +726,7 @@ var import_canvas5 = require("@uniformdev/canvas");
|
|
|
524
726
|
var import_immer = require("immer");
|
|
525
727
|
var translateComposition = ({
|
|
526
728
|
composition,
|
|
527
|
-
translationPayload
|
|
528
|
-
overrideModifiedTargetLocale
|
|
729
|
+
translationPayload
|
|
529
730
|
}) => {
|
|
530
731
|
var _a;
|
|
531
732
|
if (!composition || !composition.composition || !translationPayload) {
|
|
@@ -567,7 +768,6 @@ var translateComposition = ({
|
|
|
567
768
|
const { updated: isComponentUpdated } = processComponentTranslation({
|
|
568
769
|
uniformSourceLocale,
|
|
569
770
|
uniformTargetLocale,
|
|
570
|
-
overrideModifiedTargetLocale,
|
|
571
771
|
originalNode: component,
|
|
572
772
|
translatedComponent
|
|
573
773
|
});
|
|
@@ -592,7 +792,6 @@ var mergeCompositionTranslationToUniform = async ({
|
|
|
592
792
|
}
|
|
593
793
|
const entityType = translationPayload.metadata.entityType;
|
|
594
794
|
const entityId = translationPayload.metadata.entity.id;
|
|
595
|
-
const overrideModifiedTargetLocale = translationPayload.metadata.overrideModifiedTargetLocale;
|
|
596
795
|
if (entityType !== "composition" && entityType !== "componentPattern") {
|
|
597
796
|
return { translationMerged: false, entityId };
|
|
598
797
|
}
|
|
@@ -608,8 +807,7 @@ var mergeCompositionTranslationToUniform = async ({
|
|
|
608
807
|
}
|
|
609
808
|
const translationResult = translateComposition({
|
|
610
809
|
composition,
|
|
611
|
-
translationPayload
|
|
612
|
-
overrideModifiedTargetLocale
|
|
810
|
+
translationPayload
|
|
613
811
|
});
|
|
614
812
|
const { updated, errorKind, errorText, result: translatedComposition } = translationResult;
|
|
615
813
|
if (translatedComposition && updated && !errorKind) {
|
|
@@ -654,8 +852,7 @@ var import_canvas7 = require("@uniformdev/canvas");
|
|
|
654
852
|
var import_immer2 = require("immer");
|
|
655
853
|
var translateEntry = ({
|
|
656
854
|
entry,
|
|
657
|
-
translationPayload
|
|
658
|
-
overrideModifiedTargetLocale
|
|
855
|
+
translationPayload
|
|
659
856
|
}) => {
|
|
660
857
|
var _a;
|
|
661
858
|
if (!entry || !translationPayload) {
|
|
@@ -697,7 +894,6 @@ var translateEntry = ({
|
|
|
697
894
|
const { updated: isComponentUpdated } = processComponentTranslation({
|
|
698
895
|
uniformSourceLocale,
|
|
699
896
|
uniformTargetLocale,
|
|
700
|
-
overrideModifiedTargetLocale,
|
|
701
897
|
originalNode: component,
|
|
702
898
|
translatedComponent
|
|
703
899
|
});
|
|
@@ -722,7 +918,6 @@ var mergeEntryTranslationToUniform = async ({
|
|
|
722
918
|
}
|
|
723
919
|
const entityType = translationPayload.metadata.entityType;
|
|
724
920
|
const entityId = translationPayload.metadata.entity.id;
|
|
725
|
-
const overrideModifiedTargetLocale = translationPayload.metadata.overrideModifiedTargetLocale;
|
|
726
921
|
if (entityType !== "entry" && entityType !== "entryPattern") {
|
|
727
922
|
return { translationMerged: false, entityId };
|
|
728
923
|
}
|
|
@@ -738,8 +933,7 @@ var mergeEntryTranslationToUniform = async ({
|
|
|
738
933
|
}
|
|
739
934
|
const translationResult = translateEntry({
|
|
740
935
|
entry,
|
|
741
|
-
translationPayload
|
|
742
|
-
overrideModifiedTargetLocale
|
|
936
|
+
translationPayload
|
|
743
937
|
});
|
|
744
938
|
const { updated, errorKind, errorText, result: translatedEntry } = translationResult;
|
|
745
939
|
if (translatedEntry && updated && !errorKind) {
|