@justanarthur/payload-plugin-translator 1.3.21 → 3.0.3

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.
@@ -0,0 +1,57 @@
1
+ import {
2
+ chunkArray
3
+ } from "./chunk-frnemj69.js";
4
+
5
+ // src/resolvers/libreTranslate.ts
6
+ var localeToCountryCodeMapper = {
7
+ ua: "uk"
8
+ };
9
+ var mapLocale = (incoming) => (incoming in localeToCountryCodeMapper) ? localeToCountryCodeMapper[incoming] : incoming;
10
+ var libreResolver = ({
11
+ apiKey,
12
+ chunkLength = 100,
13
+ url = "https://libretranslate.com/translate"
14
+ }) => {
15
+ return {
16
+ key: "libre",
17
+ resolve: async (args) => {
18
+ const { localeFrom, localeTo, req, texts } = args;
19
+ const apiUrl = url;
20
+ const responses = await Promise.all(chunkArray(texts, chunkLength).map((q) => fetch(apiUrl, {
21
+ body: JSON.stringify({
22
+ api_key: apiKey,
23
+ q,
24
+ source: mapLocale(localeFrom),
25
+ target: mapLocale(localeTo)
26
+ }),
27
+ headers: {
28
+ "Content-Type": "application/json"
29
+ },
30
+ method: "POST"
31
+ }).then(async (res) => {
32
+ const data = await res.json();
33
+ if (!res.ok)
34
+ req.payload.logger.info({
35
+ libreResponse: data,
36
+ message: "An error occurred when trying to translate the data using LibreTranslate API"
37
+ });
38
+ return {
39
+ data,
40
+ success: res.ok
41
+ };
42
+ })));
43
+ if (responses.some((res) => !res.success)) {
44
+ return {
45
+ success: false
46
+ };
47
+ }
48
+ const translatedTexts = responses.flatMap((chunk) => chunk.data.translatedText);
49
+ return {
50
+ success: true,
51
+ translatedTexts
52
+ };
53
+ }
54
+ };
55
+ };
56
+
57
+ export { libreResolver };
package/dist/types.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import { CollectionSlug, GlobalSlug } from "payload";
2
2
  import { PayloadRequest } from "payload";
3
3
  type TranslateResolverArgs = {
4
- /** Locale to translate from */
5
4
  localeFrom: string;
6
- /** Locale to translate to */
7
5
  localeTo: string;
8
6
  req: PayloadRequest;
9
7
  texts: string[];
@@ -19,48 +17,12 @@ type TranslateResolver = {
19
17
  resolve: (args: TranslateResolverArgs) => Promise<TranslateResolverResponse> | TranslateResolverResponse;
20
18
  };
21
19
  type TranslatorConfig = {
22
- /**
23
- * Collections with the enabled translator in the admin UI
24
- */
25
20
  collections: CollectionSlug[];
26
- /**
27
- * Disable the plugin
28
- */
29
21
  disabled?: boolean;
30
- /**
31
- * Globals with the enabled translator in the admin UI
32
- */
33
22
  globals: GlobalSlug[];
34
- /**
35
- * Add resolvers that you want to include, examples on how to write your own in ./plugin/src/resolvers
36
- */
37
23
  resolvers: TranslateResolver[];
38
- /**
39
- * Auto-translate every save in the default locale to the other
40
- * configured locales via Payload's job queue.
41
- *
42
- * When `true`, the plugin:
43
- * - registers `createTranslateTask()` and `createTranslateWorkflow()`
44
- * in `config.jobs` (idempotent — skips if a task/workflow with
45
- * the same slug is already registered, so host-customized
46
- * factories survive),
47
- * - prepends `createAutoTranslateCollectionHook` /
48
- * `createAutoTranslateGlobalHook` to each collection/global
49
- * listed in `collections` / `globals`.
50
- *
51
- * Default: `false`. Public factories stay exported for hosts that
52
- * need per-entity control.
53
- */
54
24
  autoTranslate?: boolean;
55
- /**
56
- * Advanced traversal options. Mirrors the options accepted by the
57
- * internal field walker — keep in sync if you need the latest shape.
58
- */
59
25
  _options?: {
60
- /**
61
- * Hook invoked while walking each rich-text node. Lets you append
62
- * extra text segments to be translated (e.g. custom lexical nodes).
63
- */
64
26
  additionalTraverseRichText?: (args: {
65
27
  onText: (siblingData: Record<string, unknown>, attribute?: string) => void;
66
28
  root: Record<string, unknown>;
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": "1.3.21",
4
+ "version": "3.0.3",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [
@@ -65,15 +65,18 @@
65
65
  "default": "./dist/resolvers/google.js"
66
66
  }
67
67
  },
68
+ "./client.css": "./dist/client.css",
68
69
  "./package.json": "./package.json"
69
70
  },
70
71
  "license": "MIT",
71
- "sideEffects": false,
72
+ "sideEffects": [
73
+ "**/*.css"
74
+ ],
72
75
  "engines": {
73
76
  "node": ">=20"
74
77
  },
75
78
  "scripts": {
76
- "build": "bunup",
79
+ "build": "NODE_ENV=production bunup",
77
80
  "clean": "rm -rf dist .tsbuildinfo",
78
81
  "prepublishOnly": "bun run clean && bun run build"
79
82
  },
@@ -1,5 +0,0 @@
1
- .translator__custom-save-button {
2
- display: flex;
3
- align-items: center;
4
- gap: 10px;
5
- }
@@ -1,76 +0,0 @@
1
- .translator {
2
- &__modal {
3
- display: flex;
4
- position: relative;
5
- justify-content: center;
6
- align-items: center;
7
- width: fit-content;
8
- height: fit-content;
9
- }
10
-
11
- &__wrapper {
12
- display: flex;
13
- position: relative;
14
- flex-direction: column;
15
- gap: var(--base);
16
- z-index: 1;
17
- background: var(--theme-elevation-50);
18
- padding: 50px;
19
- }
20
-
21
- &__content {
22
- display: flex;
23
- flex-direction: column;
24
- align-items: center;
25
- gap: var(--base);
26
- max-width: 400px;
27
-
28
- h2 {
29
- margin: 0;
30
- text-align: center;
31
- }
32
- }
33
-
34
- &__buttons {
35
- display: flex;
36
- justify-content: center;
37
- gap: 10px;
38
- width: 100%;
39
-
40
- button {
41
- margin: 0;
42
- }
43
- }
44
-
45
- &__close {
46
- position: absolute;
47
- top: 10px;
48
- right: 10px;
49
- transition: 0.25s;
50
- cursor: pointer;
51
- width: 32px;
52
- height: 32px;
53
-
54
- &:hover {
55
- opacity: 0.6;
56
- }
57
-
58
- &:before,
59
- &:after {
60
- position: absolute;
61
- left: 15px;
62
- background-color: var(--theme-elevation-800);
63
- width: 2px;
64
- height: 33px;
65
- content: ' ';
66
- }
67
-
68
- &:before {
69
- transform: rotate(45deg);
70
- }
71
-
72
- &:after {
73
- transform: rotate(-45deg);
74
- }
75
- }
76
- }