Skip to content

Commit b203c67

Browse files
jun66j5akx
authored andcommitted
Fallback count="other" format in format_currency()
1 parent 3ae5402 commit b203c67

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

babel/numbers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ def get_currency_name(currency, count=None, locale=LC_NUMERIC):
127127
plural_form = loc.plural_form(count)
128128
plural_names = loc._data['currency_names_plural']
129129
if currency in plural_names:
130-
return plural_names[currency][plural_form]
130+
currency_plural_names = plural_names[currency]
131+
if plural_form in currency_plural_names:
132+
return currency_plural_names[plural_form]
133+
if 'other' in currency_plural_names:
134+
return currency_plural_names['other']
131135
return loc.currencies.get(currency, currency)
132136

133137

tests/test_numbers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ def test_format_currency():
413413
assert (numbers.format_currency(1099.98, 'USD', format=None,
414414
locale='en_US')
415415
== u'$1,099.98')
416+
assert (numbers.format_currency(1, 'USD', locale='es_AR')
417+
== u'US$\xa01,00') # one
418+
assert (numbers.format_currency(1000000, 'USD', locale='es_AR')
419+
== u'US$\xa01.000.000,00') # many
420+
assert (numbers.format_currency(0, 'USD', locale='es_AR')
421+
== u'US$\xa00,00') # other
416422

417423

418424
def test_format_currency_format_type():

0 commit comments

Comments
 (0)