Skip to content

Fix: In babel/messages/catalog.py Catalog._set_mime_headers(), the... - #1312

Open
M001N wants to merge 1 commit into
python-babel:masterfrom
M001N:oss-engine/838ac4fd-410e62b3
Open

Fix: In babel/messages/catalog.py Catalog._set_mime_headers(), the...#1312
M001N wants to merge 1 commit into
python-babel:masterfrom
M001N:oss-engine/838ac4fd-410e62b3

Conversation

@M001N

@M001N M001N commented Aug 10, 2026

Copy link
Copy Markdown

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_cldr to 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

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

1 participant