bpo-18319: gettext() can retrieve a message even if a plural form exists by gbassiere · Pull Request #19869 · python/cpython (original) (raw)

Let's say you have this in your code:

and elsewhere this :

ngettext('egg', 'eggs', n)

GNU gettext tools extracts these as the same unique message and sensibly creates a pluralized entry in the PO file.

In the Python gettext module, when the MO file is parsed, a singular 'egg' will be stored as:

whereas a pluralized 'egg' is stored as:

catalog[('egg', 0)]
catalog[('eggs', 1)]

As a consequence, gettext('egg') fail to retrieve translations and you have to resort to ngettext('egg', 'eggs', 1) which is odd.

My suggestion is simply to modify gettext() so that is looks for catalog[('egg', 0)] if catalog['egg'] didn't match.

https://bugs.python.org/issue18319