@justanarthur/payload-plugin-translator 3.3.2 → 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/client.js CHANGED
@@ -303,8 +303,7 @@ var CustomButtonWithTranslator = ({ type }) => {
303
303
  if (!id && !globalSlug)
304
304
  return /* @__PURE__ */ jsx6(DefaultButton, {});
305
305
  const { localization } = config;
306
- const isSourceLocale = Boolean(localization) && locale.code === localization.defaultLocale;
307
- if (isSourceLocale)
306
+ if (localization && locale.code === localization.defaultLocale)
308
307
  return /* @__PURE__ */ jsx6(DefaultButton, {});
309
308
  return /* @__PURE__ */ jsx6(TranslatorProvider, {
310
309
  children: /* @__PURE__ */ jsxs4("div", {
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-kxdj1t2m.js";
12
- import"./shared/chunk-pmxe5c20.js";
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-xgsxe28w.js";
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-kxdj1t2m.js";
6
+ } from "./shared/chunk-g3rrecgk.js";
7
7
  import {
8
8
  TRANSLATE_TASK_SLUG2,
9
9
  TRANSLATE_WORKFLOW_SLUG2
10
- } from "./shared/chunk-pmxe5c20.js";
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-pmxe5c20.js";
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-xgsxe28w.js";
8
+ } from "./shared/chunk-8hm2r1wg.js";
9
9
  import {
10
10
  REVIEW_VIEW_PATH
11
11
  } from "./shared/chunk-31qgv1zk.js";
@@ -7,7 +7,7 @@ import {
7
7
  collectTranslatableFields,
8
8
  entityKey,
9
9
  sourceHash
10
- } from "./chunk-pmxe5c20.js";
10
+ } from "./chunk-8hqdxnxy.js";
11
11
  import {
12
12
  TRANSLATION_STATUS_SLUG2
13
13
  } from "./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-pmxe5c20.js";
10
+ } from "./chunk-8hqdxnxy.js";
11
11
  import {
12
12
  TRANSLATION_STATUS_SLUG2
13
13
  } from "./chunk-31qgv1zk.js";
@@ -107,10 +107,9 @@ var translateOperation2 = async (args) => {
107
107
  payload: args.payload
108
108
  };
109
109
  const { collectionSlug, globalSlug, id, locale, localeFrom, overrideAccess } = args;
110
- const localization = req.payload.config.localization;
111
- const defaultLocale = localization ? localization.defaultLocale : undefined;
112
- if (defaultLocale && locale === defaultLocale) {
113
- throw new APIError3(`Refusing to translate into the default locale "${defaultLocale}" — it is the source of truth. Translate from it into a target locale instead.`, 400);
110
+ const { localization } = req.payload.config;
111
+ if (localization && locale === localization.defaultLocale) {
112
+ throw new APIError3(`Refusing to translate into the default locale "${localization.defaultLocale}" — it is the source of truth. Translate from it into a target locale instead.`, 400);
114
113
  }
115
114
  const { config, doc: dataFrom } = await findEntityWithConfig({
116
115
  collectionSlug,
@@ -124,6 +123,7 @@ var translateOperation2 = async (args) => {
124
123
  if (!resolver)
125
124
  throw new APIError3(`Resolver with the key ${args.resolver} was not found`);
126
125
  const valuesToTranslate = [];
126
+ const syncedValues = { count: 0 };
127
127
  let translatedData = args.data;
128
128
  if (!translatedData) {
129
129
  const { doc } = await findEntityWithConfig({
@@ -146,12 +146,13 @@ var translateOperation2 = async (args) => {
146
146
  fields: config.fields,
147
147
  translatedData,
148
148
  valuesToTranslate,
149
+ syncedValues,
149
150
  _options: req.payload.config.custom?.translator?._options
150
151
  });
151
152
  const entityLabel = `${collectionSlug || globalSlug}#${id ?? ""}`;
152
153
  const direction = `${args.localeFrom}→${args.locale}`;
153
154
  req.payload.logger.info({
154
- 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)` : "")
155
156
  });
156
157
  const resolveResult = valuesToTranslate.length === 0 ? { success: true, translatedTexts: [] } : await resolver.resolve({
157
158
  localeFrom: args.localeFrom,
@@ -194,7 +195,7 @@ ${valuesToTranslate.map((v) => ` ${v.path ?? "(unknown)"}: ${preview(v.value)}`
194
195
  ${summary.join(`
195
196
  `)}` : "")
196
197
  });
197
- if (args.update && valuesToTranslate.length > 0) {
198
+ if (args.update && (valuesToTranslate.length > 0 || syncedValues.count > 0)) {
198
199
  const { _locale, _parent_id, createdAt, updatedAt, ...data } = translatedData;
199
200
  await updateEntity({
200
201
  collectionSlug,
@@ -211,6 +212,7 @@ ${summary.join(`
211
212
  success: true,
212
213
  translatedData,
213
214
  translatedCount: valuesToTranslate.length,
215
+ syncedCount: syncedValues.count,
214
216
  dataFrom
215
217
  };
216
218
  }
@@ -527,7 +529,7 @@ function createTranslateTask2(options = {}) {
527
529
  });
528
530
  return { output: { success: true } };
529
531
  }
530
- if (result.translatedCount === 0) {
532
+ if (result.translatedCount === 0 && result.syncedCount === 0) {
531
533
  req.payload.logger.info({ jobId: job.id, msg: `[translate] ${entityLabel}#${id ?? global} → ${toLocale}: nothing to translate` });
532
534
  return { output: { success: true } };
533
535
  }
@@ -535,7 +537,7 @@ function createTranslateTask2(options = {}) {
535
537
  const { _locale: _dropLocale, _parent_id: _dropParent, updatedAt: _dropUpdatedAt, createdAt: _dropCreatedAt, ...data } = translated;
536
538
  req.payload.logger.info({
537
539
  jobId: job.id,
538
- msg: `[translate] persisting ${entityLabel}#${id ?? global} → ${toLocale}`
540
+ msg: `[translate] persisting ${entityLabel}#${id ?? global} → ${toLocale}` + (result.translatedCount === 0 ? " (field sync only)" : "")
539
541
  });
540
542
  try {
541
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.2",
4
+ "version": "3.3.4",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [