From c83c3402f3498c2e184eb6f3fa4c9a50dc6290cc Mon Sep 17 00:00:00 2001 From: velomovies <22169955+velomovies@users.noreply.github.com> Date: Fri, 1 Aug 2025 16:00:40 +0200 Subject: [PATCH 1/5] feat(deepl): add preserve formatting param --- src/lib/translation-services/deepl.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/translation-services/deepl.ts b/src/lib/translation-services/deepl.ts index 312ceb9..e074675 100644 --- a/src/lib/translation-services/deepl.ts +++ b/src/lib/translation-services/deepl.ts @@ -22,6 +22,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 From b839d1565da78cff848eb9a7e8de308d6c247938 Mon Sep 17 00:00:00 2001 From: velomovies <22169955+velomovies@users.noreply.github.com> Date: Fri, 1 Aug 2025 16:01:26 +0200 Subject: [PATCH 2/5] feat(Config): add option in config screens for Deepl --- src/entrypoints/ConfigScreen/ConfigScreen.tsx | 18 +++++++++++ .../FieldAddonConfigScreen.tsx | 31 ++++++++++++++++++- src/lib/types.ts | 2 ++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/entrypoints/ConfigScreen/ConfigScreen.tsx b/src/entrypoints/ConfigScreen/ConfigScreen.tsx index 8b22ff2..254f5a9 100644 --- a/src/entrypoints/ConfigScreen/ConfigScreen.tsx +++ b/src/entrypoints/ConfigScreen/ConfigScreen.tsx @@ -145,6 +145,24 @@ 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 && ( excludedKeys?: string [TranslationServiceKey.yandexKey]?: string @@ -100,6 +101,7 @@ export type TranslationOptions = { deeplOptions?: { glossaryId?: string formality?: DeeplFormalityLevel + preserveFormatting?: boolean } openAIOptions: { model: string From e8f08853ad88451d72c18a7882ec9e7569c68bc0 Mon Sep 17 00:00:00 2001 From: velomovies <22169955+velomovies@users.noreply.github.com> Date: Fri, 1 Aug 2025 16:01:55 +0200 Subject: [PATCH 3/5] feat(FieldAddon): implement option and send with options --- src/entrypoints/FieldAddon/FieldAddon.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/entrypoints/FieldAddon/FieldAddon.tsx b/src/entrypoints/FieldAddon/FieldAddon.tsx index 731c403..75504a9 100644 --- a/src/entrypoints/FieldAddon/FieldAddon.tsx +++ b/src/entrypoints/FieldAddon/FieldAddon.tsx @@ -88,6 +88,10 @@ export default function FieldAddon({ ctx }: Props) { const deeplGlossaryId = pluginParameters.deeplGlossaryId || pluginGlobalParameters.deeplGlossaryId + const deeplPreserveFormatting = + pluginParameters.deeplPreserveFormatting || + pluginGlobalParameters.deeplPreserveFormatting + const deeplFormalityLevelValue = pluginParameters.deeplFormalityLevel?.value || pluginGlobalParameters.deeplFormalityLevel?.value || @@ -141,6 +145,7 @@ export default function FieldAddon({ ctx }: Props) { deeplOptions: { glossaryId: deeplGlossaryId, formality: deeplFormalityLevelValue, + preserveFormatting: deeplPreserveFormatting, }, openAIOptions: { model: modelValue, From b0262788296bad1074577d1a3cd4bb2d81963f82 Mon Sep 17 00:00:00 2001 From: velomovies <22169955+velomovies@users.noreply.github.com> Date: Fri, 1 Aug 2025 17:09:56 +0200 Subject: [PATCH 4/5] feat(Config): set default and make sure correct value is used --- src/entrypoints/ConfigScreen/ConfigScreen.tsx | 6 +++++- src/entrypoints/FieldAddon/FieldAddon.tsx | 6 ++++-- .../FieldAddonConfigScreen/FieldAddonConfigScreen.tsx | 7 ++++--- src/lib/constants.ts | 2 ++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/entrypoints/ConfigScreen/ConfigScreen.tsx b/src/entrypoints/ConfigScreen/ConfigScreen.tsx index 254f5a9..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' @@ -151,7 +152,10 @@ export default function ConfigScreen({ ctx }: Props) { id="deeplPreserveFormatting" label="Preserve formatting" hint="Sets whether the translation engine should respect the original formatting, even if it would usually correct some aspects." - value={pluginParameters?.deeplPreserveFormatting || false} + value={ + pluginParameters?.deeplPreserveFormatting ?? + defaultDeeplPreserveFormatting + } onChange={(newValue) => { ctx.updatePluginParameters({ ...pluginParameters, diff --git a/src/entrypoints/FieldAddon/FieldAddon.tsx b/src/entrypoints/FieldAddon/FieldAddon.tsx index 75504a9..6d29861 100644 --- a/src/entrypoints/FieldAddon/FieldAddon.tsx +++ b/src/entrypoints/FieldAddon/FieldAddon.tsx @@ -28,6 +28,7 @@ import { } from '../../lib/types' import { deeplFormalityLevelOptions, + defaultDeeplPreserveFormatting, translationFormats, translationServiceOptions, } from '../../lib/constants' @@ -89,8 +90,9 @@ export default function FieldAddon({ ctx }: Props) { pluginParameters.deeplGlossaryId || pluginGlobalParameters.deeplGlossaryId const deeplPreserveFormatting = - pluginParameters.deeplPreserveFormatting || - pluginGlobalParameters.deeplPreserveFormatting + pluginParameters.deeplPreserveFormatting ?? + pluginGlobalParameters.deeplPreserveFormatting ?? + defaultDeeplPreserveFormatting const deeplFormalityLevelValue = pluginParameters.deeplFormalityLevel?.value || diff --git a/src/entrypoints/FieldAddonConfigScreen/FieldAddonConfigScreen.tsx b/src/entrypoints/FieldAddonConfigScreen/FieldAddonConfigScreen.tsx index 394dbd8..3bc7986 100644 --- a/src/entrypoints/FieldAddonConfigScreen/FieldAddonConfigScreen.tsx +++ b/src/entrypoints/FieldAddonConfigScreen/FieldAddonConfigScreen.tsx @@ -9,6 +9,7 @@ import { import { deeplFormalityLevelOptions, + defaultDeeplPreserveFormatting, translationServiceOptions, } from '../../lib/constants' import { @@ -43,9 +44,9 @@ export default function ConfigScreen({ ctx }: Props) { deeplFormalityLevelOptions[0] const selectedPreserveFormatting = - pluginParameters?.deeplPreserveFormatting || - pluginGlobalParameters?.deeplPreserveFormatting || - false + pluginParameters?.deeplPreserveFormatting ?? + pluginGlobalParameters?.deeplPreserveFormatting ?? + defaultDeeplPreserveFormatting const excludedKeys = pluginParameters?.excludedKeys || pluginGlobalParameters?.excludedKeys || '' diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 94516b8..1cae9ab 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -7,6 +7,8 @@ import { SettingOption, } from './types' +export const defaultDeeplPreserveFormatting = false + export const fieldsOptions: SettingOption[] = [ { label: 'String fields', value: DatoFieldType.stringField }, { label: 'Text fields', value: DatoFieldType.textField }, From b245222847ca02adc2f4857f48ce8be549481f75 Mon Sep 17 00:00:00 2001 From: velomovies <22169955+velomovies@users.noreply.github.com> Date: Thu, 7 Aug 2025 16:02:25 +0200 Subject: [PATCH 5/5] feat(deepl.ts): set tag handling to none if preserveFormatting is on --- src/lib/translation-services/deepl.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/translation-services/deepl.ts b/src/lib/translation-services/deepl.ts index e074675..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) {