From bb37309a6da824664e385d43ca60a3161e620195 Mon Sep 17 00:00:00 2001 From: James Addison <55152140+jayaddison@users.noreply.github.com> Date: Thu, 29 Dec 2022 19:08:47 +0000 Subject: [PATCH] Remove support for pluralisation during ``gettext`` resource translation (#10979) Code related to ``ngettext`` (support for n-ary / plural forms of translated text) doesn't appear to be used, so this commit cleans up the code by removing the ``ngettext`` reference. Detail ------ - ``ngettext`` allows an application to provide a dynamic number (often a count of items, like '5' in ``the linter produced 5 warnings``) to the translation query so that a plurality-relevant message can be retrieved from the catalogue. - ``sphinx`` has previously used this within its own codebase, but no longer does -- ``babel`` command-line extraction [1] is used to retrieve translatable resources from the codebase, and extraction of plural-form keywords is not configured (nor easy to enable, as far as I could tell). - As a result it seems like it may make sense to remove the code. [1]: https://babel.pocoo.org/en/latest/cmdline.html#extract --- sphinx/locale/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index d0a83dc3d54..97b12ea8284 100644 --- a/sphinx/locale/__init__.py +++ b/sphinx/locale/__init__.py @@ -221,16 +221,13 @@ def setup(app): .. versionadded:: 1.8 """ - def gettext(message: str, *args: Any) -> str: + def gettext(message: str) -> str: if not is_translator_registered(catalog, namespace): # not initialized yet return _TranslationProxy(_lazy_translate, catalog, namespace, message) # type: ignore[return-value] # noqa: E501 else: translator = get_translator(catalog, namespace) - if len(args) <= 1: - return translator.gettext(message) - else: # support pluralization - return translator.ngettext(message, args[0], args[1]) + return translator.gettext(message) return gettext