]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Check all plurals in python format checker (#1188)
authorTomas R. <tomas.roun8@gmail.com>
Fri, 7 Mar 2025 14:53:51 +0000 (15:53 +0100)
committerGitHub <noreply@github.com>
Fri, 7 Mar 2025 14:53:51 +0000 (16:53 +0200)
babel/messages/checkers.py
tests/messages/test_checkers.py

index c2490f62aa92394ef4b68671abc76992552c4d9b..072a48a985294ec1b4535041cd6d5739b6dfd089 100644 (file)
@@ -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:
index bba8f145ab820a59e29dad601ad0fc0ba0263738..e4559f7e938ea9bc2729ad782dcd3e4ff89e38c4 100644 (file)
@@ -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)
@@ -346,9 +348,13 @@ class TestPythonFormat:
     @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)