Skip to content

Preserve translator comments for same-line Python calls - #1476

Open
Yin123-ybh wants to merge 1 commit into
python-babel:masterfrom
Yin123-ybh:fix/1475-python-same-line-comments
Open

Yin123-ybh wants to merge 1 commit into
python-babel:masterfrom
Yin123-ybh:fix/1475-python-same-line-comments

Conversation

@Yin123-ybh

Copy link
Copy Markdown

Fixes #1475

When a source line contains multiple translation calls, the Python extractor clears the preceding translator comment after the first call. For example, in operators = (_('IS'), _('NOT')), only IS receives the comment.

Keep the comment available for sibling calls beginning on the same line, then discard it before moving to another line. Preserve the existing comment behavior for translation calls nested inside another translation call. Add regression coverage for sibling calls, semicolons, wrapping, comment-tag stripping, and separate comment blocks, plus a documentation example.

Validation on Python 3.12.9 with CLDR 49 imported through the repository script

  • The nine new regression cases fail before the fix.
  • Full suite python -m pytest -q passes with 8,229 passed, 3 skipped, and 2 xfailed.
  • ruff check babel/messages/extract.py tests/messages/test_extract_python.py passes with Ruff 0.14.10.
  • python -m build successfully builds the sdist and wheel.
  • git diff --check passes.

Prepared with OpenAI Codex assistance.

This branch has not been deployed

No deployments
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.

Attaching context to multiple messages located in the same string

1 participant