Skip to content

Preserve nonconsecutive repeated comment lines - #1348

Open
berkay-byte wants to merge 1 commit into
python-babel:masterfrom
berkay-byte:fix-po-duplicate-comment-lines
Open

berkay-byte wants to merge 1 commit into
python-babel:masterfrom
berkay-byte:fix-po-duplicate-comment-lines

Conversation

@berkay-byte

@berkay-byte berkay-byte commented Sep 18, 2026

Copy link
Copy Markdown

Closes #417.

Two long comments beginning with KEY: can wrap onto separate lines when written to a PO file. Reading that file removes the second KEY: because Message.__init__() deduplicates comments across the entire list.

Use itertools.groupby in Message.__init__() to collapse only consecutive identical comments. Repeated lines separated by other text keep their positions. Both extracted and translator comments follow this rule, including when messages are cloned. PO parsing continues to use the constructor normally.

Tests cover consecutive and separated repeats, empty comments, iterator inputs, cloning, obsolete PO entries, and wrapped-comment round trips. Existing catalog-merge deduplication remains unchanged.

Prepared with OpenAI Codex assistance.

Validation: 7,844 tests passed, 9 skipped, 2 expected failures on Python 3.14. Repository pre-commit checks passed for the changed files.

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I don't know the rationale for the "only write unique comments" commit from nearly 20 years ago fdb3468, I think there may have been something to it.

To fix the issue in #417, namely

#. KEY:
#. foo.bar.baz...<long words more>...
#. KEY:
#. waldo.fred.plugh...<long words more>...

losing the second KEY:, I think a better patch would be to adjust Message.__init__() to keep only one copy of the same line repeated. What do you think?

@berkay-byte
berkay-byte force-pushed the fix-po-duplicate-comment-lines branch from 8bfa0a8 to 155c599 Compare September 18, 2026 14:23
@berkay-byte berkay-byte changed the title Fix repeated comment lines being lost when reading PO files Preserve nonconsecutive repeated comment lines Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't remove duplicated comment lines.

2 participants