fix HTML placeholder restoration in parallel chunk translation
This commit is contained in:
parent
eed55b922a
commit
5ddf7d36d7
1 changed files with 10 additions and 2 deletions
|
|
@ -508,10 +508,18 @@ export async function translateHTML(htmlContent, targetLanguage, sourceUrl = nul
|
|||
const chunks = await splitHTMLIntoChunks(processedContent, availableTokens, getSelectedModel());
|
||||
console.log(`Split into ${chunks.length} chunks for parallel translation`);
|
||||
|
||||
// Translate all chunks in parallel for much faster processing
|
||||
// Apply HTML preservation to each chunk individually before translation
|
||||
const translationPromises = chunks.map((chunk, index) => {
|
||||
console.log(`Queued chunk ${index + 1}/${chunks.length} for translation`);
|
||||
return translateText(chunk, targetLanguage);
|
||||
|
||||
// Each chunk gets its own preservation/restoration cycle
|
||||
const { preservedText, preservations } = preserveSpecialContent(chunk);
|
||||
|
||||
// Translate the preserved chunk
|
||||
return translateText(preservedText, targetLanguage).then(translatedChunk => {
|
||||
// Restore special content for this chunk
|
||||
return restoreSpecialContent(translatedChunk, preservations);
|
||||
});
|
||||
});
|
||||
|
||||
// Wait for all translations to complete
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue