Skip to content

Commit

Permalink
Merge 2efd6c6 into 3e2a92e
Browse files Browse the repository at this point in the history
  • Loading branch information
ZRunner committed Oct 21, 2020
2 parents 3e2a92e + 2efd6c6 commit c3f8fa2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions i18n/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def t(key, **kwargs):
def translate(key, **kwargs):
locale = kwargs.pop('locale', config.get('locale'))
translation = translations.get(key, locale=locale)
if isinstance(translation, list):
# if we can apply plural/formats to the items, let's try
if all(isinstance(data, (str, dict)) for data in translation):
# if needed, we should format every item in the list
if 'count' in kwargs:
translation = [pluralize(key, data, kwargs['count']) for data in translation]
# items may be non-plural dictionnaries, which we cannot format
return [TranslationFormatter(data).format(**kwargs) if isinstance(data, str) else data for data in translation]
return translation
if 'count' in kwargs:
translation = pluralize(key, translation, kwargs['count'])
return TranslationFormatter(translation).format(**kwargs)
Expand Down

0 comments on commit c3f8fa2

Please sign in to comment.