diff --git a/apps/readest-app/src/pages/api/deepl/translate.ts b/apps/readest-app/src/pages/api/deepl/translate.ts index 45a726f7..c3a39ed4 100644 --- a/apps/readest-app/src/pages/api/deepl/translate.ts +++ b/apps/readest-app/src/pages/api/deepl/translate.ts @@ -183,12 +183,21 @@ async function callDeepLAPI( // TODO: this should be processed in the client, but for now, we need to do it here // please remove this when most clients are updated const input = text.replaceAll('\n', '').trim(); - const requestBody = { + + const requestBody: { + text: string | string[]; + target_lang: string; + source_lang?: string; + } = { text: isV2Api ? [input] : input, source_lang: isV2Api ? sourceLang : (LANG_V2_V1_MAP[sourceLang] ?? sourceLang), target_lang: isV2Api ? targetLang : (LANG_V2_V1_MAP[targetLang] ?? targetLang), }; + if (isV2Api && requestBody.source_lang?.toUpperCase() === 'AUTO') { + delete requestBody.source_lang; + } + const response = await fetch(apiUrl, { method: 'POST', headers: { diff --git a/apps/readest-app/src/services/translators/providers/deepl.ts b/apps/readest-app/src/services/translators/providers/deepl.ts index a2710821..3d3ec337 100644 --- a/apps/readest-app/src/services/translators/providers/deepl.ts +++ b/apps/readest-app/src/services/translators/providers/deepl.ts @@ -36,9 +36,10 @@ export const deeplProvider: TranslationProvider = { throw new Error('Authentication token is required for DeepL translation'); } + const normalizedSourceLang = normalizeToShortLang(sourceLang).toUpperCase(); const body = JSON.stringify({ text: text, - source_lang: normalizeToShortLang(sourceLang).toUpperCase(), + ...(normalizedSourceLang !== 'AUTO' ? { source_lang: normalizedSourceLang } : {}), target_lang: normalizeToShortLang(targetLang).toUpperCase(), use_cache: useCache, });