Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback count="other" format in format_currency() #872

Merged
merged 1 commit into from May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion babel/numbers.py
Expand Up @@ -127,7 +127,11 @@ def get_currency_name(currency, count=None, locale=LC_NUMERIC):
plural_form = loc.plural_form(count)
plural_names = loc._data['currency_names_plural']
if currency in plural_names:
return plural_names[currency][plural_form]
currency_plural_names = plural_names[currency]
if plural_form in currency_plural_names:
return currency_plural_names[plural_form]
if 'other' in currency_plural_names:
return currency_plural_names['other']
return loc.currencies.get(currency, currency)


Expand Down
6 changes: 6 additions & 0 deletions tests/test_numbers.py
Expand Up @@ -413,6 +413,12 @@ def test_format_currency():
assert (numbers.format_currency(1099.98, 'USD', format=None,
locale='en_US')
== u'$1,099.98')
assert (numbers.format_currency(1, 'USD', locale='es_AR')
== u'US$\xa01,00') # one
assert (numbers.format_currency(1000000, 'USD', locale='es_AR')
== u'US$\xa01.000.000,00') # many
assert (numbers.format_currency(0, 'USD', locale='es_AR')
== u'US$\xa00,00') # other


def test_format_currency_format_type():
Expand Down