Skip to content

Commit 7490077

Browse files
authored
fix[plugin][smartling]: ENG-10907 smartling fixes (#4208)
## Description Fixes in this PR: 1. Add a "View job in smartling" button on the job menu 2. Fix the webhook not updating when re-loading the plugin 3. Fix the content api query issue 4. Fix the nested symbol data not going for translation **Loom** https://www.loom.com/share/f8b2a75c4e234bbdbae3008f8a345ed0 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds a Smartling job view action, updates webhooks when URLs change, fixes content picker query, includes nested symbols in translation jobs, and improves localized value extraction in utils. > > - **Smartling Plugin**: > - **Job UI**: Add "View job in smartling" action that opens the job in Smartling using `projectId:translationJobUid`. > - **Webhooks**: Update model webhook whenever the URL differs from the template. > - **Content Picker**: Query updated to `published or draft` for job selection. > - **Translation Jobs**: > - Update existing jobs to include recursively discovered nested `Symbol` references and avoid duplicates. > - New jobs also recursively include nested symbols during creation. > - **Utils** (`packages/utils/src/translation-helpers.ts`): > - When encountering `@builder.io/core:LocalizedValue`, store string values directly and recurse into arrays/objects to collect nested localized values. > - **Dependencies**: > - Bump `@builder.io/utils` to `1.1.26` and `@builder.io/plugin-smartling` to `0.0.23-11`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 35ce193. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 1304e3e commit 7490077

File tree

7 files changed

+218
-123
lines changed

7 files changed

+218
-123
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.25",
3+
"version": "1.1.26",
44
"description": "Utils for working with Builder.io content",
55
"main": "./dist/index.js",
66
"scripts": {

packages/utils/src/translation-helpers.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,27 @@ function recordValue({
5959
});
6060
} else if (typeof value === 'object' && value !== null) {
6161
if (value['@type'] === localizedType) {
62-
results[path] = {
63-
value: value?.[sourceLocaleId] || value?.Default,
64-
instructions,
65-
};
62+
const extractedValue = value?.[sourceLocaleId] || value?.Default;
63+
64+
// If the extracted value is a string, store it directly
65+
if (typeof extractedValue === 'string') {
66+
results[path] = {
67+
value: extractedValue,
68+
instructions,
69+
};
70+
} else if (
71+
Array.isArray(extractedValue) ||
72+
(typeof extractedValue === 'object' && extractedValue !== null)
73+
) {
74+
// If the extracted value is an array or object, recurse into it to find more localized values
75+
recordValue({
76+
results,
77+
value: extractedValue,
78+
path,
79+
instructions,
80+
sourceLocaleId,
81+
});
82+
}
6683
} else {
6784
Object.entries(value).forEach(([key, v]) => {
6885
recordValue({

plugins/smartling/package-lock.json

Lines changed: 5 additions & 5 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@builder.io/plugin-smartling",
3-
"version": "0.0.23-9",
3+
"version": "0.0.23-11",
44
"description": "",
55
"keywords": [],
66
"main": "dist/plugin.system.js",
@@ -125,7 +125,7 @@
125125
"typescript": "^3.0.3"
126126
},
127127
"dependencies": {
128-
"@builder.io/utils": "1.1.25",
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: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ const initializeSmartlingPlugin = async () => {
213213
pkg.name
214214
);
215215

216-
// Check if webhook URL needs updating
216+
// Check if webhook URL needs updating - update whenever the URL is different
217217
const currentWebhookUrl = existingModel.webhooks?.[0]?.url;
218218
const newWebhookUrl = updatedTemplate.webhooks[0].url;
219219

220-
if (currentWebhookUrl && !currentWebhookUrl.includes('preferredVersion=v2') && newWebhookUrl.includes('preferredVersion=v2')) {
221-
// Update the existing model with v2 webhook
220+
if (currentWebhookUrl !== newWebhookUrl) {
221+
// Update the existing model with new webhook configuration
222222
existingModel.webhooks = updatedTemplate.webhooks;
223223
}
224224
}
@@ -649,6 +649,61 @@ const initializeSmartlingPlugin = async () => {
649649
},
650650
});
651651

652+
registerContentAction({
653+
label: 'View job in smartling',
654+
showIf(content, model) {
655+
const translationModel = getTranslationModel();
656+
if (!translationModel) return false;
657+
if (!model?.name || model.name !== translationModel.name) return false;
658+
659+
// translationBatch is set by backend after job is published
660+
if (!content.meta || !content.data) return false;
661+
662+
const meta = fastClone(content.meta);
663+
const data = content.data;
664+
665+
// Get project ID from jobDetails
666+
const projectId = data?.get?.('jobDetails')?.get?.('project') || data?.get?.('jobDetails')?.project;
667+
668+
// Get job UID from translationBatch (only available after job is authorized in Smartling)
669+
const translationJobUid = meta?.translationBatch?.translationJobUid;
670+
671+
return (
672+
projectId &&
673+
translationJobUid
674+
);
675+
},
676+
async onClick(translationJob) {
677+
if (!translationJob) {
678+
appState.snackBar.show('Job information not available');
679+
return;
680+
}
681+
682+
if (!translationJob.meta || !translationJob.data) {
683+
appState.snackBar.show('Job information not available');
684+
return;
685+
}
686+
687+
const meta = fastClone(translationJob.meta);
688+
const data = translationJob.data;
689+
690+
// Get project ID from jobDetails
691+
const projectId = data?.get?.('jobDetails')?.get?.('project') || data?.get?.('jobDetails')?.project;
692+
693+
// Get job UID from translationBatch
694+
const translationJobUid = meta?.translationBatch?.translationJobUid;
695+
696+
if (!projectId || !translationJobUid) {
697+
appState.snackBar.show('Job information not available');
698+
return;
699+
}
700+
701+
// Construct Smartling job URL with format: projectId:translationJobUid
702+
const smartlingJobUrl = `https://dashboard.smartling.com/app/projects/${projectId}/account-jobs/${projectId}:${translationJobUid}`;
703+
window.open(smartlingJobUrl, '_blank', 'noreferrer,noopener');
704+
},
705+
});
706+
652707
registerContentAction({
653708
label: 'View translation job',
654709
showIf(content, model) {
@@ -873,13 +928,7 @@ function pickTranslationJob() {
873928
'@type': '@builder.io/core:Query',
874929
property: 'query.published',
875930
operator: 'is',
876-
value: 'draft',
877-
},
878-
{
879-
'@type': '@builder.io/core:Query',
880-
property: 'query.published',
881-
operator: 'is',
882-
value: 'published',
931+
value: 'published or draft',
883932
},
884933
],
885934
});

0 commit comments

Comments
 (0)