Fix: In babel/messages/catalog.py Catalog._set_mime_headers(), the... - #1312
Open
M001N wants to merge 1 commit into
Open
Fix: In babel/messages/catalog.py Catalog._set_mime_headers(), the...#1312M001N wants to merge 1 commit into
M001N wants to merge 1 commit into
Conversation
read_po() crashed with ValueError when a POT/PO Plural-Forms header still had the unexpanded xgettext placeholders (nplurals=INTEGER; plural=EXPRESSION;). Fall back to the same defaults used elsewhere in Catalog._set_mime_headers (2 plurals, '(n != 1)'), mirroring the existing po-revision-date placeholder guard. Fixes python-babel#1154
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.
Summary
Added a fallback in the 'plural-forms' branch of _set_mime_headers(): if nplurals == 'INTEGER', use the default 2; if plural == 'EXPRESSION', use the default '(n != 1)' expression -- otherwise parse/use the real values as before. This work was already completed and committed in this worktree (commit 314ade9) prior to this session's verification pass.
Problem
python-babel/babel issue reference: #1154
Root Cause
In babel/messages/catalog.py Catalog._set_mime_headers(), the 'plural-forms' branch did
int(params.get('nplurals', 2))and used the raw 'plural' value unconditionally. When a POT template is freshly generated by xgettext but not yet localized, these fields retain the literal placeholder tokens 'INTEGER' and 'EXPRESSION' instead of real values, so int() crashes. This mirrors the pre-existing 'YEAR' placeholder issue already guarded for po-revision-date just below it.Testing
PASS - all 79 tests in test_pofile.py and test_catalog.py pass (after running
python setup.py import_cldrto build required CLDR data files, which is a documented one-time environment setup step, not related to this fix); the new test_issue_1154 regression test passes on its own as well.Related Issue
#1154