Skip to content

Commit f4bd2ef

Browse files
committed
multiple features
1 parent ee29448 commit f4bd2ef

File tree

5 files changed

+126
-31
lines changed

5 files changed

+126
-31
lines changed

packages/utils/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@builder.io/utils",
3-
"version": "1.1.27",
3+
"version": "1.1.28",
44
"description": "Utils for working with Builder.io content",
55
"main": "./dist/index.js",
66
"scripts": {

packages/utils/src/__snapshots__/translation-helpers.test.ts.snap

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,31 @@ Object {
322322
}
323323
`;
324324

325+
exports[`getTranslateableFields from carousel content and custom component with subFields to match snapshot 1`] = `
326+
Object {
327+
"blocks.builder-06d3f6da74fb4054ad311afc1dda3675#text": Object {
328+
"instructions": "Visit https://builder.io/fiddle/... for more details",
329+
"value": "<p>I am slide second</p>",
330+
},
331+
"blocks.builder-0a10ae48b6314221bbb7d06d068d623d#text": Object {
332+
"instructions": "Visit https://builder.io/fiddle/... for more details",
333+
"value": "<p>I am slide 1</p>",
334+
},
335+
"blocks.builder-23e0618256ab40799ecf6504bc57fa1c#listItems.0.field1": Object {
336+
"instructions": "Visit https://builder.io/fiddle/... for more details",
337+
"value": "<p>text 1 value</p>",
338+
},
339+
"blocks.builder-23e0618256ab40799ecf6504bc57fa1c#listItems.1.field1": Object {
340+
"instructions": "Visit https://builder.io/fiddle/... for more details",
341+
"value": "<p>text 1.1 value</p>",
342+
},
343+
"blocks.builder-23e0618256ab40799ecf6504bc57fa1c#title.text": Object {
344+
"instructions": "Visit https://builder.io/fiddle/... for more details",
345+
"value": "<p>custom component subField input</p>",
346+
},
347+
}
348+
`;
349+
325350
exports[`getTranslateableFields from content to match snapshot 1`] = `
326351
Object {
327352
"blocks.block-id#text": Object {
@@ -360,6 +385,14 @@ Object {
360385
"instructions": "Visit https://builder.io/fiddle/... for more details",
361386
"value": "en-us headings!",
362387
},
388+
"blocks.button-localized-text-id#text": Object {
389+
"instructions": "Button with pre-localized text",
390+
"value": "Click Me!",
391+
},
392+
"blocks.button-plain-text-id#text": Object {
393+
"instructions": "Button with plain text",
394+
"value": "Cute Baby",
395+
},
363396
"metadata.seo": Object {
364397
"instructions": "Visit https://builder.io/fiddle/... for more details",
365398
"value": Object {
@@ -386,28 +419,3 @@ Object {
386419
},
387420
}
388421
`;
389-
390-
exports[`getTranslateableFields from carousel content and custom component with subFields to match snapshot 1`] = `
391-
Object {
392-
"blocks.builder-06d3f6da74fb4054ad311afc1dda3675#text": Object {
393-
"instructions": "Visit https://builder.io/fiddle/... for more details",
394-
"value": "<p>I am slide second</p>",
395-
},
396-
"blocks.builder-0a10ae48b6314221bbb7d06d068d623d#text": Object {
397-
"instructions": "Visit https://builder.io/fiddle/... for more details",
398-
"value": "<p>I am slide 1</p>",
399-
},
400-
"blocks.builder-23e0618256ab40799ecf6504bc57fa1c#listItems.0.field1": Object {
401-
"instructions": "Visit https://builder.io/fiddle/... for more details",
402-
"value": "<p>text 1 value</p>",
403-
},
404-
"blocks.builder-23e0618256ab40799ecf6504bc57fa1c#listItems.1.field1": Object {
405-
"instructions": "Visit https://builder.io/fiddle/... for more details",
406-
"value": "<p>text 1.1 value</p>",
407-
},
408-
"blocks.builder-23e0618256ab40799ecf6504bc57fa1c#title.text": Object {
409-
"instructions": "Visit https://builder.io/fiddle/... for more details",
410-
"value": "<p>custom component subField input</p>",
411-
},
412-
}
413-
`;

packages/utils/src/translation-helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export function getTranslateableFields(
221221
// blocks
222222
if (blocks) {
223223
traverse(blocks).forEach(function (el) {
224-
if (this.key && el && el.meta?.localizedTextInputs) {
224+
if (this.key && el && el.meta?.localizedTextInputs && !el.meta?.excludeFromTranslation) {
225225
const localizedTextInputs = el.meta.localizedTextInputs as string[];
226226
if (localizedTextInputs && Array.isArray(localizedTextInputs)) {
227227
localizedTextInputs
@@ -264,7 +264,7 @@ export function getTranslateableFields(
264264
}
265265
}
266266

267-
if (el && el.id && el.component?.name === 'Symbol') {
267+
if (el && el.id && el.component?.name === 'Symbol'&& !el.meta?.excludeFromTranslation) {
268268
const symbolInputs = Object.entries(el.component?.options?.symbol?.data) || [];
269269
if (symbolInputs.length) {
270270
const basePath = `blocks.${el.id}.symbolInput`;
@@ -440,7 +440,7 @@ export function applyTranslation(
440440
}
441441

442442
// custom components
443-
if (el && el.id && el.meta?.localizedTextInputs) {
443+
if (el && el.id && el.meta?.localizedTextInputs && !el.meta?.excludeFromTranslation) {
444444
// there's a localized input
445445
const keys = el.meta?.localizedTextInputs as string[];
446446
let options = el.component.options;

plugins/smartling/src/plugin.tsx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ Builder.register('plugin', {
163163
advanced: false,
164164
requiredPermissions: ['admin'],
165165
},
166+
{
167+
name: 'disableVisualContextCapture',
168+
friendlyName: 'Disable Visual Context Capture',
169+
type: 'boolean',
170+
defaultValue: false,
171+
helperText: 'Disable automatic visual context capture for translations',
172+
requiredPermissions: ['admin'],
173+
},
174+
{
175+
name: 'contextOverrideOlderThanDays',
176+
friendlyName: 'Context Override Older Than Days',
177+
type: 'number',
178+
helperText: 'Override context for content older than this number of days',
179+
requiredPermissions: ['admin'],
180+
},
166181
],
167182
onSave: async actions => {
168183
const pluginPrivateKey = await appState.globalState.getPluginPrivateKey(pkg.name);
@@ -483,6 +498,78 @@ const initializeSmartlingPlugin = async () => {
483498
},
484499
});
485500

501+
502+
registerContextMenuAction({
503+
label: 'Add String Instructions',
504+
showIf(selectedElements) {
505+
if (selectedElements.length !== 1) {
506+
// todo maybe apply for multiple
507+
return false;
508+
}
509+
const element = selectedElements[0];
510+
return element.meta?.get('instructions') === undefined;
511+
},
512+
async onClick(elements) {
513+
if (elements.length !== 1) {
514+
// todo maybe apply for multiple
515+
return false;
516+
}
517+
const instructions = await appState.dialogs.prompt({
518+
placeholderText: 'Enter string instructions for translation',
519+
});
520+
if (instructions) {
521+
elements[0].meta.set('instructions', instructions);
522+
appState.snackBar.show('String instructions added to content');
523+
}
524+
},
525+
});
526+
527+
registerContextMenuAction({
528+
label: 'Edit String Instructions',
529+
showIf(selectedElements) {
530+
if (selectedElements.length !== 1) {
531+
// todo maybe apply for multiple
532+
return false;
533+
}
534+
const element = selectedElements[0];
535+
return element.meta?.get('instructions') !== undefined;
536+
},
537+
async onClick(elements) {
538+
if (elements.length !== 1) {
539+
// todo maybe apply for multiple
540+
return false;
541+
}
542+
const element = elements[0];
543+
const instructions = element.meta?.get('instructions');
544+
if (instructions) {
545+
const newInstructions = await appState.dialogs.prompt({
546+
placeholderText: 'Enter new string instructions for translation',
547+
defaultValue: instructions,
548+
});
549+
if (newInstructions) {
550+
element.meta.set('instructions', newInstructions);
551+
appState.snackBar.show('String instructions updated');
552+
}
553+
}
554+
},
555+
});
556+
557+
registerContextMenuAction({
558+
label: 'Delete String Instructions',
559+
showIf(selectedElements) {
560+
if (selectedElements.length !== 1) {
561+
// todo maybe apply for multiple
562+
return false;
563+
}
564+
const element = selectedElements[0];
565+
return element.meta?.get('instructions') !== undefined;
566+
},
567+
onClick(elements) {
568+
elements[0].meta.delete('instructions');
569+
appState.snackBar.show('String instructions deleted');
570+
},
571+
});
572+
486573
registerContentAction({
487574
label: 'Add to translation job',
488575
showIf(content, model) {

0 commit comments

Comments
 (0)