@uniformdev/tms-sdk 20.50.2-alpha.1 → 20.50.2-alpha.117
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 +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.esm.js +134 -16
- package/dist/index.js +132 -16
- package/dist/index.mjs +134 -16
- package/package.json +7 -8
package/dist/index.d.mts
CHANGED
|
@@ -29,13 +29,20 @@ type EntityTranslationResult<TResult = unknown> = {
|
|
|
29
29
|
errorText?: string;
|
|
30
30
|
};
|
|
31
31
|
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>;
|
|
32
|
+
type CollectTranslationConfig = {
|
|
33
|
+
/**
|
|
34
|
+
* By default, if target locale value exists and different from source locale value, it will be skipped for translation.
|
|
35
|
+
* If `true`, target locale value mismatch will be ignored.
|
|
36
|
+
*/
|
|
37
|
+
ignoreTargetLocaleValueMismatch?: boolean;
|
|
38
|
+
};
|
|
32
39
|
|
|
33
40
|
type CollectTranslationPayloadResult = {
|
|
34
41
|
payload?: TranslationPayload;
|
|
35
42
|
errorKind?: 'unknown' | 'invalid-args' | 'entity-source-locale-missing';
|
|
36
43
|
errorText?: string;
|
|
37
44
|
};
|
|
38
|
-
declare const collectTranslationPayload: ({ uniformProjectId, uniformSourceLocale, uniformTargetLocale, uniformReleaseId, targetLang, entity, entityType, }: {
|
|
45
|
+
declare const collectTranslationPayload: ({ uniformProjectId, uniformSourceLocale, uniformTargetLocale, uniformReleaseId, targetLang, entity, entityType, config, }: {
|
|
39
46
|
uniformProjectId: string;
|
|
40
47
|
uniformSourceLocale: string;
|
|
41
48
|
uniformTargetLocale: string;
|
|
@@ -43,6 +50,7 @@ declare const collectTranslationPayload: ({ uniformProjectId, uniformSourceLocal
|
|
|
43
50
|
targetLang: string;
|
|
44
51
|
entity: RootComponentInstance | EntryData;
|
|
45
52
|
entityType: EntityType;
|
|
53
|
+
config?: CollectTranslationConfig;
|
|
46
54
|
}) => CollectTranslationPayloadResult;
|
|
47
55
|
|
|
48
56
|
declare const getCompositionForTranslation: ({ canvasClient, compositionId, releaseId, state, }: {
|
|
@@ -118,4 +126,4 @@ declare const translateEntry: ({ entry, translationPayload, }: {
|
|
|
118
126
|
translationPayload: TranslationPayload;
|
|
119
127
|
}) => EntityTranslationResult<Entry>;
|
|
120
128
|
|
|
121
|
-
export { type CollectTranslationPayloadResult, type ComponentTranslationPayload, type EntityTranslationResult, type EntityType, type MaybePromise, type MergeCompositionTranslationToUniformOptions, type MergeEntryTranslationToUniformOptions, type MergeTranslationToUniformOptions, type TranslationPayload, collectTranslationPayload, getCompositionForTranslation, getEntryForTranslation, mergeCompositionTranslationToUniform, mergeEntryTranslationToUniform, mergeTranslationToUniform, translateComposition, translateEntry };
|
|
129
|
+
export { type CollectTranslationConfig, type CollectTranslationPayloadResult, type ComponentTranslationPayload, type EntityTranslationResult, type EntityType, type MaybePromise, type MergeCompositionTranslationToUniformOptions, type MergeEntryTranslationToUniformOptions, type MergeTranslationToUniformOptions, type TranslationPayload, collectTranslationPayload, getCompositionForTranslation, getEntryForTranslation, mergeCompositionTranslationToUniform, mergeEntryTranslationToUniform, mergeTranslationToUniform, translateComposition, translateEntry };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,13 +29,20 @@ type EntityTranslationResult<TResult = unknown> = {
|
|
|
29
29
|
errorText?: string;
|
|
30
30
|
};
|
|
31
31
|
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>;
|
|
32
|
+
type CollectTranslationConfig = {
|
|
33
|
+
/**
|
|
34
|
+
* By default, if target locale value exists and different from source locale value, it will be skipped for translation.
|
|
35
|
+
* If `true`, target locale value mismatch will be ignored.
|
|
36
|
+
*/
|
|
37
|
+
ignoreTargetLocaleValueMismatch?: boolean;
|
|
38
|
+
};
|
|
32
39
|
|
|
33
40
|
type CollectTranslationPayloadResult = {
|
|
34
41
|
payload?: TranslationPayload;
|
|
35
42
|
errorKind?: 'unknown' | 'invalid-args' | 'entity-source-locale-missing';
|
|
36
43
|
errorText?: string;
|
|
37
44
|
};
|
|
38
|
-
declare const collectTranslationPayload: ({ uniformProjectId, uniformSourceLocale, uniformTargetLocale, uniformReleaseId, targetLang, entity, entityType, }: {
|
|
45
|
+
declare const collectTranslationPayload: ({ uniformProjectId, uniformSourceLocale, uniformTargetLocale, uniformReleaseId, targetLang, entity, entityType, config, }: {
|
|
39
46
|
uniformProjectId: string;
|
|
40
47
|
uniformSourceLocale: string;
|
|
41
48
|
uniformTargetLocale: string;
|
|
@@ -43,6 +50,7 @@ declare const collectTranslationPayload: ({ uniformProjectId, uniformSourceLocal
|
|
|
43
50
|
targetLang: string;
|
|
44
51
|
entity: RootComponentInstance | EntryData;
|
|
45
52
|
entityType: EntityType;
|
|
53
|
+
config?: CollectTranslationConfig;
|
|
46
54
|
}) => CollectTranslationPayloadResult;
|
|
47
55
|
|
|
48
56
|
declare const getCompositionForTranslation: ({ canvasClient, compositionId, releaseId, state, }: {
|
|
@@ -118,4 +126,4 @@ declare const translateEntry: ({ entry, translationPayload, }: {
|
|
|
118
126
|
translationPayload: TranslationPayload;
|
|
119
127
|
}) => EntityTranslationResult<Entry>;
|
|
120
128
|
|
|
121
|
-
export { type CollectTranslationPayloadResult, type ComponentTranslationPayload, type EntityTranslationResult, type EntityType, type MaybePromise, type MergeCompositionTranslationToUniformOptions, type MergeEntryTranslationToUniformOptions, type MergeTranslationToUniformOptions, type TranslationPayload, collectTranslationPayload, getCompositionForTranslation, getEntryForTranslation, mergeCompositionTranslationToUniform, mergeEntryTranslationToUniform, mergeTranslationToUniform, translateComposition, translateEntry };
|
|
129
|
+
export { type CollectTranslationConfig, type CollectTranslationPayloadResult, type ComponentTranslationPayload, type EntityTranslationResult, type EntityType, type MaybePromise, type MergeCompositionTranslationToUniformOptions, type MergeEntryTranslationToUniformOptions, type MergeTranslationToUniformOptions, type TranslationPayload, collectTranslationPayload, getCompositionForTranslation, getEntryForTranslation, mergeCompositionTranslationToUniform, mergeEntryTranslationToUniform, mergeTranslationToUniform, translateComposition, translateEntry };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/collectTranslationPayload.ts
|
|
2
2
|
import {
|
|
3
3
|
bindVariables,
|
|
4
|
+
CANVAS_BLOCK_PARAM_TYPE as CANVAS_BLOCK_PARAM_TYPE2,
|
|
4
5
|
walkNodeTree as walkNodeTree2
|
|
5
6
|
} from "@uniformdev/canvas";
|
|
6
7
|
import { isRichTextValue as isRichTextValue2, isRichTextValueConsideredEmpty as isRichTextValueConsideredEmpty2 } from "@uniformdev/richtext";
|
|
@@ -109,6 +110,7 @@ var getNodeMetaAttributesString = (node) => {
|
|
|
109
110
|
|
|
110
111
|
// src/translationHelpers.ts
|
|
111
112
|
import {
|
|
113
|
+
CANVAS_BLOCK_PARAM_TYPE,
|
|
112
114
|
walkNodeTree
|
|
113
115
|
} from "@uniformdev/canvas";
|
|
114
116
|
import { isRichTextValueConsideredEmpty } from "@uniformdev/richtext";
|
|
@@ -287,6 +289,9 @@ var processComponentTranslation = ({
|
|
|
287
289
|
});
|
|
288
290
|
return { updated };
|
|
289
291
|
};
|
|
292
|
+
var isNestedParameterType = (type) => {
|
|
293
|
+
return type === CANVAS_BLOCK_PARAM_TYPE;
|
|
294
|
+
};
|
|
290
295
|
var processParameterTranslation = ({
|
|
291
296
|
uniformSourceLocale,
|
|
292
297
|
uniformTargetLocale,
|
|
@@ -297,6 +302,14 @@ var processParameterTranslation = ({
|
|
|
297
302
|
if (originalParameter.type !== parameter.type) {
|
|
298
303
|
return { updated: false };
|
|
299
304
|
}
|
|
305
|
+
if (isNestedParameterType(originalParameter.type)) {
|
|
306
|
+
return processNestedParameterTranslation({
|
|
307
|
+
uniformSourceLocale,
|
|
308
|
+
uniformTargetLocale,
|
|
309
|
+
originalParameter,
|
|
310
|
+
parameter
|
|
311
|
+
});
|
|
312
|
+
}
|
|
300
313
|
if (!originalParameter.locales && originalParameter.value === void 0) {
|
|
301
314
|
return { updated: false };
|
|
302
315
|
}
|
|
@@ -309,7 +322,7 @@ var processParameterTranslation = ({
|
|
|
309
322
|
left: originalParameterSource,
|
|
310
323
|
right: sourceValue
|
|
311
324
|
});
|
|
312
|
-
const isTargetValueUntouched = isSameParameterValue({
|
|
325
|
+
const isTargetValueUntouched = originalTargetValue === void 0 ? true : isSameParameterValue({
|
|
313
326
|
parameterType: originalParameter.type,
|
|
314
327
|
left: (_d = originalParameter.locales) == null ? void 0 : _d[uniformTargetLocale],
|
|
315
328
|
right: originalTargetValue
|
|
@@ -341,6 +354,39 @@ var processParameterTranslation = ({
|
|
|
341
354
|
}
|
|
342
355
|
return { updated: false };
|
|
343
356
|
};
|
|
357
|
+
var processNestedParameterTranslation = ({
|
|
358
|
+
uniformSourceLocale,
|
|
359
|
+
uniformTargetLocale,
|
|
360
|
+
originalParameter,
|
|
361
|
+
parameter
|
|
362
|
+
}) => {
|
|
363
|
+
let updated = false;
|
|
364
|
+
if (originalParameter.type == CANVAS_BLOCK_PARAM_TYPE && Array.isArray(originalParameter.value) && Array.isArray(parameter.value)) {
|
|
365
|
+
const originalValue = originalParameter.value;
|
|
366
|
+
const translatedValue = parameter.value;
|
|
367
|
+
for (const translatedBlock of translatedValue) {
|
|
368
|
+
if (!translatedBlock._id || !translatedBlock.type) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
const originalBlock = originalValue.find(
|
|
372
|
+
(b) => b._id === translatedBlock._id && b.type === translatedBlock.type
|
|
373
|
+
);
|
|
374
|
+
if (!originalBlock) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const { updated: blockUpdated } = processComponentTranslation({
|
|
378
|
+
uniformSourceLocale,
|
|
379
|
+
uniformTargetLocale,
|
|
380
|
+
originalNode: originalBlock,
|
|
381
|
+
translatedComponent: translatedBlock
|
|
382
|
+
});
|
|
383
|
+
if (blockUpdated) {
|
|
384
|
+
updated = true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return { updated };
|
|
389
|
+
};
|
|
344
390
|
var processOverrideTranslation = ({
|
|
345
391
|
uniformSourceLocale,
|
|
346
392
|
uniformTargetLocale,
|
|
@@ -453,7 +499,8 @@ var collectTranslationPayload = ({
|
|
|
453
499
|
uniformReleaseId,
|
|
454
500
|
targetLang,
|
|
455
501
|
entity,
|
|
456
|
-
entityType
|
|
502
|
+
entityType,
|
|
503
|
+
config = {}
|
|
457
504
|
}) => {
|
|
458
505
|
if (!uniformSourceLocale || !uniformTargetLocale || !targetLang || !entity) {
|
|
459
506
|
return createErrorResult2("invalid-args");
|
|
@@ -477,16 +524,22 @@ var collectTranslationPayload = ({
|
|
|
477
524
|
},
|
|
478
525
|
components: {}
|
|
479
526
|
};
|
|
480
|
-
walkNodeTree2(entity, ({ node, actions }) => {
|
|
527
|
+
walkNodeTree2(entity, ({ node, actions, ancestorsAndSelf }) => {
|
|
528
|
+
var _a;
|
|
481
529
|
if (!node.type || !node._id) {
|
|
482
530
|
actions.stopProcessingDescendants();
|
|
483
531
|
return;
|
|
484
532
|
}
|
|
533
|
+
if (((_a = ancestorsAndSelf.at(0)) == null ? void 0 : _a.type) === "block") {
|
|
534
|
+
actions.stopProcessingDescendants();
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
485
537
|
const { _id, type, parameters, _overrides } = collectFromNode({
|
|
486
538
|
uniformSourceLocale,
|
|
487
539
|
uniformTargetLocale,
|
|
488
540
|
node,
|
|
489
|
-
deep: false
|
|
541
|
+
deep: false,
|
|
542
|
+
config
|
|
490
543
|
});
|
|
491
544
|
if (parameters || _overrides) {
|
|
492
545
|
payload.components[node._id] = {
|
|
@@ -503,7 +556,8 @@ var collectFromNode = ({
|
|
|
503
556
|
uniformSourceLocale,
|
|
504
557
|
uniformTargetLocale,
|
|
505
558
|
node,
|
|
506
|
-
deep
|
|
559
|
+
deep,
|
|
560
|
+
config
|
|
507
561
|
}) => {
|
|
508
562
|
var _a, _b, _c;
|
|
509
563
|
const collectedParameters = {};
|
|
@@ -513,12 +567,24 @@ var collectFromNode = ({
|
|
|
513
567
|
const entryFields = "fields" in node ? node.fields : void 0;
|
|
514
568
|
Object.entries((_a = componentParameters != null ? componentParameters : entryFields) != null ? _a : {}).forEach(([paramKey, param]) => {
|
|
515
569
|
var _a2, _b2;
|
|
570
|
+
if (isNestedParameterType(param.type)) {
|
|
571
|
+
const nestedParam = collectNestedParameter({
|
|
572
|
+
param,
|
|
573
|
+
uniformSourceLocale,
|
|
574
|
+
uniformTargetLocale,
|
|
575
|
+
config
|
|
576
|
+
});
|
|
577
|
+
if (nestedParam) {
|
|
578
|
+
collectedParameters[paramKey] = nestedParam;
|
|
579
|
+
}
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
516
582
|
const sourceLocaleValue = (_a2 = param.locales) == null ? void 0 : _a2[uniformSourceLocale];
|
|
517
583
|
const targetLocaleValue = (_b2 = param.locales) == null ? void 0 : _b2[uniformTargetLocale];
|
|
518
584
|
if (!canTranslateParameterValue(param, sourceLocaleValue)) {
|
|
519
585
|
return;
|
|
520
586
|
}
|
|
521
|
-
if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
587
|
+
if (!config.ignoreTargetLocaleValueMismatch && !isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
522
588
|
return;
|
|
523
589
|
}
|
|
524
590
|
collectedParameters[paramKey] = {
|
|
@@ -526,7 +592,7 @@ var collectFromNode = ({
|
|
|
526
592
|
locales: {
|
|
527
593
|
[TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
|
|
528
594
|
[TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
|
|
529
|
-
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
|
|
595
|
+
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: !config.ignoreTargetLocaleValueMismatch ? targetLocaleValue : void 0
|
|
530
596
|
}
|
|
531
597
|
};
|
|
532
598
|
});
|
|
@@ -541,7 +607,8 @@ var collectFromNode = ({
|
|
|
541
607
|
uniformSourceLocale,
|
|
542
608
|
uniformTargetLocale,
|
|
543
609
|
node: slotComponent,
|
|
544
|
-
deep: true
|
|
610
|
+
deep: true,
|
|
611
|
+
config
|
|
545
612
|
});
|
|
546
613
|
const hasContent = collectedNode.parameters || collectedNode._overrides || collectedNode.slots;
|
|
547
614
|
if (hasContent) {
|
|
@@ -554,23 +621,37 @@ var collectFromNode = ({
|
|
|
554
621
|
Object.entries((_c = node._overrides) != null ? _c : {}).forEach(([overrideKey, override]) => {
|
|
555
622
|
var _a2, _b2;
|
|
556
623
|
Object.entries((_a2 = override.parameters) != null ? _a2 : {}).forEach(([paramKey, param]) => {
|
|
557
|
-
var _a3, _b3, _c2, _d, _e;
|
|
558
|
-
|
|
559
|
-
|
|
624
|
+
var _a3, _b3, _c2, _d, _e, _f, _g, _h;
|
|
625
|
+
if (isNestedParameterType(param.type)) {
|
|
626
|
+
const nestedParam = collectNestedParameter({
|
|
627
|
+
param,
|
|
628
|
+
uniformSourceLocale,
|
|
629
|
+
uniformTargetLocale,
|
|
630
|
+
config
|
|
631
|
+
});
|
|
632
|
+
if (nestedParam) {
|
|
633
|
+
(_a3 = collectedOverrides[overrideKey]) != null ? _a3 : collectedOverrides[overrideKey] = {};
|
|
634
|
+
(_c2 = (_b3 = collectedOverrides[overrideKey]).parameters) != null ? _c2 : _b3.parameters = {};
|
|
635
|
+
collectedOverrides[overrideKey].parameters[paramKey] = nestedParam;
|
|
636
|
+
}
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
const sourceLocaleValue = (_d = param.locales) == null ? void 0 : _d[uniformSourceLocale];
|
|
640
|
+
const targetLocaleValue = (_e = param.locales) == null ? void 0 : _e[uniformTargetLocale];
|
|
560
641
|
if (!canTranslateParameterValue(param, sourceLocaleValue)) {
|
|
561
642
|
return;
|
|
562
643
|
}
|
|
563
|
-
if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
644
|
+
if (!config.ignoreTargetLocaleValueMismatch && !isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
564
645
|
return;
|
|
565
646
|
}
|
|
566
|
-
(
|
|
567
|
-
(
|
|
647
|
+
(_f = collectedOverrides[overrideKey]) != null ? _f : collectedOverrides[overrideKey] = {};
|
|
648
|
+
(_h = (_g = collectedOverrides[overrideKey]).parameters) != null ? _h : _g.parameters = {};
|
|
568
649
|
collectedOverrides[overrideKey].parameters[paramKey] = {
|
|
569
650
|
type: param.type,
|
|
570
651
|
locales: {
|
|
571
652
|
[TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
|
|
572
653
|
[TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
|
|
573
|
-
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
|
|
654
|
+
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: !config.ignoreTargetLocaleValueMismatch ? targetLocaleValue : void 0
|
|
574
655
|
}
|
|
575
656
|
};
|
|
576
657
|
});
|
|
@@ -586,7 +667,8 @@ var collectFromNode = ({
|
|
|
586
667
|
node: slotComponent,
|
|
587
668
|
// keep tree structure for `Slot Sections`
|
|
588
669
|
// to store whole `override` content in scope of current component
|
|
589
|
-
deep: true
|
|
670
|
+
deep: true,
|
|
671
|
+
config
|
|
590
672
|
});
|
|
591
673
|
const hasContent = collectedNode.parameters || collectedNode._overrides || collectedNode.slots;
|
|
592
674
|
if (hasContent) {
|
|
@@ -609,6 +691,42 @@ var collectFromNode = ({
|
|
|
609
691
|
_overrides: hasOverrides ? collectedOverrides : void 0
|
|
610
692
|
};
|
|
611
693
|
};
|
|
694
|
+
var collectNestedParameter = ({
|
|
695
|
+
param,
|
|
696
|
+
uniformSourceLocale,
|
|
697
|
+
uniformTargetLocale,
|
|
698
|
+
config
|
|
699
|
+
}) => {
|
|
700
|
+
if (param.type === CANVAS_BLOCK_PARAM_TYPE2 && Array.isArray(param.value)) {
|
|
701
|
+
const blockValue = param.value;
|
|
702
|
+
const collectedBlocks = [];
|
|
703
|
+
for (const blockEntry of blockValue) {
|
|
704
|
+
if (!blockEntry._id || !blockEntry.type) {
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
const collectedNode = collectFromNode({
|
|
708
|
+
uniformSourceLocale,
|
|
709
|
+
uniformTargetLocale,
|
|
710
|
+
node: blockEntry,
|
|
711
|
+
deep: false,
|
|
712
|
+
config
|
|
713
|
+
});
|
|
714
|
+
const hasContent = collectedNode.parameters || collectedNode._overrides;
|
|
715
|
+
if (hasContent) {
|
|
716
|
+
collectedNode.slots = void 0;
|
|
717
|
+
collectedBlocks.push(collectedNode);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (collectedBlocks.length === 0) {
|
|
721
|
+
return void 0;
|
|
722
|
+
}
|
|
723
|
+
return {
|
|
724
|
+
type: CANVAS_BLOCK_PARAM_TYPE2,
|
|
725
|
+
value: collectedBlocks
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
return void 0;
|
|
729
|
+
};
|
|
612
730
|
var canTranslateParameterValue = (parameter, value) => {
|
|
613
731
|
if (parameter.type === SUPPORTED_PARAM_TYPES.text) {
|
|
614
732
|
if (typeof value !== "string" || !value) {
|
package/dist/index.js
CHANGED
|
@@ -315,6 +315,9 @@ var processComponentTranslation = ({
|
|
|
315
315
|
});
|
|
316
316
|
return { updated };
|
|
317
317
|
};
|
|
318
|
+
var isNestedParameterType = (type) => {
|
|
319
|
+
return type === import_canvas.CANVAS_BLOCK_PARAM_TYPE;
|
|
320
|
+
};
|
|
318
321
|
var processParameterTranslation = ({
|
|
319
322
|
uniformSourceLocale,
|
|
320
323
|
uniformTargetLocale,
|
|
@@ -325,6 +328,14 @@ var processParameterTranslation = ({
|
|
|
325
328
|
if (originalParameter.type !== parameter.type) {
|
|
326
329
|
return { updated: false };
|
|
327
330
|
}
|
|
331
|
+
if (isNestedParameterType(originalParameter.type)) {
|
|
332
|
+
return processNestedParameterTranslation({
|
|
333
|
+
uniformSourceLocale,
|
|
334
|
+
uniformTargetLocale,
|
|
335
|
+
originalParameter,
|
|
336
|
+
parameter
|
|
337
|
+
});
|
|
338
|
+
}
|
|
328
339
|
if (!originalParameter.locales && originalParameter.value === void 0) {
|
|
329
340
|
return { updated: false };
|
|
330
341
|
}
|
|
@@ -337,7 +348,7 @@ var processParameterTranslation = ({
|
|
|
337
348
|
left: originalParameterSource,
|
|
338
349
|
right: sourceValue
|
|
339
350
|
});
|
|
340
|
-
const isTargetValueUntouched = isSameParameterValue({
|
|
351
|
+
const isTargetValueUntouched = originalTargetValue === void 0 ? true : isSameParameterValue({
|
|
341
352
|
parameterType: originalParameter.type,
|
|
342
353
|
left: (_d = originalParameter.locales) == null ? void 0 : _d[uniformTargetLocale],
|
|
343
354
|
right: originalTargetValue
|
|
@@ -369,6 +380,39 @@ var processParameterTranslation = ({
|
|
|
369
380
|
}
|
|
370
381
|
return { updated: false };
|
|
371
382
|
};
|
|
383
|
+
var processNestedParameterTranslation = ({
|
|
384
|
+
uniformSourceLocale,
|
|
385
|
+
uniformTargetLocale,
|
|
386
|
+
originalParameter,
|
|
387
|
+
parameter
|
|
388
|
+
}) => {
|
|
389
|
+
let updated = false;
|
|
390
|
+
if (originalParameter.type == import_canvas.CANVAS_BLOCK_PARAM_TYPE && Array.isArray(originalParameter.value) && Array.isArray(parameter.value)) {
|
|
391
|
+
const originalValue = originalParameter.value;
|
|
392
|
+
const translatedValue = parameter.value;
|
|
393
|
+
for (const translatedBlock of translatedValue) {
|
|
394
|
+
if (!translatedBlock._id || !translatedBlock.type) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const originalBlock = originalValue.find(
|
|
398
|
+
(b) => b._id === translatedBlock._id && b.type === translatedBlock.type
|
|
399
|
+
);
|
|
400
|
+
if (!originalBlock) {
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
const { updated: blockUpdated } = processComponentTranslation({
|
|
404
|
+
uniformSourceLocale,
|
|
405
|
+
uniformTargetLocale,
|
|
406
|
+
originalNode: originalBlock,
|
|
407
|
+
translatedComponent: translatedBlock
|
|
408
|
+
});
|
|
409
|
+
if (blockUpdated) {
|
|
410
|
+
updated = true;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return { updated };
|
|
415
|
+
};
|
|
372
416
|
var processOverrideTranslation = ({
|
|
373
417
|
uniformSourceLocale,
|
|
374
418
|
uniformTargetLocale,
|
|
@@ -481,7 +525,8 @@ var collectTranslationPayload = ({
|
|
|
481
525
|
uniformReleaseId,
|
|
482
526
|
targetLang,
|
|
483
527
|
entity,
|
|
484
|
-
entityType
|
|
528
|
+
entityType,
|
|
529
|
+
config = {}
|
|
485
530
|
}) => {
|
|
486
531
|
if (!uniformSourceLocale || !uniformTargetLocale || !targetLang || !entity) {
|
|
487
532
|
return createErrorResult2("invalid-args");
|
|
@@ -505,16 +550,22 @@ var collectTranslationPayload = ({
|
|
|
505
550
|
},
|
|
506
551
|
components: {}
|
|
507
552
|
};
|
|
508
|
-
(0, import_canvas2.walkNodeTree)(entity, ({ node, actions }) => {
|
|
553
|
+
(0, import_canvas2.walkNodeTree)(entity, ({ node, actions, ancestorsAndSelf }) => {
|
|
554
|
+
var _a;
|
|
509
555
|
if (!node.type || !node._id) {
|
|
510
556
|
actions.stopProcessingDescendants();
|
|
511
557
|
return;
|
|
512
558
|
}
|
|
559
|
+
if (((_a = ancestorsAndSelf.at(0)) == null ? void 0 : _a.type) === "block") {
|
|
560
|
+
actions.stopProcessingDescendants();
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
513
563
|
const { _id, type, parameters, _overrides } = collectFromNode({
|
|
514
564
|
uniformSourceLocale,
|
|
515
565
|
uniformTargetLocale,
|
|
516
566
|
node,
|
|
517
|
-
deep: false
|
|
567
|
+
deep: false,
|
|
568
|
+
config
|
|
518
569
|
});
|
|
519
570
|
if (parameters || _overrides) {
|
|
520
571
|
payload.components[node._id] = {
|
|
@@ -531,7 +582,8 @@ var collectFromNode = ({
|
|
|
531
582
|
uniformSourceLocale,
|
|
532
583
|
uniformTargetLocale,
|
|
533
584
|
node,
|
|
534
|
-
deep
|
|
585
|
+
deep,
|
|
586
|
+
config
|
|
535
587
|
}) => {
|
|
536
588
|
var _a, _b, _c;
|
|
537
589
|
const collectedParameters = {};
|
|
@@ -541,12 +593,24 @@ var collectFromNode = ({
|
|
|
541
593
|
const entryFields = "fields" in node ? node.fields : void 0;
|
|
542
594
|
Object.entries((_a = componentParameters != null ? componentParameters : entryFields) != null ? _a : {}).forEach(([paramKey, param]) => {
|
|
543
595
|
var _a2, _b2;
|
|
596
|
+
if (isNestedParameterType(param.type)) {
|
|
597
|
+
const nestedParam = collectNestedParameter({
|
|
598
|
+
param,
|
|
599
|
+
uniformSourceLocale,
|
|
600
|
+
uniformTargetLocale,
|
|
601
|
+
config
|
|
602
|
+
});
|
|
603
|
+
if (nestedParam) {
|
|
604
|
+
collectedParameters[paramKey] = nestedParam;
|
|
605
|
+
}
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
544
608
|
const sourceLocaleValue = (_a2 = param.locales) == null ? void 0 : _a2[uniformSourceLocale];
|
|
545
609
|
const targetLocaleValue = (_b2 = param.locales) == null ? void 0 : _b2[uniformTargetLocale];
|
|
546
610
|
if (!canTranslateParameterValue(param, sourceLocaleValue)) {
|
|
547
611
|
return;
|
|
548
612
|
}
|
|
549
|
-
if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
613
|
+
if (!config.ignoreTargetLocaleValueMismatch && !isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
550
614
|
return;
|
|
551
615
|
}
|
|
552
616
|
collectedParameters[paramKey] = {
|
|
@@ -554,7 +618,7 @@ var collectFromNode = ({
|
|
|
554
618
|
locales: {
|
|
555
619
|
[TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
|
|
556
620
|
[TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
|
|
557
|
-
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
|
|
621
|
+
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: !config.ignoreTargetLocaleValueMismatch ? targetLocaleValue : void 0
|
|
558
622
|
}
|
|
559
623
|
};
|
|
560
624
|
});
|
|
@@ -569,7 +633,8 @@ var collectFromNode = ({
|
|
|
569
633
|
uniformSourceLocale,
|
|
570
634
|
uniformTargetLocale,
|
|
571
635
|
node: slotComponent,
|
|
572
|
-
deep: true
|
|
636
|
+
deep: true,
|
|
637
|
+
config
|
|
573
638
|
});
|
|
574
639
|
const hasContent = collectedNode.parameters || collectedNode._overrides || collectedNode.slots;
|
|
575
640
|
if (hasContent) {
|
|
@@ -582,23 +647,37 @@ var collectFromNode = ({
|
|
|
582
647
|
Object.entries((_c = node._overrides) != null ? _c : {}).forEach(([overrideKey, override]) => {
|
|
583
648
|
var _a2, _b2;
|
|
584
649
|
Object.entries((_a2 = override.parameters) != null ? _a2 : {}).forEach(([paramKey, param]) => {
|
|
585
|
-
var _a3, _b3, _c2, _d, _e;
|
|
586
|
-
|
|
587
|
-
|
|
650
|
+
var _a3, _b3, _c2, _d, _e, _f, _g, _h;
|
|
651
|
+
if (isNestedParameterType(param.type)) {
|
|
652
|
+
const nestedParam = collectNestedParameter({
|
|
653
|
+
param,
|
|
654
|
+
uniformSourceLocale,
|
|
655
|
+
uniformTargetLocale,
|
|
656
|
+
config
|
|
657
|
+
});
|
|
658
|
+
if (nestedParam) {
|
|
659
|
+
(_a3 = collectedOverrides[overrideKey]) != null ? _a3 : collectedOverrides[overrideKey] = {};
|
|
660
|
+
(_c2 = (_b3 = collectedOverrides[overrideKey]).parameters) != null ? _c2 : _b3.parameters = {};
|
|
661
|
+
collectedOverrides[overrideKey].parameters[paramKey] = nestedParam;
|
|
662
|
+
}
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
const sourceLocaleValue = (_d = param.locales) == null ? void 0 : _d[uniformSourceLocale];
|
|
666
|
+
const targetLocaleValue = (_e = param.locales) == null ? void 0 : _e[uniformTargetLocale];
|
|
588
667
|
if (!canTranslateParameterValue(param, sourceLocaleValue)) {
|
|
589
668
|
return;
|
|
590
669
|
}
|
|
591
|
-
if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
670
|
+
if (!config.ignoreTargetLocaleValueMismatch && !isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
592
671
|
return;
|
|
593
672
|
}
|
|
594
|
-
(
|
|
595
|
-
(
|
|
673
|
+
(_f = collectedOverrides[overrideKey]) != null ? _f : collectedOverrides[overrideKey] = {};
|
|
674
|
+
(_h = (_g = collectedOverrides[overrideKey]).parameters) != null ? _h : _g.parameters = {};
|
|
596
675
|
collectedOverrides[overrideKey].parameters[paramKey] = {
|
|
597
676
|
type: param.type,
|
|
598
677
|
locales: {
|
|
599
678
|
[TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
|
|
600
679
|
[TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
|
|
601
|
-
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
|
|
680
|
+
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: !config.ignoreTargetLocaleValueMismatch ? targetLocaleValue : void 0
|
|
602
681
|
}
|
|
603
682
|
};
|
|
604
683
|
});
|
|
@@ -614,7 +693,8 @@ var collectFromNode = ({
|
|
|
614
693
|
node: slotComponent,
|
|
615
694
|
// keep tree structure for `Slot Sections`
|
|
616
695
|
// to store whole `override` content in scope of current component
|
|
617
|
-
deep: true
|
|
696
|
+
deep: true,
|
|
697
|
+
config
|
|
618
698
|
});
|
|
619
699
|
const hasContent = collectedNode.parameters || collectedNode._overrides || collectedNode.slots;
|
|
620
700
|
if (hasContent) {
|
|
@@ -637,6 +717,42 @@ var collectFromNode = ({
|
|
|
637
717
|
_overrides: hasOverrides ? collectedOverrides : void 0
|
|
638
718
|
};
|
|
639
719
|
};
|
|
720
|
+
var collectNestedParameter = ({
|
|
721
|
+
param,
|
|
722
|
+
uniformSourceLocale,
|
|
723
|
+
uniformTargetLocale,
|
|
724
|
+
config
|
|
725
|
+
}) => {
|
|
726
|
+
if (param.type === import_canvas2.CANVAS_BLOCK_PARAM_TYPE && Array.isArray(param.value)) {
|
|
727
|
+
const blockValue = param.value;
|
|
728
|
+
const collectedBlocks = [];
|
|
729
|
+
for (const blockEntry of blockValue) {
|
|
730
|
+
if (!blockEntry._id || !blockEntry.type) {
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
const collectedNode = collectFromNode({
|
|
734
|
+
uniformSourceLocale,
|
|
735
|
+
uniformTargetLocale,
|
|
736
|
+
node: blockEntry,
|
|
737
|
+
deep: false,
|
|
738
|
+
config
|
|
739
|
+
});
|
|
740
|
+
const hasContent = collectedNode.parameters || collectedNode._overrides;
|
|
741
|
+
if (hasContent) {
|
|
742
|
+
collectedNode.slots = void 0;
|
|
743
|
+
collectedBlocks.push(collectedNode);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (collectedBlocks.length === 0) {
|
|
747
|
+
return void 0;
|
|
748
|
+
}
|
|
749
|
+
return {
|
|
750
|
+
type: import_canvas2.CANVAS_BLOCK_PARAM_TYPE,
|
|
751
|
+
value: collectedBlocks
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
return void 0;
|
|
755
|
+
};
|
|
640
756
|
var canTranslateParameterValue = (parameter, value) => {
|
|
641
757
|
if (parameter.type === SUPPORTED_PARAM_TYPES.text) {
|
|
642
758
|
if (typeof value !== "string" || !value) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/collectTranslationPayload.ts
|
|
2
2
|
import {
|
|
3
3
|
bindVariables,
|
|
4
|
+
CANVAS_BLOCK_PARAM_TYPE as CANVAS_BLOCK_PARAM_TYPE2,
|
|
4
5
|
walkNodeTree as walkNodeTree2
|
|
5
6
|
} from "@uniformdev/canvas";
|
|
6
7
|
import { isRichTextValue as isRichTextValue2, isRichTextValueConsideredEmpty as isRichTextValueConsideredEmpty2 } from "@uniformdev/richtext";
|
|
@@ -109,6 +110,7 @@ var getNodeMetaAttributesString = (node) => {
|
|
|
109
110
|
|
|
110
111
|
// src/translationHelpers.ts
|
|
111
112
|
import {
|
|
113
|
+
CANVAS_BLOCK_PARAM_TYPE,
|
|
112
114
|
walkNodeTree
|
|
113
115
|
} from "@uniformdev/canvas";
|
|
114
116
|
import { isRichTextValueConsideredEmpty } from "@uniformdev/richtext";
|
|
@@ -287,6 +289,9 @@ var processComponentTranslation = ({
|
|
|
287
289
|
});
|
|
288
290
|
return { updated };
|
|
289
291
|
};
|
|
292
|
+
var isNestedParameterType = (type) => {
|
|
293
|
+
return type === CANVAS_BLOCK_PARAM_TYPE;
|
|
294
|
+
};
|
|
290
295
|
var processParameterTranslation = ({
|
|
291
296
|
uniformSourceLocale,
|
|
292
297
|
uniformTargetLocale,
|
|
@@ -297,6 +302,14 @@ var processParameterTranslation = ({
|
|
|
297
302
|
if (originalParameter.type !== parameter.type) {
|
|
298
303
|
return { updated: false };
|
|
299
304
|
}
|
|
305
|
+
if (isNestedParameterType(originalParameter.type)) {
|
|
306
|
+
return processNestedParameterTranslation({
|
|
307
|
+
uniformSourceLocale,
|
|
308
|
+
uniformTargetLocale,
|
|
309
|
+
originalParameter,
|
|
310
|
+
parameter
|
|
311
|
+
});
|
|
312
|
+
}
|
|
300
313
|
if (!originalParameter.locales && originalParameter.value === void 0) {
|
|
301
314
|
return { updated: false };
|
|
302
315
|
}
|
|
@@ -309,7 +322,7 @@ var processParameterTranslation = ({
|
|
|
309
322
|
left: originalParameterSource,
|
|
310
323
|
right: sourceValue
|
|
311
324
|
});
|
|
312
|
-
const isTargetValueUntouched = isSameParameterValue({
|
|
325
|
+
const isTargetValueUntouched = originalTargetValue === void 0 ? true : isSameParameterValue({
|
|
313
326
|
parameterType: originalParameter.type,
|
|
314
327
|
left: (_d = originalParameter.locales) == null ? void 0 : _d[uniformTargetLocale],
|
|
315
328
|
right: originalTargetValue
|
|
@@ -341,6 +354,39 @@ var processParameterTranslation = ({
|
|
|
341
354
|
}
|
|
342
355
|
return { updated: false };
|
|
343
356
|
};
|
|
357
|
+
var processNestedParameterTranslation = ({
|
|
358
|
+
uniformSourceLocale,
|
|
359
|
+
uniformTargetLocale,
|
|
360
|
+
originalParameter,
|
|
361
|
+
parameter
|
|
362
|
+
}) => {
|
|
363
|
+
let updated = false;
|
|
364
|
+
if (originalParameter.type == CANVAS_BLOCK_PARAM_TYPE && Array.isArray(originalParameter.value) && Array.isArray(parameter.value)) {
|
|
365
|
+
const originalValue = originalParameter.value;
|
|
366
|
+
const translatedValue = parameter.value;
|
|
367
|
+
for (const translatedBlock of translatedValue) {
|
|
368
|
+
if (!translatedBlock._id || !translatedBlock.type) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
const originalBlock = originalValue.find(
|
|
372
|
+
(b) => b._id === translatedBlock._id && b.type === translatedBlock.type
|
|
373
|
+
);
|
|
374
|
+
if (!originalBlock) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const { updated: blockUpdated } = processComponentTranslation({
|
|
378
|
+
uniformSourceLocale,
|
|
379
|
+
uniformTargetLocale,
|
|
380
|
+
originalNode: originalBlock,
|
|
381
|
+
translatedComponent: translatedBlock
|
|
382
|
+
});
|
|
383
|
+
if (blockUpdated) {
|
|
384
|
+
updated = true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return { updated };
|
|
389
|
+
};
|
|
344
390
|
var processOverrideTranslation = ({
|
|
345
391
|
uniformSourceLocale,
|
|
346
392
|
uniformTargetLocale,
|
|
@@ -453,7 +499,8 @@ var collectTranslationPayload = ({
|
|
|
453
499
|
uniformReleaseId,
|
|
454
500
|
targetLang,
|
|
455
501
|
entity,
|
|
456
|
-
entityType
|
|
502
|
+
entityType,
|
|
503
|
+
config = {}
|
|
457
504
|
}) => {
|
|
458
505
|
if (!uniformSourceLocale || !uniformTargetLocale || !targetLang || !entity) {
|
|
459
506
|
return createErrorResult2("invalid-args");
|
|
@@ -477,16 +524,22 @@ var collectTranslationPayload = ({
|
|
|
477
524
|
},
|
|
478
525
|
components: {}
|
|
479
526
|
};
|
|
480
|
-
walkNodeTree2(entity, ({ node, actions }) => {
|
|
527
|
+
walkNodeTree2(entity, ({ node, actions, ancestorsAndSelf }) => {
|
|
528
|
+
var _a;
|
|
481
529
|
if (!node.type || !node._id) {
|
|
482
530
|
actions.stopProcessingDescendants();
|
|
483
531
|
return;
|
|
484
532
|
}
|
|
533
|
+
if (((_a = ancestorsAndSelf.at(0)) == null ? void 0 : _a.type) === "block") {
|
|
534
|
+
actions.stopProcessingDescendants();
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
485
537
|
const { _id, type, parameters, _overrides } = collectFromNode({
|
|
486
538
|
uniformSourceLocale,
|
|
487
539
|
uniformTargetLocale,
|
|
488
540
|
node,
|
|
489
|
-
deep: false
|
|
541
|
+
deep: false,
|
|
542
|
+
config
|
|
490
543
|
});
|
|
491
544
|
if (parameters || _overrides) {
|
|
492
545
|
payload.components[node._id] = {
|
|
@@ -503,7 +556,8 @@ var collectFromNode = ({
|
|
|
503
556
|
uniformSourceLocale,
|
|
504
557
|
uniformTargetLocale,
|
|
505
558
|
node,
|
|
506
|
-
deep
|
|
559
|
+
deep,
|
|
560
|
+
config
|
|
507
561
|
}) => {
|
|
508
562
|
var _a, _b, _c;
|
|
509
563
|
const collectedParameters = {};
|
|
@@ -513,12 +567,24 @@ var collectFromNode = ({
|
|
|
513
567
|
const entryFields = "fields" in node ? node.fields : void 0;
|
|
514
568
|
Object.entries((_a = componentParameters != null ? componentParameters : entryFields) != null ? _a : {}).forEach(([paramKey, param]) => {
|
|
515
569
|
var _a2, _b2;
|
|
570
|
+
if (isNestedParameterType(param.type)) {
|
|
571
|
+
const nestedParam = collectNestedParameter({
|
|
572
|
+
param,
|
|
573
|
+
uniformSourceLocale,
|
|
574
|
+
uniformTargetLocale,
|
|
575
|
+
config
|
|
576
|
+
});
|
|
577
|
+
if (nestedParam) {
|
|
578
|
+
collectedParameters[paramKey] = nestedParam;
|
|
579
|
+
}
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
516
582
|
const sourceLocaleValue = (_a2 = param.locales) == null ? void 0 : _a2[uniformSourceLocale];
|
|
517
583
|
const targetLocaleValue = (_b2 = param.locales) == null ? void 0 : _b2[uniformTargetLocale];
|
|
518
584
|
if (!canTranslateParameterValue(param, sourceLocaleValue)) {
|
|
519
585
|
return;
|
|
520
586
|
}
|
|
521
|
-
if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
587
|
+
if (!config.ignoreTargetLocaleValueMismatch && !isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
522
588
|
return;
|
|
523
589
|
}
|
|
524
590
|
collectedParameters[paramKey] = {
|
|
@@ -526,7 +592,7 @@ var collectFromNode = ({
|
|
|
526
592
|
locales: {
|
|
527
593
|
[TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
|
|
528
594
|
[TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
|
|
529
|
-
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
|
|
595
|
+
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: !config.ignoreTargetLocaleValueMismatch ? targetLocaleValue : void 0
|
|
530
596
|
}
|
|
531
597
|
};
|
|
532
598
|
});
|
|
@@ -541,7 +607,8 @@ var collectFromNode = ({
|
|
|
541
607
|
uniformSourceLocale,
|
|
542
608
|
uniformTargetLocale,
|
|
543
609
|
node: slotComponent,
|
|
544
|
-
deep: true
|
|
610
|
+
deep: true,
|
|
611
|
+
config
|
|
545
612
|
});
|
|
546
613
|
const hasContent = collectedNode.parameters || collectedNode._overrides || collectedNode.slots;
|
|
547
614
|
if (hasContent) {
|
|
@@ -554,23 +621,37 @@ var collectFromNode = ({
|
|
|
554
621
|
Object.entries((_c = node._overrides) != null ? _c : {}).forEach(([overrideKey, override]) => {
|
|
555
622
|
var _a2, _b2;
|
|
556
623
|
Object.entries((_a2 = override.parameters) != null ? _a2 : {}).forEach(([paramKey, param]) => {
|
|
557
|
-
var _a3, _b3, _c2, _d, _e;
|
|
558
|
-
|
|
559
|
-
|
|
624
|
+
var _a3, _b3, _c2, _d, _e, _f, _g, _h;
|
|
625
|
+
if (isNestedParameterType(param.type)) {
|
|
626
|
+
const nestedParam = collectNestedParameter({
|
|
627
|
+
param,
|
|
628
|
+
uniformSourceLocale,
|
|
629
|
+
uniformTargetLocale,
|
|
630
|
+
config
|
|
631
|
+
});
|
|
632
|
+
if (nestedParam) {
|
|
633
|
+
(_a3 = collectedOverrides[overrideKey]) != null ? _a3 : collectedOverrides[overrideKey] = {};
|
|
634
|
+
(_c2 = (_b3 = collectedOverrides[overrideKey]).parameters) != null ? _c2 : _b3.parameters = {};
|
|
635
|
+
collectedOverrides[overrideKey].parameters[paramKey] = nestedParam;
|
|
636
|
+
}
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
const sourceLocaleValue = (_d = param.locales) == null ? void 0 : _d[uniformSourceLocale];
|
|
640
|
+
const targetLocaleValue = (_e = param.locales) == null ? void 0 : _e[uniformTargetLocale];
|
|
560
641
|
if (!canTranslateParameterValue(param, sourceLocaleValue)) {
|
|
561
642
|
return;
|
|
562
643
|
}
|
|
563
|
-
if (!isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
644
|
+
if (!config.ignoreTargetLocaleValueMismatch && !isTargetLocaleUntouched(param.type, sourceLocaleValue, targetLocaleValue)) {
|
|
564
645
|
return;
|
|
565
646
|
}
|
|
566
|
-
(
|
|
567
|
-
(
|
|
647
|
+
(_f = collectedOverrides[overrideKey]) != null ? _f : collectedOverrides[overrideKey] = {};
|
|
648
|
+
(_h = (_g = collectedOverrides[overrideKey]).parameters) != null ? _h : _g.parameters = {};
|
|
568
649
|
collectedOverrides[overrideKey].parameters[paramKey] = {
|
|
569
650
|
type: param.type,
|
|
570
651
|
locales: {
|
|
571
652
|
[TRANSLATION_PAYLOAD_SOURCE_KEY]: sourceLocaleValue,
|
|
572
653
|
[TRANSLATION_PAYLOAD_TARGET_KEY]: preprocessTargetValue(param, sourceLocaleValue),
|
|
573
|
-
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: targetLocaleValue
|
|
654
|
+
[TRANSLATION_PAYLOAD_ORIGINAL_TARGET_KEY]: !config.ignoreTargetLocaleValueMismatch ? targetLocaleValue : void 0
|
|
574
655
|
}
|
|
575
656
|
};
|
|
576
657
|
});
|
|
@@ -586,7 +667,8 @@ var collectFromNode = ({
|
|
|
586
667
|
node: slotComponent,
|
|
587
668
|
// keep tree structure for `Slot Sections`
|
|
588
669
|
// to store whole `override` content in scope of current component
|
|
589
|
-
deep: true
|
|
670
|
+
deep: true,
|
|
671
|
+
config
|
|
590
672
|
});
|
|
591
673
|
const hasContent = collectedNode.parameters || collectedNode._overrides || collectedNode.slots;
|
|
592
674
|
if (hasContent) {
|
|
@@ -609,6 +691,42 @@ var collectFromNode = ({
|
|
|
609
691
|
_overrides: hasOverrides ? collectedOverrides : void 0
|
|
610
692
|
};
|
|
611
693
|
};
|
|
694
|
+
var collectNestedParameter = ({
|
|
695
|
+
param,
|
|
696
|
+
uniformSourceLocale,
|
|
697
|
+
uniformTargetLocale,
|
|
698
|
+
config
|
|
699
|
+
}) => {
|
|
700
|
+
if (param.type === CANVAS_BLOCK_PARAM_TYPE2 && Array.isArray(param.value)) {
|
|
701
|
+
const blockValue = param.value;
|
|
702
|
+
const collectedBlocks = [];
|
|
703
|
+
for (const blockEntry of blockValue) {
|
|
704
|
+
if (!blockEntry._id || !blockEntry.type) {
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
const collectedNode = collectFromNode({
|
|
708
|
+
uniformSourceLocale,
|
|
709
|
+
uniformTargetLocale,
|
|
710
|
+
node: blockEntry,
|
|
711
|
+
deep: false,
|
|
712
|
+
config
|
|
713
|
+
});
|
|
714
|
+
const hasContent = collectedNode.parameters || collectedNode._overrides;
|
|
715
|
+
if (hasContent) {
|
|
716
|
+
collectedNode.slots = void 0;
|
|
717
|
+
collectedBlocks.push(collectedNode);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (collectedBlocks.length === 0) {
|
|
721
|
+
return void 0;
|
|
722
|
+
}
|
|
723
|
+
return {
|
|
724
|
+
type: CANVAS_BLOCK_PARAM_TYPE2,
|
|
725
|
+
value: collectedBlocks
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
return void 0;
|
|
729
|
+
};
|
|
612
730
|
var canTranslateParameterValue = (parameter, value) => {
|
|
613
731
|
if (parameter.type === SUPPORTED_PARAM_TYPES.text) {
|
|
614
732
|
if (typeof value !== "string" || !value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/tms-sdk",
|
|
3
|
-
"version": "20.50.2-alpha.
|
|
3
|
+
"version": "20.50.2-alpha.117+4eb2f1aa44",
|
|
4
4
|
"description": "Uniform Translation Management System SDK",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,9 +22,8 @@
|
|
|
22
22
|
"dev:ts": "tsup --watch",
|
|
23
23
|
"clean": "rimraf dist",
|
|
24
24
|
"test": "vitest run",
|
|
25
|
-
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
|
|
26
25
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
|
|
27
|
-
"
|
|
26
|
+
"apidocs-extract": "api-extractor run --local"
|
|
28
27
|
},
|
|
29
28
|
"files": [
|
|
30
29
|
"/dist"
|
|
@@ -33,12 +32,12 @@
|
|
|
33
32
|
"access": "public"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
|
-
"@uniformdev/canvas": "20.50.2-alpha.
|
|
37
|
-
"@uniformdev/mesh-sdk": "20.50.2-alpha.
|
|
38
|
-
"@uniformdev/richtext": "20.50.2-alpha.
|
|
35
|
+
"@uniformdev/canvas": "20.50.2-alpha.117+4eb2f1aa44",
|
|
36
|
+
"@uniformdev/mesh-sdk": "20.50.2-alpha.117+4eb2f1aa44",
|
|
37
|
+
"@uniformdev/richtext": "20.50.2-alpha.117+4eb2f1aa44",
|
|
39
38
|
"dequal": "2.0.3",
|
|
40
|
-
"fast-xml-parser": "4.
|
|
39
|
+
"fast-xml-parser": "4.5.5",
|
|
41
40
|
"immer": "10.1.3"
|
|
42
41
|
},
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "4eb2f1aa443ff87c7f365c70c1cf221f3ec07a78"
|
|
44
43
|
}
|