solid-translate 1.4.4 → 1.4.5
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.
|
@@ -73,15 +73,19 @@ async function translateBatch(model, entries, targetLocale, sourceLocale, system
|
|
|
73
73
|
contextSection,
|
|
74
74
|
JSON.stringify(entries, null, 2)
|
|
75
75
|
].join("\n");
|
|
76
|
-
const attempt = async (prompt) => {
|
|
76
|
+
const attempt = async (prompt, keyCount) => {
|
|
77
77
|
const { text } = await generateText({
|
|
78
78
|
model,
|
|
79
79
|
system: systemPrompt || defaultSystem,
|
|
80
|
-
prompt
|
|
80
|
+
prompt,
|
|
81
|
+
// Provider-default output ceilings (often 4k tokens) truncate large
|
|
82
|
+
// batches mid-JSON ("Unterminated string in JSON"). Scale the ceiling
|
|
83
|
+
// with batch size so the full object always fits.
|
|
84
|
+
maxTokens: Math.min(32e3, 2e3 + 400 * keyCount)
|
|
81
85
|
});
|
|
82
86
|
return collectBatchTranslations(extractJsonObject(text), keys);
|
|
83
87
|
};
|
|
84
|
-
let { translations, missing } = await attempt(basePrompt);
|
|
88
|
+
let { translations, missing } = await attempt(basePrompt, keys.length);
|
|
85
89
|
if (missing.length > 0) {
|
|
86
90
|
const retryEntries = {};
|
|
87
91
|
for (const key of missing) retryEntries[key] = entries[key];
|
|
@@ -91,7 +95,8 @@ async function translateBatch(model, entries, targetLocale, sourceLocale, system
|
|
|
91
95
|
`Respond with ONLY a JSON object \u2014 no prose, no code fences \u2014 containing the exact same keys and the translated values.`,
|
|
92
96
|
contextSection,
|
|
93
97
|
JSON.stringify(retryEntries, null, 2)
|
|
94
|
-
].join("\n")
|
|
98
|
+
].join("\n"),
|
|
99
|
+
missing.length
|
|
95
100
|
);
|
|
96
101
|
translations = { ...translations, ...retry.translations };
|
|
97
102
|
missing = retry.missing;
|
|
@@ -123,6 +128,9 @@ async function translateMarkdown(model, content, targetLocale, sourceLocale, sys
|
|
|
123
128
|
translated: z.string()
|
|
124
129
|
}),
|
|
125
130
|
system: systemPrompt || defaultSystem,
|
|
131
|
+
// Scale the output ceiling with document size so long documents are not
|
|
132
|
+
// truncated by provider-default limits.
|
|
133
|
+
maxTokens: Math.min(32e3, 2e3 + Math.ceil(content.length / 2)),
|
|
126
134
|
prompt: [
|
|
127
135
|
`Translate this Markdown/MDX content from "${sourceLocale}" to "${targetLocale}".`,
|
|
128
136
|
`Return the complete translated document.`,
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
translateBatch
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-36PYT2MX.js";
|
|
5
5
|
import {
|
|
6
6
|
__commonJS,
|
|
7
7
|
__toESM
|
|
@@ -15570,7 +15570,7 @@ Run \`solid-translate translate\` to refresh ${sourceLocale} \u2192 targets.`
|
|
|
15570
15570
|
);
|
|
15571
15571
|
}
|
|
15572
15572
|
async function runTranslate() {
|
|
15573
|
-
const { translateBatch: translateBatch2, translateMarkdown: translateMarkdown2 } = await import("./translate-
|
|
15573
|
+
const { translateBatch: translateBatch2, translateMarkdown: translateMarkdown2 } = await import("./translate-PTFH3PFU.js");
|
|
15574
15574
|
const config = await loadConfig();
|
|
15575
15575
|
const root = process.cwd();
|
|
15576
15576
|
const sourceLocale = config.sourceLocale || "en";
|
package/dist/vite.js
CHANGED
|
@@ -14684,15 +14684,19 @@ async function translateBatch(model, entries, targetLocale, sourceLocale, system
|
|
|
14684
14684
|
contextSection,
|
|
14685
14685
|
JSON.stringify(entries, null, 2)
|
|
14686
14686
|
].join("\n");
|
|
14687
|
-
const attempt = async (prompt) => {
|
|
14687
|
+
const attempt = async (prompt, keyCount) => {
|
|
14688
14688
|
const { text } = await generateText({
|
|
14689
14689
|
model,
|
|
14690
14690
|
system: systemPrompt || defaultSystem,
|
|
14691
|
-
prompt
|
|
14691
|
+
prompt,
|
|
14692
|
+
// Provider-default output ceilings (often 4k tokens) truncate large
|
|
14693
|
+
// batches mid-JSON ("Unterminated string in JSON"). Scale the ceiling
|
|
14694
|
+
// with batch size so the full object always fits.
|
|
14695
|
+
maxTokens: Math.min(32e3, 2e3 + 400 * keyCount)
|
|
14692
14696
|
});
|
|
14693
14697
|
return collectBatchTranslations(extractJsonObject(text), keys);
|
|
14694
14698
|
};
|
|
14695
|
-
let { translations, missing } = await attempt(basePrompt);
|
|
14699
|
+
let { translations, missing } = await attempt(basePrompt, keys.length);
|
|
14696
14700
|
if (missing.length > 0) {
|
|
14697
14701
|
const retryEntries = {};
|
|
14698
14702
|
for (const key of missing) retryEntries[key] = entries[key];
|
|
@@ -14702,7 +14706,8 @@ async function translateBatch(model, entries, targetLocale, sourceLocale, system
|
|
|
14702
14706
|
`Respond with ONLY a JSON object \u2014 no prose, no code fences \u2014 containing the exact same keys and the translated values.`,
|
|
14703
14707
|
contextSection,
|
|
14704
14708
|
JSON.stringify(retryEntries, null, 2)
|
|
14705
|
-
].join("\n")
|
|
14709
|
+
].join("\n"),
|
|
14710
|
+
missing.length
|
|
14706
14711
|
);
|
|
14707
14712
|
translations = { ...translations, ...retry.translations };
|
|
14708
14713
|
missing = retry.missing;
|