post_translate_paragraph compares unchanged text with the TranslateInput object
Environment
- OS: macOS
- Python: 3.12
- BabelDOC: 0.6.4 and current
mainat38d3896dcde9b5a940c62cf5563cadea673a64d3
Describe the bug
ILTranslator.post_translate_paragraph currently checks:
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:
- Create
ILTranslator.TranslateInput("unchanged", [], None). - Call
post_translate_paragraph(..., translated_text="unchanged")with a tracker whoselast_llm_translate_tracker()returnsNone. - Observe that the method returns
Trueand rebuilds the paragraph composition, although the output equalstranslate_input.unicode.
Expected behavior
Compare against the string payload:
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.
Source: funstory-ai/BabelDOC