Repository navigation
fix: tolerate placeholder nplurals values in PO headers - #1480
Open
abu-tahir-0 wants to merge 1 commit into
Open
abu-tahir-0 wants to merge 1 commit into
abu-tahir-0 wants to merge 1 commit into
Conversation
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
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.
Problem
Reading a PO file whose
Plural-Formsheader contains a placeholder such asnplurals=EXPRESSIONraises aValueErrorand aborts the whole catalog load (issue #1154).Root Cause
Catalog.read_popasses the rawnpluralsheader value straight toint(). Template/generated PO files can carry a non-numeric placeholder there, but the parser treats it as a fatal error.Solution
When
npluralsis 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
test_read_po_tolerates_placeholder_plural_formsintests/messages/test_pofile.py.Impact
Projects can load template PO files with placeholder plural headers instead of crashing at catalog-read time.