FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixed normalize() not wrapping msgstr that exceeds width when keyword prefix is included. by tejas-ae · Pull Request #1270 · python-babel/babel · GitHub

Repository navigation

Fixed normalize() not wrapping msgstr that exceeds width when keyword prefix is included. - #1270

Open
tejas-ae wants to merge 3 commits into
python-babel:masterfrom
tejas-ae:fix/normalize-first-line-offset
Open

tejas-ae wants to merge 3 commits into
python-babel:masterfrom
tejas-ae:fix/normalize-first-line-offset

Conversation

tejas-ae commented May 9, 2026

Copy link
Copy Markdown

Fixes #1266.

Root cause: normalize() checks whether each line of the string exceeds width, but it does not account for the keyword prefix (msgstr , msgid , msgctxt ) that the caller prepends on the same line. A 116-char string with width=120 escapes to 118 chars — under the limit — so it is returned as a single line. The combined output msgstr "..." is 125 chars, which exceeds width=120.

Fix: Add a first_line_offset parameter (default 0) to normalize(). When the escaped string plus first_line_offset would exceed width, the multi-line ""\n"..." form is used, placing the content on its own line where the keyword prefix is absent.

All call sites in generate_po are updated to pass first_line_offset=len(prefix) + len("msgstr ") (and equivalents for msgid, msgctxt, msgid_plural, msgstr[N]).

Before:

msgstr "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrystandard"
# ↑ 125 chars — exceeds -w 120

After:

msgstr ""
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrystandard"
# ↑ msgstr line = 9 chars; content line = 118 chars — both within 120

Two regression tests added to tests/messages/test_pofile.py.

Used an LLM to help trace the root cause and draft the fix; all output verified manually.

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Over-long msgstr not line wrapped when setting --width

1 participant


Back | FazBrowse Home | New Git URL