Skip to content

fix: tolerate placeholder nplurals values in PO headers - #1480

Open
abu-tahir-0 wants to merge 1 commit into
python-babel:masterfrom
abu-tahir-0:fix/tolerate-placeholder-nplurals
Open

abu-tahir-0 wants to merge 1 commit into
python-babel:masterfrom
abu-tahir-0:fix/tolerate-placeholder-nplurals

Conversation

@abu-tahir-0

Copy link
Copy Markdown

Problem

Reading a PO file whose Plural-Forms header contains a placeholder such as nplurals=EXPRESSION raises a ValueError and aborts the whole catalog load (issue #1154).

Root Cause

Catalog.read_po passes the raw nplurals header value straight to int(). Template/generated PO files can carry a non-numeric placeholder there, but the parser treats it as a fatal error.

Solution

When nplurals is not an integer, fall back to the standard default of 2 rather than failing the import. The plural expression is still read normally. This keeps valid files unchanged and only makes placeholder headers loadable.

Testing

  • Added test_read_po_tolerates_placeholder_plural_forms in tests/messages/test_pofile.py.
  • Confirmed the test fails on the original code and passes with the fix.
  • Full suite: the new test passes; 15 pre-existing CLDR-data failures remain (environment lacks imported CLDR data), confirmed identical on baseline.

Impact

Projects can load template PO files with placeholder plural headers instead of crashing at catalog-read time.

xgettext emits 'nplurals=INTEGER; plural=EXPRESSION;' in POT templates.
read_po() called int() on the literal 'INTEGER' and raised ValueError,
making such templates impossible to parse. Fall back to the default of
two plurals when the value is not an integer, and add a regression test.

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.

1 participant