@justanarthur/payload-plugin-translator 3.3.0 → 3.3.2

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
@@ -4,7 +4,7 @@ import {
4
4
  } from "./shared/chunk-31qgv1zk.js";
5
5
 
6
6
  // src/client/components/CustomButton/CustomButtonWithTranslator.tsx
7
- import { PublishButton, SaveButton, useConfig as useConfig2, useDocumentInfo as useDocumentInfo2 } from "@payloadcms/ui";
7
+ import { PublishButton, SaveButton, useConfig as useConfig2, useDocumentInfo as useDocumentInfo2, useLocale as useLocale2 } from "@payloadcms/ui";
8
8
 
9
9
  // src/client/providers/Translator/TranslatorProvider.tsx
10
10
  import {
@@ -298,9 +298,14 @@ var CustomButtonWithTranslator = ({ type }) => {
298
298
  const { config } = useConfig2();
299
299
  const DefaultButton = type === "publish" ? PublishButton : SaveButton;
300
300
  const { globalSlug, id } = useDocumentInfo2();
301
+ const locale = useLocale2();
301
302
  const resolvers = config.admin?.custom?.translator?.resolvers ?? [];
302
303
  if (!id && !globalSlug)
303
304
  return /* @__PURE__ */ jsx6(DefaultButton, {});
305
+ const { localization } = config;
306
+ const isSourceLocale = Boolean(localization) && locale.code === localization.defaultLocale;
307
+ if (isSourceLocale)
308
+ return /* @__PURE__ */ jsx6(DefaultButton, {});
304
309
  return /* @__PURE__ */ jsx6(TranslatorProvider, {
305
310
  children: /* @__PURE__ */ jsxs4("div", {
306
311
  className: "translator__custom-save-button",
package/dist/index.js CHANGED
@@ -8,15 +8,15 @@ import {
8
8
  isTranslateMode,
9
9
  createTranslateTask2,
10
10
  createTranslateWorkflow2
11
- } from "./shared/chunk-z55qxmj2.js";
12
- import"./shared/chunk-3rz1t943.js";
11
+ } from "./shared/chunk-kxdj1t2m.js";
12
+ import"./shared/chunk-pmxe5c20.js";
13
13
  import {
14
14
  readLocales,
15
15
  parseEntityKey,
16
16
  hasTranslateWorkflow,
17
17
  queueBulkTranslation,
18
18
  runQueuedTranslations
19
- } from "./shared/chunk-gd0rak8x.js";
19
+ } from "./shared/chunk-xgsxe28w.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-z55qxmj2.js";
6
+ } from "./shared/chunk-kxdj1t2m.js";
7
7
  import {
8
8
  TRANSLATE_TASK_SLUG2,
9
9
  TRANSLATE_WORKFLOW_SLUG2
10
- } from "./shared/chunk-3rz1t943.js";
10
+ } from "./shared/chunk-pmxe5c20.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-3rz1t943.js";
1
+ import"./shared/chunk-pmxe5c20.js";
2
2
  import {
3
3
  readLocales,
4
4
  loadCollectionReview,
5
5
  loadGlobalsReview,
6
6
  loadEntityLocaleReview,
7
7
  loadJobsProgress
8
- } from "./shared/chunk-gd0rak8x.js";
8
+ } from "./shared/chunk-xgsxe28w.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-3rz1t943.js";
10
+ } from "./chunk-pmxe5c20.js";
11
11
  import {
12
12
  TRANSLATION_STATUS_SLUG2
13
13
  } from "./chunk-31qgv1zk.js";
@@ -17,7 +17,8 @@ import he from "he";
17
17
  import { APIError as APIError3 } from "payload";
18
18
 
19
19
  // src/translate/findEntityWithConfig.ts
20
- import { APIError } from "payload";
20
+ import { APIError, isolateObjectProperty } from "payload";
21
+ var isolateReqLocale = (req) => isolateObjectProperty(req, ["locale", "fallbackLocale"]);
21
22
  var findConfigBySlug = (slug, enities) => enities.find((entity) => entity.slug === slug);
22
23
  var findEntityWithConfig = async (args) => {
23
24
  const { collectionSlug, globalSlug, id, locale, overrideAccess, req } = args;
@@ -31,12 +32,13 @@ var findEntityWithConfig = async (args) => {
31
32
  const entityConfig = isGlobal ? findConfigBySlug(globalSlug, config.globals) : findConfigBySlug(collectionSlug, config.collections);
32
33
  if (!entityConfig)
33
34
  throw new APIError("Bad Request", 400);
35
+ const isolatedReq = isolateReqLocale(req);
34
36
  const docPromise = isGlobal ? payload.findGlobal({
35
37
  depth: 0,
36
38
  fallbackLocale: false,
37
39
  locale,
38
40
  overrideAccess,
39
- req,
41
+ req: isolatedReq,
40
42
  slug: args.globalSlug
41
43
  }) : payload.findByID({
42
44
  collection: collectionSlug,
@@ -45,7 +47,7 @@ var findEntityWithConfig = async (args) => {
45
47
  id,
46
48
  locale,
47
49
  overrideAccess,
48
- req
50
+ req: isolatedReq
49
51
  });
50
52
  const doc = await docPromise;
51
53
  return {
@@ -72,13 +74,14 @@ var updateEntity = ({
72
74
  if (!isGlobal && !id)
73
75
  throw new APIError2("Bad Request", 400);
74
76
  const depth = incomingDepth ?? req.payload.config.defaultDepth;
77
+ const isolatedReq = isolateReqLocale(req);
75
78
  const promise = isGlobal ? req.payload.updateGlobal({
76
79
  data,
77
80
  depth,
78
81
  context: { disableAutoTranslate: true },
79
82
  locale,
80
83
  overrideAccess,
81
- req,
84
+ req: isolatedReq,
82
85
  slug: globalSlug
83
86
  }) : req.payload.update({
84
87
  collection: collectionSlug,
@@ -88,7 +91,7 @@ var updateEntity = ({
88
91
  id,
89
92
  locale,
90
93
  overrideAccess,
91
- req
94
+ req: isolatedReq
92
95
  });
93
96
  return promise;
94
97
  };
@@ -104,6 +107,11 @@ var translateOperation2 = async (args) => {
104
107
  payload: args.payload
105
108
  };
106
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);
114
+ }
107
115
  const { config, doc: dataFrom } = await findEntityWithConfig({
108
116
  collectionSlug,
109
117
  globalSlug,
@@ -157,6 +157,7 @@ var buildLocalizedRows = (from, existing, isBlocks, emptyOnly) => {
157
157
  return from.map((row, index) => {
158
158
  const previous = existing[index] && (!isBlocks || existing[index].blockType === row.blockType) ? existing[index] : undefined;
159
159
  return {
160
+ ...structuredClone(row),
160
161
  ...previous ?? {},
161
162
  id: previous?.id ?? ObjectID().toHexString(),
162
163
  ...isBlocks ? { blockType: row.blockType, blockName: row.blockName ?? previous?.blockName } : {}
@@ -377,8 +378,12 @@ var traverseFields = (args) => {
377
378
  const current = siblingDataTranslated[field.name];
378
379
  const richTextPath = joinPath(path, field.name);
379
380
  onField?.({ path: richTextPath, type: "richText", source: richTextDataFrom, target: current });
380
- if (!richTextDataFrom || !hasText(richTextDataFrom))
381
+ if (!richTextDataFrom || !hasText(richTextDataFrom)) {
382
+ if (richTextDataFrom && current === undefined) {
383
+ siblingDataTranslated[field.name] = structuredClone(richTextDataFrom);
384
+ }
381
385
  break;
386
+ }
382
387
  if (keepsTarget(richTextDataFrom, current))
383
388
  break;
384
389
  const isSlate = Array.isArray(richTextDataFrom);
@@ -7,7 +7,7 @@ import {
7
7
  collectTranslatableFields,
8
8
  entityKey,
9
9
  sourceHash
10
- } from "./chunk-3rz1t943.js";
10
+ } from "./chunk-pmxe5c20.js";
11
11
  import {
12
12
  TRANSLATION_STATUS_SLUG2
13
13
  } from "./chunk-31qgv1zk.js";
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.0",
4
+ "version": "3.3.2",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [