export async function translateHtml(htmlContent, sourceLang, targetLang, env) {
try {
console.log('Translating HTML content...');
console.log(htmlContent);
const authKey = getEnvironmentVariable('DEEPL_API_KEY', env);
const response = await fetch('https://api-free.deepl.com/v2/translate', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
auth_key: authKey,
text: htmlContent,
source_lang: sourceLang.toUpperCase(),
target_lang: targetLang.toUpperCase(),
tag_handling: 'xml', // Ensure HTML/XML tags are preserved
}),
});
// Check if the response is successful
if (!response.ok) {
const errorText = await response.text();
console.error(
export async function translateHtml(htmlContent, sourceLang, targetLang, env) {
try {
console.log('Translating HTML content...');
console.log(htmlContent);
const authKey = getEnvironmentVariable('DEEPL_API_KEY', env);
const response = await fetch('https://api-free.deepl.com/v2/translate', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
auth_key: authKey,
text: htmlContent,
source_lang: sourceLang.toUpperCase(),
target_lang: targetLang.toUpperCase(),
tag_handling: 'xml', // Ensure HTML/XML tags are preserved
}),
});
// Check if the response is successful
if (!response.ok) {
const errorText = await response.text();
console.error(