Repository navigation
Warn about inconsistent plural forms during extraction - #1364
saltnpepper97 wants to merge 1 commit into
Conversation
chrikrah
left a comment
There was a problem hiding this comment.
@saltnpepper97 approving at 33c3e3a. The check sits next to the one catalog.add() call in pybabel extract. The case from #1003 now warns, and the first plural still wins.
Head 33c3e3a, merge base e2a1791, Python 3.12.3, pytest 9.1.1, CLDR 48.2 imported:
$ python -m pytest tests/messages/frontend/test_extract.py -q
23 passed in 0.14s
$ python -m pytest tests/messages/frontend/test_extract.py -q # frontend.py from e2a1791, your tests kept
FAILED tests/messages/frontend/test_extract.py::test_extraction_plural_conflicts[conflicting-ngettext]
FAILED tests/messages/frontend/test_extract.py::test_extraction_plural_conflicts[conflicting-npgettext]
FAILED tests/messages/frontend/test_extract.py::test_extraction_plural_conflicts[conflicting-across-files]
3 failed, 20 passed in 0.17s
$ python -m pytest tests/messages -q
391 passed, 1 skipped, 1 warning in 1.15s
non-blocking: across files the warning names only the second call site, so the user still has to grep for the first one:
$ pybabel extract -o o2.pot x # x/one.py:1 ngettext("foo", "foos", 2), x/two.py:3 ngettext("foo", "bars", 2)
x/two.py:3: conflicting plurals for 'foo': 'foos' and 'bars'
existing.locations[0] already holds it. With *existing.locations[0] added to the arguments, the line reads x/two.py:3: conflicting plurals for 'foo': 'foos' (first seen at x/one.py:1) and 'bars'. Your 23 tests still pass with that change.
@akx you merged most of frontend.py recently. Would you take this as it is, or with the first location added to the message?
When plural messages share the same singular text and context but use different plural text, Babel currently keeps the first plural without a warning.
This change checks the existing catalog entry before adding the incoming message and logs a warning with the source location and both plural forms when they conflict. The first plural and merged source locations are preserved.
Tests cover conflicting
ngettextandnpgettextcalls, conflicts across files, identical plural text, separate contexts, and mixed singular/plural calls.Validation on macOS with Python 3.14.2:
Fixes #1003.