complete translateTextRaw function to properly separate raw and preserved translation
This commit is contained in:
parent
36828be6ae
commit
7d3e7ec111
1 changed files with 40 additions and 23 deletions
|
|
@ -382,36 +382,53 @@ ${preservedText}`;
|
|||
);
|
||||
}
|
||||
|
||||
// Check if placeholders are still in the response
|
||||
preservations.forEach((item, _index) => {
|
||||
const found = translatedText.includes(item.placeholder);
|
||||
console.log(
|
||||
` Placeholder ${item.placeholder} found in response: ${found}`,
|
||||
);
|
||||
});
|
||||
// Return raw translated text without restoration (for chunked translations)
|
||||
console.log("=== RAW TRANSLATION RESULT ===");
|
||||
console.log(`Raw translated length: ${translatedText.length} characters`);
|
||||
|
||||
// Restore preserved content
|
||||
const restored = restoreSpecialContent(translatedText, preservations);
|
||||
console.log("Restored text length:", restored.length);
|
||||
// Only log full text in debug mode, otherwise just show length
|
||||
if (restored.length < 500) {
|
||||
console.log("Restored text:", restored);
|
||||
} else {
|
||||
console.log("Restored text preview:", restored.substring(0, 100) + "...");
|
||||
}
|
||||
|
||||
// Final validation
|
||||
if (!restored || restored.length === 0) {
|
||||
throw new Error("Translation processing failed. Please try again.");
|
||||
}
|
||||
|
||||
return restored;
|
||||
return translatedText;
|
||||
} catch (error) {
|
||||
console.error("Translation error:", error);
|
||||
throw new Error("Translation failed. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
// Translate text using Hermes AI with minimal system context
|
||||
export async function translateText(text, targetLanguage) {
|
||||
const { preservedText, preservations } = preserveSpecialContent(text);
|
||||
|
||||
// Use raw translation function
|
||||
const translatedText = await translateTextRaw(preservedText, targetLanguage);
|
||||
|
||||
// Check if placeholders are still in the response
|
||||
preservations.forEach((item, _index) => {
|
||||
const found = translatedText.includes(item.placeholder);
|
||||
console.log(
|
||||
` Placeholder ${item.placeholder} found in response: ${found}`,
|
||||
);
|
||||
});
|
||||
|
||||
// Restore preserved content
|
||||
const restored = restoreSpecialContent(translatedText, preservations);
|
||||
console.log("Restored text length:", restored.length);
|
||||
// Only log full text in debug mode, otherwise just show length
|
||||
if (restored.length < 500) {
|
||||
console.log("Restored text:", restored);
|
||||
} else {
|
||||
console.log("Restored text preview:", restored.substring(0, 100) + "...");
|
||||
}
|
||||
|
||||
// Final validation
|
||||
if (!restored || restored.length === 0) {
|
||||
throw new Error("Translation processing failed. Please try again.");
|
||||
}
|
||||
|
||||
console.log("=== FINAL RESULT ===");
|
||||
console.log(`Final translated length: ${restored.length} characters`);
|
||||
|
||||
return restored;
|
||||
}
|
||||
|
||||
// Extract page content for translation
|
||||
export function extractPageContent() {
|
||||
// Clone the document to avoid modifying the original
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue