#610·BabelDOC

post_translate_paragraph compares unchanged text with the TranslateInput object

Author: hazugi2004Created Aug 19, 2026Updated Aug 19, 2026

Environment

  • OS: macOS
  • Python: 3.12
  • BabelDOC: 0.6.4 and current main at 38d3896dcde9b5a940c62cf5563cadea673a64d3

Describe the bug

ILTranslator.post_translate_paragraph currently checks:

python
if translated_text == translate_input:

translated_text is a str, while translate_input is an ILTranslator.TranslateInput object. The unchanged-output branch is therefore unreachable for a normal TranslateInput, even when the translator returns exactly translate_input.unicode.

The method then replaces paragraph.unicode and rebuilds pdf_paragraph_composition. For callers that intentionally preserve a paragraph by returning its input unchanged, this needlessly re-typesets the paragraph instead of retaining its original layout objects.

This is distinct from #554: that issue concerns the LLM same-text fallback policy before post-processing. This issue concerns the direct type mismatch inside post_translate_paragraph after an unchanged result has already been accepted.

Minimal reproduction

The condition can be reproduced without a particular PDF or network call:

  1. Create ILTranslator.TranslateInput("unchanged", [], None).
  2. Call post_translate_paragraph(..., translated_text="unchanged") with a tracker whose last_llm_translate_tracker() returns None.
  3. Observe that the method returns True and rebuilds the paragraph composition, although the output equals translate_input.unicode.

Expected behavior

Compare against the string payload:

python
if translated_text == translate_input.unicode:

The method should return False and leave the paragraph's original unicode/composition objects unchanged.

Downstream evidence

A local 27-page line-numbered scientific manuscript used an exact-preserve reference policy. All preserved reference targets equaled their sources, but BabelDOC still re-typeset those paragraphs and merged manuscript margin line numbers into the bibliography flow. The document is copyrighted and is not attached or redistributed; the type mismatch and regression test are independent of that file.

I can submit a one-line fix plus a focused unit regression if maintainers agree with this behavior.