Skip to content

Commit

Permalink
Remove support for pluralisation during gettext resource translat…
Browse files Browse the repository at this point in the history
…ion (#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
  • Loading branch information
jayaddison committed Dec 29, 2022
1 parent 5a46d8d commit bb37309
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions sphinx/locale/__init__.py
Expand Up @@ -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

Expand Down

0 comments on commit bb37309

Please sign in to comment.