Skip to content

Commit

Permalink
Fix for wrong plurals with multiple domains
Browse files Browse the repository at this point in the history
When translations from different catalogs are being merged, there is a
workaround to copy the `plurals()` function from the catalog to the combined
`translations` object. If the locale catalog doesn't exist for a
particular domain, a default value is copied, overriding the proper
`plurals()`function. This results in the plural version of a string not
being translated for languages with different plural values.

See for instance `test_gettext.py::test_plurals_different_domains`: the
Japanese locale exists only in the `messages` domain (`translations`
folder) but not on the `myapp` one (`translations_different_domain`
folder).

First reported in ckan/ckan#8258
  • Loading branch information
amercader committed Jun 12, 2024
1 parent 38a3458 commit dad01d3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion flask_babel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def get_translations(self):
# does not copy _info, plural(), or any other instance variables
# populated by GNUTranslations. We probably want to stop using
# `support.Translations.merge` entirely.
if hasattr(catalog, 'plural'):
if catalog.info() and hasattr(catalog, 'plural'):
translations.plural = catalog.plural

cache[str(locale), self.domain[0]] = translations
Expand Down

0 comments on commit dad01d3

Please sign in to comment.