Skip to content

fix: send HTML tag handling to DeepL so notranslate works - #16

Merged
Halvanhelv merged 1 commit into
mainfrom
fix/deepl-tag-handling
Sep 8, 2026
Merged

Halvanhelv merged 1 commit into
mainfrom
fix/deepl-tag-handling

Conversation

@Halvanhelv

Copy link
Copy Markdown
Owner

The DeepL provider sent no tag_handling. Per DeepL's documentation, "Without tag_handling, tags are treated as regular text" — and class="notranslate", which DeepL does honour, is honoured only under HTML tag handling.

The tokenizer hands a notranslate span to the provider whole, tags included, precisely so the provider can leave its contents alone. It could not.

Confirmed against the live API

"<span class='notranslate'>Bold Mountain</span> is a good place."

no tag_handling ->  "<span class='notranslate'>Болд-Маунтин</span> — отличное место."
tag_handling    ->  "<span class='notranslate'>Bold Mountain</span> — это хорошее место."

Note what the first line does: the span's tags survive untouched and only the protected name is translated. Nothing about the output looks wrong — which is why this went unnoticed. tag_handling appears nowhere in this repository's history, so notranslate has not worked for a single day since the gem moved from Google to DeepL.

The change

tag_handling: :html and tag_handling_version: "v2" (the algorithm DeepL's docs recommend) are sent as defaults a caller can override, the way every other provider option works.

Under HTML tag handling DeepL defaults split_sentences to nonewlines; this library sends one sentence per value, so that changes nothing here.

Detection is left alone: it sends a 100-character sample that may end mid-tag, and DeepL never strictly parses HTML anyway.

Verification

  • 229 runs, 492 assertions, 0 failures, on seeds 1, 99 and 4242. RuboCop clean on 52 files.
  • Live end-to-end through the gem:
"<span class='notranslate'>Bold Mountain</span> is a good place."
→ "<span class='notranslate'>Bold Mountain</span> — это хорошее место."

"<!-- internal note --> Visible text here."
→ "<!-- internal note --> Здесь отображается текст."

"Salt &amp; pepper. Fine."
→ "Соль и перец. Хорошо."

The DeepL provider sent no `tag_handling` at all. Per DeepL's own
documentation, "Without `tag_handling`, tags are treated as regular
text" -- and `class="notranslate"`, which DeepL does honour, is honoured
only under HTML tag handling. The tokenizer hands a notranslate span to
the provider whole, tags included, precisely so the provider can leave
its contents alone. It could not.

Confirmed against the live API:

    "<span class='notranslate'>Bold Mountain</span> is a good place."
    no tag_handling -> "<span class='notranslate'>Болд-Маунтин</span> — отличное место."
    tag_handling    -> "<span class='notranslate'>Bold Mountain</span> — это хорошее место."

Note what the first line does: the span's tags survive untouched and only
the protected name is translated. Nothing about the output looks wrong,
which is why this went unnoticed -- `tag_handling` appears nowhere in this
repository's history, so notranslate has not worked for a single day since
the gem moved from Google to DeepL.

Both values are sent as defaults a caller can override, the way every
other provider option works. Under HTML tag handling DeepL defaults
`split_sentences` to `nonewlines`; this library sends one sentence per
value, so that changes nothing here.

Detection is left alone: it sends a 100-character sample that may end
mid-tag, and DeepL never strictly parses HTML anyway.
@Halvanhelv
Halvanhelv merged commit 981fea7 into main Sep 8, 2026
5 checks passed
@Halvanhelv
Halvanhelv deleted the fix/deepl-tag-handling branch September 8, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant