Skip to content

Commit 35ce193

Browse files
committed
Merge branch 'ENG-10907-smartling-fixes' of github.com:anaghav2023/builder into ENG-10907-smartling-fixes
2 parents fe4d778 + 8c64006 commit 35ce193

File tree

6 files changed

+97
-10
lines changed

6 files changed

+97
-10
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,38 @@ test('getTranslateableFields from content to match snapshot', async () => {
5454
},
5555
},
5656
},
57+
{
58+
meta: {
59+
instructions: 'Button with plain text',
60+
},
61+
id: 'button-plain-text-id',
62+
'@type': '@builder.io/sdk:Element',
63+
component: {
64+
name: 'Core:Button',
65+
options: {
66+
text: 'Cute Baby',
67+
openLinkInNewTab: false,
68+
},
69+
},
70+
},
71+
{
72+
meta: {
73+
instructions: 'Button with pre-localized text',
74+
},
75+
id: 'button-localized-text-id',
76+
'@type': '@builder.io/sdk:Element',
77+
component: {
78+
name: 'Core:Button',
79+
options: {
80+
text: {
81+
'@type': localizedType,
82+
'en-US': 'Click Me!',
83+
Default: 'Click Here',
84+
},
85+
openLinkInNewTab: true,
86+
},
87+
},
88+
},
5789
{
5890
'@type': '@builder.io/sdk:Element',
5991
id: 'builder-custom-component-id',

packages/utils/src/translation-helpers.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ export function getTranslateableFields(
207207
};
208208
}
209209

210+
if (el && el.id && el.component?.name === 'Core:Button' && !el.meta?.excludeFromTranslation) {
211+
const componentText = el.component.options?.text;
212+
if (componentText) {
213+
const textValue = typeof componentText === 'string'
214+
? componentText
215+
: componentText?.[sourceLocaleId] || componentText?.Default;
216+
if (textValue) {
217+
results[`blocks.${el.id}#text`] = {
218+
value: textValue,
219+
instructions: el.meta?.instructions || defaultInstructions,
220+
};
221+
}
222+
}
223+
}
224+
210225
if (el && el.id && el.component?.name === 'Symbol') {
211226
const symbolInputs = Object.entries(el.component?.options?.symbol?.data) || [];
212227
if (symbolInputs.length) {
@@ -342,6 +357,45 @@ export function applyTranslation(
342357
});
343358
}
344359

360+
// Core:Button special handling - similar to Text component
361+
if (
362+
el &&
363+
el.id &&
364+
el.component?.name === 'Core:Button' &&
365+
!el.meta?.excludeFromTranslation &&
366+
translation[`blocks.${el.id}#text`]
367+
) {
368+
const localizedValues =
369+
typeof el.component.options?.text === 'string'
370+
? {
371+
Default: el.component.options.text,
372+
}
373+
: el.component.options.text;
374+
375+
const updatedElement = {
376+
...el,
377+
meta: {
378+
...el.meta,
379+
translated: true,
380+
// this tells the editor that this is a forced localized input similar to clicking the globe icon
381+
'transformed.text': 'localized',
382+
},
383+
component: {
384+
...el.component,
385+
options: {
386+
...el.component.options,
387+
text: {
388+
'@type': localizedType,
389+
...localizedValues,
390+
[locale]: unescapeStringOrObject(translation[`blocks.${el.id}#text`].value),
391+
},
392+
},
393+
},
394+
};
395+
396+
this.update(updatedElement);
397+
}
398+
345399
// custom components
346400
if (el && el.id && el.meta?.localizedTextInputs) {
347401
// there's a localized input

packages/utils/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"esModuleInterop": true,
88
"skipLibCheck": true,
99
"strict": true,
10-
"declaration": true
10+
"declaration": true,
11+
"types": []
1112
},
1213
"include": ["./src"],
1314
"exclude": ["node_modules", "**/*.test.ts"]

plugins/smartling/package-lock.json

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

plugins/smartling/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"typescript": "^3.0.3"
126126
},
127127
"dependencies": {
128-
"@builder.io/utils": "1.1.25-2",
128+
"@builder.io/utils": "1.1.26",
129129
"fast-json-stable-stringify": "^2.1.0",
130130
"lodash": "^4.17.21",
131131
"object-hash": "^3.0.0",

plugins/smartling/src/plugin.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ const initializeSmartlingPlugin = async () => {
747747
},
748748
async onClick(content) {
749749
const translationBatch = fastClone(content.meta).translationBatch;
750-
// https://dashboard.smartling.com/app/projects/0e6193784/strings/jobs/schqxtpcnxix
751-
const smartlingFile = `https://dashboard.smartling.com/app/projects/${translationBatch.projectId}/strings/jobs/${translationBatch.translationJobUid}`;
750+
// Filter by file URI (content ID) to show all translations across all jobs
751+
const smartlingFile = `https://dashboard.smartling.com/app/projects/${translationBatch.projectId}/strings/?urlsFilter.urls=${content.id}&limit=200&offset=0`;
752752
window.open(smartlingFile, '_blank', 'noreferrer,noopener');
753753
},
754754
});

0 commit comments

Comments
 (0)