@justanarthur/payload-plugin-translator 3.3.3 → 3.3.4
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.ts +2 -0
- package/dist/index.js +3 -3
- package/dist/jobs.js +2 -2
- package/dist/rsc.js +2 -2
- package/dist/shared/{chunk-xgsxe28w.js → chunk-8hm2r1wg.js} +1 -1
- package/dist/shared/{chunk-pmxe5c20.js → chunk-8hqdxnxy.js} +6 -0
- package/dist/shared/{chunk-12hf0kdf.js → chunk-g3rrecgk.js} +8 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ type TranslateResult = {
|
|
|
22
22
|
translatedData: Record<string, any>;
|
|
23
23
|
/** values sent to the resolver; 0 means the target needed nothing */
|
|
24
24
|
translatedCount: number;
|
|
25
|
+
/** non-translatable values (relationships, selects, …) copied from the source because they differed; a sync-only run still persists */
|
|
26
|
+
syncedCount: number;
|
|
25
27
|
dataFrom: Doc;
|
|
26
28
|
};
|
|
27
29
|
type TranslateOperationArgs = ({
|
package/dist/index.js
CHANGED
|
@@ -8,15 +8,15 @@ import {
|
|
|
8
8
|
isTranslateMode,
|
|
9
9
|
createTranslateTask2,
|
|
10
10
|
createTranslateWorkflow2
|
|
11
|
-
} from "./shared/chunk-
|
|
12
|
-
import"./shared/chunk-
|
|
11
|
+
} from "./shared/chunk-g3rrecgk.js";
|
|
12
|
+
import"./shared/chunk-8hqdxnxy.js";
|
|
13
13
|
import {
|
|
14
14
|
readLocales,
|
|
15
15
|
parseEntityKey,
|
|
16
16
|
hasTranslateWorkflow,
|
|
17
17
|
queueBulkTranslation,
|
|
18
18
|
runQueuedTranslations
|
|
19
|
-
} from "./shared/chunk-
|
|
19
|
+
} from "./shared/chunk-8hm2r1wg.js";
|
|
20
20
|
import {
|
|
21
21
|
TRANSLATION_STATUS_SLUG2,
|
|
22
22
|
REVIEW_VIEW_PATH
|
package/dist/jobs.js
CHANGED
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
createAutoTranslateGlobalHook2,
|
|
4
4
|
createTranslateTask2,
|
|
5
5
|
createTranslateWorkflow2
|
|
6
|
-
} from "./shared/chunk-
|
|
6
|
+
} from "./shared/chunk-g3rrecgk.js";
|
|
7
7
|
import {
|
|
8
8
|
TRANSLATE_TASK_SLUG2,
|
|
9
9
|
TRANSLATE_WORKFLOW_SLUG2
|
|
10
|
-
} from "./shared/chunk-
|
|
10
|
+
} from "./shared/chunk-8hqdxnxy.js";
|
|
11
11
|
|
|
12
12
|
// src/exports/jobs.ts
|
|
13
13
|
var jobs = {
|
package/dist/rsc.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import"./shared/chunk-
|
|
1
|
+
import"./shared/chunk-8hqdxnxy.js";
|
|
2
2
|
import {
|
|
3
3
|
readLocales,
|
|
4
4
|
loadCollectionReview,
|
|
5
5
|
loadGlobalsReview,
|
|
6
6
|
loadEntityLocaleReview,
|
|
7
7
|
loadJobsProgress
|
|
8
|
-
} from "./shared/chunk-
|
|
8
|
+
} from "./shared/chunk-8hm2r1wg.js";
|
|
9
9
|
import {
|
|
10
10
|
REVIEW_VIEW_PATH
|
|
11
11
|
} from "./shared/chunk-31qgv1zk.js";
|
|
@@ -175,6 +175,7 @@ var traverseFields = (args) => {
|
|
|
175
175
|
path,
|
|
176
176
|
translatedData,
|
|
177
177
|
valuesToTranslate,
|
|
178
|
+
syncedValues,
|
|
178
179
|
onField,
|
|
179
180
|
_options
|
|
180
181
|
} = args;
|
|
@@ -235,6 +236,8 @@ var traverseFields = (args) => {
|
|
|
235
236
|
break;
|
|
236
237
|
const existing = Array.isArray(siblingDataTranslated[field.name]) ? siblingDataTranslated[field.name] : [];
|
|
237
238
|
const localized = Boolean(field.localized || localizedParent);
|
|
239
|
+
if (localized && existing.length !== rowsFrom.length)
|
|
240
|
+
syncedValues.count++;
|
|
238
241
|
const rows = localized ? buildLocalizedRows(rowsFrom, existing, isBlocks, emptyOnly) : existing.length ? existing : structuredClone(rowsFrom);
|
|
239
242
|
rows.forEach((row, index) => {
|
|
240
243
|
const rowFrom = rowsFrom[index];
|
|
@@ -278,6 +281,8 @@ var traverseFields = (args) => {
|
|
|
278
281
|
case "relationship":
|
|
279
282
|
case "select":
|
|
280
283
|
case "upload":
|
|
284
|
+
if (JSON.stringify(siblingDataTranslated[field.name]) !== JSON.stringify(siblingDataFrom[field.name]))
|
|
285
|
+
syncedValues.count++;
|
|
281
286
|
siblingDataTranslated[field.name] = siblingDataFrom[field.name];
|
|
282
287
|
break;
|
|
283
288
|
case "json": {
|
|
@@ -423,6 +428,7 @@ var collectTranslatableFields = ({ config, dataFrom, dataTarget, options }) => {
|
|
|
423
428
|
fields: config.fields,
|
|
424
429
|
translatedData: structuredClone(dataTarget ?? {}),
|
|
425
430
|
valuesToTranslate: [],
|
|
431
|
+
syncedValues: { count: 0 },
|
|
426
432
|
onField: (field) => fields.push(field),
|
|
427
433
|
_options: options
|
|
428
434
|
});
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
collectTranslatableFields,
|
|
8
8
|
entityKey,
|
|
9
9
|
sourceHash
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-8hqdxnxy.js";
|
|
11
11
|
import {
|
|
12
12
|
TRANSLATION_STATUS_SLUG2
|
|
13
13
|
} from "./chunk-31qgv1zk.js";
|
|
@@ -123,6 +123,7 @@ var translateOperation2 = async (args) => {
|
|
|
123
123
|
if (!resolver)
|
|
124
124
|
throw new APIError3(`Resolver with the key ${args.resolver} was not found`);
|
|
125
125
|
const valuesToTranslate = [];
|
|
126
|
+
const syncedValues = { count: 0 };
|
|
126
127
|
let translatedData = args.data;
|
|
127
128
|
if (!translatedData) {
|
|
128
129
|
const { doc } = await findEntityWithConfig({
|
|
@@ -145,12 +146,13 @@ var translateOperation2 = async (args) => {
|
|
|
145
146
|
fields: config.fields,
|
|
146
147
|
translatedData,
|
|
147
148
|
valuesToTranslate,
|
|
149
|
+
syncedValues,
|
|
148
150
|
_options: req.payload.config.custom?.translator?._options
|
|
149
151
|
});
|
|
150
152
|
const entityLabel = `${collectionSlug || globalSlug}#${id ?? ""}`;
|
|
151
153
|
const direction = `${args.localeFrom}→${args.locale}`;
|
|
152
154
|
req.payload.logger.info({
|
|
153
|
-
msg: `[translate] ${entityLabel} ${direction}: traversed ${valuesToTranslate.length} translatable value(s)`
|
|
155
|
+
msg: `[translate] ${entityLabel} ${direction}: traversed ${valuesToTranslate.length} translatable value(s)` + (syncedValues.count ? `, synced ${syncedValues.count} field value(s)` : "")
|
|
154
156
|
});
|
|
155
157
|
const resolveResult = valuesToTranslate.length === 0 ? { success: true, translatedTexts: [] } : await resolver.resolve({
|
|
156
158
|
localeFrom: args.localeFrom,
|
|
@@ -193,7 +195,7 @@ ${valuesToTranslate.map((v) => ` ${v.path ?? "(unknown)"}: ${preview(v.value)}`
|
|
|
193
195
|
${summary.join(`
|
|
194
196
|
`)}` : "")
|
|
195
197
|
});
|
|
196
|
-
if (args.update && valuesToTranslate.length > 0) {
|
|
198
|
+
if (args.update && (valuesToTranslate.length > 0 || syncedValues.count > 0)) {
|
|
197
199
|
const { _locale, _parent_id, createdAt, updatedAt, ...data } = translatedData;
|
|
198
200
|
await updateEntity({
|
|
199
201
|
collectionSlug,
|
|
@@ -210,6 +212,7 @@ ${summary.join(`
|
|
|
210
212
|
success: true,
|
|
211
213
|
translatedData,
|
|
212
214
|
translatedCount: valuesToTranslate.length,
|
|
215
|
+
syncedCount: syncedValues.count,
|
|
213
216
|
dataFrom
|
|
214
217
|
};
|
|
215
218
|
}
|
|
@@ -526,7 +529,7 @@ function createTranslateTask2(options = {}) {
|
|
|
526
529
|
});
|
|
527
530
|
return { output: { success: true } };
|
|
528
531
|
}
|
|
529
|
-
if (result.translatedCount === 0) {
|
|
532
|
+
if (result.translatedCount === 0 && result.syncedCount === 0) {
|
|
530
533
|
req.payload.logger.info({ jobId: job.id, msg: `[translate] ${entityLabel}#${id ?? global} → ${toLocale}: nothing to translate` });
|
|
531
534
|
return { output: { success: true } };
|
|
532
535
|
}
|
|
@@ -534,7 +537,7 @@ function createTranslateTask2(options = {}) {
|
|
|
534
537
|
const { _locale: _dropLocale, _parent_id: _dropParent, updatedAt: _dropUpdatedAt, createdAt: _dropCreatedAt, ...data } = translated;
|
|
535
538
|
req.payload.logger.info({
|
|
536
539
|
jobId: job.id,
|
|
537
|
-
msg: `[translate] persisting ${entityLabel}#${id ?? global} → ${toLocale}`
|
|
540
|
+
msg: `[translate] persisting ${entityLabel}#${id ?? global} → ${toLocale}` + (result.translatedCount === 0 ? " (field sync only)" : "")
|
|
538
541
|
});
|
|
539
542
|
try {
|
|
540
543
|
await updateEntity({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justanarthur/payload-plugin-translator",
|
|
3
3
|
"description": "Translator plugin for Payload CMS — automatic localization via Google, OpenAI, LibreTranslate, or custom resolvers.",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"files": [
|