summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun Omae <jun66j5@gmail.com>2022-05-08 00:50:21 +0900
committerAarni Koskela <akx@iki.fi>2022-05-10 07:30:54 +0200
commitb203c672a265bc9d4e6b44cc46359d9414252736 (patch)
tree6bd25e6f067c259d596fb1fe758fbf48fc9a9203
parent3ae540289aa4669f0cab079876b05863abee0f0d (diff)
downloadbabel-b203c672a265bc9d4e6b44cc46359d9414252736.tar.gz
Fallback count="other" format in format_currency()
-rw-r--r--babel/numbers.py6
-rw-r--r--tests/test_numbers.py6
2 files changed, 11 insertions, 1 deletions
diff --git a/babel/numbers.py b/babel/numbers.py
index 6e15fd3..904ebbe 100644
--- a/babel/numbers.py
+++ b/babel/numbers.py
@@ -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)
diff --git a/tests/test_numbers.py b/tests/test_numbers.py
index a77efc4..3fab394 100644
--- a/tests/test_numbers.py
+++ b/tests/test_numbers.py
@@ -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():