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

format_currency throws a KeyError when using the "es_AR" locale #868

Closed
pedrogut opened this issue Apr 28, 2022 · 2 comments
Closed

format_currency throws a KeyError when using the "es_AR" locale #868

pedrogut opened this issue Apr 28, 2022 · 2 comments

Comments

@pedrogut
Copy link

Overview Description

format_currency throws a KeyError for any multiple of 1000000 when using the "es_AR" locale.

Steps to Reproduce

from babel.numbers import format_currency
format_currency(1000000, "ARS", locale="es_AR")

Actual Results

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pedro/Documents/project/venv/lib/python3.10/site-packages/babel/numbers.py", line 533, in format_currency
    return pattern.apply(
  File "/home/pedro/Documents/project/venv/lib/python3.10/site-packages/babel/numbers.py", line 1028, in apply
    get_currency_name(currency, value, locale))
  File "/home/pedro/Documents/project/venv/lib/python3.10/site-packages/babel/numbers.py", line 130, in get_currency_name
    return plural_names[currency][plural_form]
  File "/home/pedro/Documents/project/venv/lib/python3.10/site-packages/babel/localedata.py", line 238, in __getitem__
    orig = val = self._data[key]
KeyError: 'many'

Expected Results

'$\xa01.000.000,00'

Additional Information

This works fine for other values such as: 100000, 999999 and 1000001. But fails for any other multiple of 1000000 (2000000, 3000000, 4000000, etc.)

@jun66j5
Copy link
Contributor

jun66j5 commented May 7, 2022

According to https://unicode.org/reports/tr35/tr35-numbers.html#4-currencies:

If no matching displayName element was found in the previous step, then look for a displayName element that matches count="other", starting in the current locale and then following the locale fallback chain up to, but not including root.

However, this step is not implemented in format_currency().

I posted pull request #872 for this issue.

@akx
Copy link
Member

akx commented May 10, 2022

Fixed in #872. Thank you, @jun66j5!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants