@justanarthur/payload-plugin-translator 3.3.0 → 3.3.1

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,7 +8,7 @@ import {
8
8
  isTranslateMode,
9
9
  createTranslateTask2,
10
10
  createTranslateWorkflow2
11
- } from "./shared/chunk-z55qxmj2.js";
11
+ } from "./shared/chunk-hg50cgsw.js";
12
12
  import"./shared/chunk-3rz1t943.js";
13
13
  import {
14
14
  readLocales,
package/dist/jobs.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  createAutoTranslateGlobalHook2,
4
4
  createTranslateTask2,
5
5
  createTranslateWorkflow2
6
- } from "./shared/chunk-z55qxmj2.js";
6
+ } from "./shared/chunk-hg50cgsw.js";
7
7
  import {
8
8
  TRANSLATE_TASK_SLUG2,
9
9
  TRANSLATE_WORKFLOW_SLUG2
@@ -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,
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.1",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [