@purposeinplay/payload-ai-translate 0.1.3 → 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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purposeinplay/payload-ai-translate",
|
|
3
|
-
"version": "0.1.
|
|
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",
|
|
@@ -41,6 +41,9 @@
|
|
|
41
41
|
"files": [
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
44
47
|
"peerDependencies": {
|
|
45
48
|
"@ai-sdk/anthropic": "^3.0.0",
|
|
46
49
|
"@ai-sdk/google": "^3.0.0",
|