Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions babel/messages/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ def python_format(catalog: Catalog | None, message: Message) -> None:
if not isinstance(msgstrs, (list, tuple)):
msgstrs = (msgstrs,)

for msgid, msgstr in zip(msgids, msgstrs):
if msgstr:
_validate_format(msgid, msgstr)
if msgstrs[0]:
_validate_format(msgids[0], msgstrs[0])
if message.pluralizable:
for msgstr in msgstrs[1:]:
if msgstr:
_validate_format(msgids[1], msgstr)


def _validate_format(format: str, alternative: str) -> None:
Expand Down
8 changes: 7 additions & 1 deletion tests/messages/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ class TestPythonFormat:
(('foo %s', 'bar'), ('foo', 'bar')),
(('foo', 'bar %s'), ('foo', 'bar')),
(('foo %s', 'bar'), ('foo')),
(('foo %s', 'bar %d'), ('foo %s', 'bar %d', 'baz')),
(('foo %s', 'bar %d'), ('foo %s', 'bar %d', 'baz %d', 'qux')),
])
def test_python_format_invalid(self, msgid, msgstr):
msg = Message(msgid, msgstr)
Expand All @@ -346,9 +348,13 @@ def test_python_format_invalid(self, msgid, msgstr):
@pytest.mark.parametrize(('msgid', 'msgstr'), [
('foo', 'foo'),
('foo', 'foo %s'),
('foo %s', ''),
(('foo %s', 'bar %d'), ('foo %s', 'bar %d')),
(('foo %s', 'bar %d'), ('foo %s', 'bar %d', 'baz')),
(('foo %s', 'bar %d'), ('foo %s', 'bar %d', 'baz %d')),
(('foo', 'bar %s'), ('foo')),
(('foo', 'bar %s'), ('', '')),
(('foo', 'bar %s'), ('foo', '')),
(('foo %s', 'bar %d'), ('foo %s', '')),
])
def test_python_format_valid(self, msgid, msgstr):
msg = Message(msgid, msgstr)
Expand Down
Loading