From 36828be6ae56cef30adeb05f0d0e12b6e2b0ebe7 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Fri, 11 Jul 2025 20:18:46 -0400 Subject: [PATCH] fix double HTML preservation in chunked translations by using raw translate function --- src/translation.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/translation.js b/src/translation.js index 05c3814..6a8f3de 100644 --- a/src/translation.js +++ b/src/translation.js @@ -304,13 +304,14 @@ export function estimateProcessingTime(tokenCount) { return Math.ceil(totalTime); } -// Translate text using Hermes AI with minimal system context -export async function translateText(text, targetLanguage) { +// Internal function to translate text without preservation (for chunked translations) +async function translateTextRaw(text, targetLanguage) { // Ensure models are loaded before translation const { fetchModelsFromEndpoints } = await import("./models.js"); await fetchModelsFromEndpoints(); - const { preservedText, preservations } = preserveSpecialContent(text); + // Skip preservation - assume text is already preserved + const preservedText = text; // Build the actual prompt that will be sent to the AI const prompt = `Translate the following HTML content into ${SUPPORTED_LANGUAGES[targetLanguage]}. The input is in English and formatted as HTML, which includes formatting, code blocks, and technical content. Ensure the output preserves the structure, syntax, and formatting of the original. Do not translate or modify placeholders like __CODE_0__, __URI_0__, __HTML_0__, etc., as they represent code blocks, URLs, or HTML elements that should remain unchanged. Only translate the surrounding text. Here is the text to translate: @@ -515,8 +516,8 @@ export async function translateHTML(htmlContent, targetLanguage, sourceUrl = nul // Each chunk gets its own preservation/restoration cycle const { preservedText, preservations } = preserveSpecialContent(chunk); - // Translate the preserved chunk - return translateText(preservedText, targetLanguage).then(translatedChunk => { + // Translate the preserved chunk using raw function (no double preservation) + return translateTextRaw(preservedText, targetLanguage).then(translatedChunk => { // Restore special content for this chunk return restoreSpecialContent(translatedChunk, preservations); });