diff --git a/src/entrypoints/ConfigScreen/ConfigScreen.tsx b/src/entrypoints/ConfigScreen/ConfigScreen.tsx index 8b22ff2..e6f9467 100644 --- a/src/entrypoints/ConfigScreen/ConfigScreen.tsx +++ b/src/entrypoints/ConfigScreen/ConfigScreen.tsx @@ -9,6 +9,7 @@ import { import { deeplFormalityLevelOptions, + defaultDeeplPreserveFormatting, fieldsOptions, translationServiceOptions, } from '../../lib/constants' @@ -145,6 +146,27 @@ export default function ConfigScreen({ ctx }: Props) { /> )} + {isDeepl && ( + { + ctx.updatePluginParameters({ + ...pluginParameters, + deeplPreserveFormatting: newValue, + }) + + ctx.notice('Settings updated successfully!') + }} + /> + )} + {isDeepl && ( )} + {isDeepl && ( + { + ctx.setParameters({ + ...pluginParameters, + deeplPreserveFormatting: newValue, + }) + + ctx.notice('Settings updated successfully!') + }} + value={selectedPreserveFormatting} + /> + )} + {isDeepl && ( [] = [ { label: 'String fields', value: DatoFieldType.stringField }, { label: 'Text fields', value: DatoFieldType.textField }, diff --git a/src/lib/translation-services/deepl.ts b/src/lib/translation-services/deepl.ts index 312ceb9..58529e3 100644 --- a/src/lib/translation-services/deepl.ts +++ b/src/lib/translation-services/deepl.ts @@ -11,7 +11,13 @@ export default async function translate( const params = new URLSearchParams() params.set('target_lang', options.toLocale) - params.set('tag_handling', options.format === 'html' ? 'html' : 'xml') + + if (options.format === 'html') { + params.set('tag_handling', 'html') + } else if (!options.deeplOptions?.preserveFormatting) { + params.set('tag_handling', 'xml') + } + params.set('text', string) if (options.fromLocale) { @@ -22,6 +28,10 @@ export default async function translate( params.set('glossary_id', options.deeplOptions.glossaryId) } + if (options.deeplOptions?.preserveFormatting) { + params.set('preserve_formatting', '1') + } + if ( options.deeplOptions?.formality && options.deeplOptions.formality !== DeeplFormalityLevel.default diff --git a/src/lib/types.ts b/src/lib/types.ts index e8fd9aa..3b7a05d 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -72,6 +72,7 @@ export type Parameters = { topP?: number prompt?: string deeplGlossaryId?: string + deeplPreserveFormatting?: boolean deeplFormalityLevel?: SettingOption excludedKeys?: string [TranslationServiceKey.yandexKey]?: string @@ -100,6 +101,7 @@ export type TranslationOptions = { deeplOptions?: { glossaryId?: string formality?: DeeplFormalityLevel + preserveFormatting?: boolean } openAIOptions: { model: string