diff --git a/src/translation.js b/src/translation.js index ceb2221..b35fca7 100644 --- a/src/translation.js +++ b/src/translation.js @@ -645,7 +645,8 @@ export async function translateHTML(htmlContent, targetLanguage, sourceUrl = nul // Debug: log chunk content to see what we're actually translating chunks.forEach((chunk, index) => { - console.log(`Chunk ${index + 1} preview:`, chunk.substring(0, 200) + (chunk.length > 200 ? '...' : '')); + console.log(`Chunk ${index + 1} length: ${chunk.length} chars`); + console.log(`Chunk ${index + 1} preview:`, chunk.substring(0, 400) + (chunk.length > 400 ? '...' : '')); }); // Process chunks in batches to avoid overwhelming the API @@ -659,6 +660,7 @@ export async function translateHTML(htmlContent, targetLanguage, sourceUrl = nul const batchPromises = batch.map((chunk, batchIndex) => { const chunkIndex = i + batchIndex + 1; console.log(`Translating chunk ${chunkIndex}/${chunks.length}`); + console.log(`Chunk ${chunkIndex} content preview:`, chunk.substring(0, 300)); return translateFragment(chunk, targetLanguage); }); @@ -679,9 +681,12 @@ export async function translateHTML(htmlContent, targetLanguage, sourceUrl = nul const originalDoc = originalParser.parseFromString(processedContent, 'text/html'); // Extract only the body content from each translated chunk to avoid stacking full HTML documents - const cleanedChunks = translatedChunks.map(chunk => { + const cleanedChunks = translatedChunks.map((chunk, index) => { + console.log(`Raw translated chunk ${index + 1} preview:`, chunk.substring(0, 500) + '...'); const chunkDoc = new DOMParser().parseFromString(chunk, 'text/html'); - return chunkDoc.body ? chunkDoc.body.innerHTML : chunk; + const bodyContent = chunkDoc.body ? chunkDoc.body.innerHTML : chunk; + console.log(`Extracted body content ${index + 1} preview:`, bodyContent.substring(0, 300) + '...'); + return bodyContent; }); // Replace the body content with reassembled translated chunks