@purposeinplay/payload-ai-translate 0.1.2 → 0.1.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.
@@ -188,8 +188,32 @@ function extractJsonUnits(obj, basePath, excludePatterns, units) {
188
188
  } else if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
189
189
  // Recurse into nested objects
190
190
  extractJsonUnits(value, fieldPath, excludePatterns, units);
191
+ } else if (Array.isArray(value)) {
192
+ // Arrays of strings (e.g. `advantages: ["a", "b"]`) and arrays of
193
+ // objects are translated at indexed paths, mirroring the blocks
194
+ // walker. Numbers/booleans/null items are passed through.
195
+ extractJsonArrayUnits(value, fieldPath, excludePatterns, units);
196
+ }
197
+ // Skip numbers, booleans, nulls — not translatable
198
+ }
199
+ }
200
+ function extractJsonArrayUnits(arr, basePath, excludePatterns, units) {
201
+ for(let i = 0; i < arr.length; i++){
202
+ const item = arr[i];
203
+ const itemPath = `${basePath}.${i}`;
204
+ if (isExcluded(itemPath, excludePatterns)) continue;
205
+ if (typeof item === 'string' && item.trim().length > 0) {
206
+ units.push({
207
+ id: `${itemPath}::0`,
208
+ fieldPath: itemPath,
209
+ text: item,
210
+ kind: 'plain'
211
+ });
212
+ } else if (item !== null && typeof item === 'object' && !Array.isArray(item)) {
213
+ extractJsonUnits(item, itemPath, excludePatterns, units);
214
+ } else if (Array.isArray(item)) {
215
+ extractJsonArrayUnits(item, itemPath, excludePatterns, units);
191
216
  }
192
- // Skip arrays, numbers, booleans, nulls — not translatable
193
217
  }
194
218
  }
195
219
  // ---------------------------------------------------------------------------
@@ -97,6 +97,22 @@ function patchJsonValues(obj, basePath, translatedUnits) {
97
97
  obj[key] = translated;
98
98
  } else if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
99
99
  patchJsonValues(value, fieldPath, translatedUnits);
100
+ } else if (Array.isArray(value)) {
101
+ patchJsonArrayValues(value, fieldPath, translatedUnits);
102
+ }
103
+ }
104
+ }
105
+ function patchJsonArrayValues(arr, basePath, translatedUnits) {
106
+ for(let i = 0; i < arr.length; i++){
107
+ const item = arr[i];
108
+ const itemPath = `${basePath}.${i}`;
109
+ if (typeof item === 'string') {
110
+ const translated = translatedUnits.get(`${itemPath}::0`);
111
+ if (translated !== undefined) arr[i] = translated;
112
+ } else if (item !== null && typeof item === 'object' && !Array.isArray(item)) {
113
+ patchJsonValues(item, itemPath, translatedUnits);
114
+ } else if (Array.isArray(item)) {
115
+ patchJsonArrayValues(item, itemPath, translatedUnits);
100
116
  }
101
117
  }
102
118
  }
package/package.json CHANGED
@@ -1,97 +1,48 @@
1
1
  {
2
2
  "name": "@purposeinplay/payload-ai-translate",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "AI translation plugin for Payload CMS 3 — multi-provider (OpenAI, Anthropic, Gemini, custom), bulk translation, Lexical-aware, with an admin Translation Hub.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "packageManager": "pnpm@9.15.0",
8
- "main": "./src/exports/index.ts",
9
- "types": "./src/exports/index.ts",
7
+ "main": "./dist/exports/index.js",
8
+ "types": "./dist/exports/index.d.ts",
10
9
  "exports": {
11
10
  ".": {
12
- "types": "./src/exports/index.ts",
13
- "import": "./src/exports/index.ts",
14
- "default": "./src/exports/index.ts"
11
+ "types": "./dist/exports/index.d.ts",
12
+ "import": "./dist/exports/index.js",
13
+ "default": "./dist/exports/index.js"
15
14
  },
16
15
  "./providers": {
17
- "types": "./src/exports/providers.ts",
18
- "import": "./src/exports/providers.ts",
19
- "default": "./src/exports/providers.ts"
16
+ "types": "./dist/exports/providers.d.ts",
17
+ "import": "./dist/exports/providers.js",
18
+ "default": "./dist/exports/providers.js"
20
19
  },
21
20
  "./views": {
22
- "types": "./src/exports/views.ts",
23
- "import": "./src/exports/views.ts",
24
- "default": "./src/exports/views.ts"
21
+ "types": "./dist/exports/views.d.ts",
22
+ "import": "./dist/exports/views.js",
23
+ "default": "./dist/exports/views.js"
25
24
  },
26
25
  "./views-client": {
27
- "types": "./src/exports/views-client.ts",
28
- "import": "./src/exports/views-client.ts",
29
- "default": "./src/exports/views-client.ts"
26
+ "types": "./dist/exports/views-client.d.ts",
27
+ "import": "./dist/exports/views-client.js",
28
+ "default": "./dist/exports/views-client.js"
30
29
  },
31
30
  "./client": {
32
- "types": "./src/exports/client.ts",
33
- "import": "./src/exports/client.ts",
34
- "default": "./src/exports/client.ts"
31
+ "types": "./dist/exports/client.d.ts",
32
+ "import": "./dist/exports/client.js",
33
+ "default": "./dist/exports/client.js"
35
34
  },
36
35
  "./components": {
37
- "types": "./src/exports/components.ts",
38
- "import": "./src/exports/components.ts",
39
- "default": "./src/exports/components.ts"
36
+ "types": "./dist/exports/components.d.ts",
37
+ "import": "./dist/exports/components.js",
38
+ "default": "./dist/exports/components.js"
40
39
  }
41
40
  },
42
41
  "files": [
43
42
  "dist"
44
43
  ],
45
44
  "publishConfig": {
46
- "main": "./dist/exports/index.js",
47
- "types": "./dist/exports/index.d.ts",
48
- "exports": {
49
- ".": {
50
- "types": "./dist/exports/index.d.ts",
51
- "import": "./dist/exports/index.js",
52
- "default": "./dist/exports/index.js"
53
- },
54
- "./providers": {
55
- "types": "./dist/exports/providers.d.ts",
56
- "import": "./dist/exports/providers.js",
57
- "default": "./dist/exports/providers.js"
58
- },
59
- "./views": {
60
- "types": "./dist/exports/views.d.ts",
61
- "import": "./dist/exports/views.js",
62
- "default": "./dist/exports/views.js"
63
- },
64
- "./views-client": {
65
- "types": "./dist/exports/views-client.d.ts",
66
- "import": "./dist/exports/views-client.js",
67
- "default": "./dist/exports/views-client.js"
68
- },
69
- "./client": {
70
- "types": "./dist/exports/client.d.ts",
71
- "import": "./dist/exports/client.js",
72
- "default": "./dist/exports/client.js"
73
- },
74
- "./components": {
75
- "types": "./dist/exports/components.d.ts",
76
- "import": "./dist/exports/components.js",
77
- "default": "./dist/exports/components.js"
78
- }
79
- }
80
- },
81
- "scripts": {
82
- "build": "pnpm run build:types && pnpm run build:swc && pnpm run build:fix-esm",
83
- "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly --outDir dist",
84
- "build:swc": "swc ./src -d ./dist --config-file ./.swcrc --strip-leading-paths --ignore \"**/__tests__/**\"",
85
- "build:fix-esm": "node ./scripts/fix-dist-extensions.mjs dist && node ./scripts/check-dist-esm.mjs dist",
86
- "typecheck": "tsc -p tsconfig.json --noEmit",
87
- "test": "vitest run",
88
- "lint": "biome check .",
89
- "format": "biome format --write .",
90
- "check": "biome check . && pnpm typecheck && pnpm build && pnpm test",
91
- "clean": "rm -rf dist *.tsbuildinfo",
92
- "changeset": "changeset",
93
- "version-packages": "changeset version",
94
- "release": "pnpm build && changeset publish"
45
+ "access": "public"
95
46
  },
96
47
  "peerDependencies": {
97
48
  "@ai-sdk/anthropic": "^3.0.0",
@@ -174,5 +125,20 @@
174
125
  "openai",
175
126
  "anthropic",
176
127
  "gemini"
177
- ]
178
- }
128
+ ],
129
+ "scripts": {
130
+ "build": "pnpm run build:types && pnpm run build:swc && pnpm run build:fix-esm",
131
+ "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly --outDir dist",
132
+ "build:swc": "swc ./src -d ./dist --config-file ./.swcrc --strip-leading-paths --ignore \"**/__tests__/**\"",
133
+ "build:fix-esm": "node ./scripts/fix-dist-extensions.mjs dist && node ./scripts/check-dist-esm.mjs dist",
134
+ "typecheck": "tsc -p tsconfig.json --noEmit",
135
+ "test": "vitest run",
136
+ "lint": "biome check .",
137
+ "format": "biome format --write .",
138
+ "check": "biome check . && pnpm typecheck && pnpm build && pnpm test",
139
+ "clean": "rm -rf dist *.tsbuildinfo",
140
+ "changeset": "changeset",
141
+ "version-packages": "changeset version",
142
+ "release": "pnpm build && changeset publish"
143
+ }
144
+ }