From dab43fb6f565e67f0bbc7aca9405d9d0f86e341d Mon Sep 17 00:00:00 2001 From: Iain Date: Tue, 17 Nov 2026 20:26:05 +0000 Subject: [PATCH] Don't count untranslated plurals in compile --statistics --- babel/messages/frontend.py | 2 +- tests/messages/frontend/test_frontend.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index e642a1a08..a333ab65b 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -255,7 +255,7 @@ def _run_domain(self, domain): if self.statistics: translated = 0 for message in list(catalog)[1:]: - if message.string: + if message.string and (not message.pluralizable or any(message.string)): translated += 1 percentage = 0 if len(catalog): diff --git a/tests/messages/frontend/test_frontend.py b/tests/messages/frontend/test_frontend.py index c8b8d17d5..8600b9f5c 100644 --- a/tests/messages/frontend/test_frontend.py +++ b/tests/messages/frontend/test_frontend.py @@ -279,6 +279,21 @@ def test_compile_catalog_explicit(tmp_path): assert mo_file.exists() +def test_compile_catalog_statistics_untranslated_plural(tmp_path, caplog): + po_file = tmp_path / 'temp.po' + po_file.write_text('msgid "a"\nmsgstr "b"\n\nmsgid "c"\nmsgid_plural "d"\nmsgstr[0] ""\n') + cmdinst = configure_cli_command([ + 'compile', + '--statistics', + '--use-fuzzy', + '-i', str(po_file), + '-o', str(tmp_path / 'temp.mo'), + ]) # fmt: skip + with caplog.at_level('INFO', logger='babel'): + assert not cmdinst.run() + assert '1 of 2 messages (50%) translated' in caplog.text + + @pytest.mark.parametrize("explicit_locale", [None, 'fi_FI'], ids=("implicit", "explicit")) def test_update_dir(tmp_path, explicit_locale: bool): """