Fixed normalize() not wrapping msgstr that exceeds width when keyword prefix is included.#1270
Open
tejasae-afk wants to merge 3 commits intopython-babel:masterfrom
Open
Conversation
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1266.
Root cause:
normalize()checks whether each line of the string exceedswidth, but it does not account for the keyword prefix (msgstr,msgid,msgctxt) that the caller prepends on the same line. A 116-char string withwidth=120escapes to 118 chars — under the limit — so it is returned as a single line. The combined outputmsgstr "..."is 125 chars, which exceedswidth=120.Fix: Add a
first_line_offsetparameter (default0) tonormalize(). When the escaped string plusfirst_line_offsetwould exceedwidth, 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_poare updated to passfirst_line_offset=len(prefix) + len("msgstr ")(and equivalents formsgid,msgctxt,msgid_plural,msgstr[N]).Before:
After:
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.