Skip to content
New issue

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

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

Already on GitHub? # to your account

Allow parsing of symbols to get to currency code. #141

Open
LaughInJar opened this issue Feb 10, 2015 · 2 comments
Open

Allow parsing of symbols to get to currency code. #141

LaughInJar opened this issue Feb 10, 2015 · 2 comments

Comments

@LaughInJar
Copy link

Babel allows to "speak" any locale but no to understand other locales.

Similar to get_currency_name() and get_currency_symbol() from the currency code, there should be a method allowing to get the currency code from the symbol, e.g.

>>> from babel.numbers import get_currency_code
>>> get_currency_code('$', locale='en_US')
'USD'
>>> get_currency_code(u'\u20ac', locale='de_DE') 
'EUR'.

Even better would be a reverse method to format_currency(), e.g.

>>> from babel.numbers import parse_currency
>>> parse_currency(u'123,45 \u20ac', locale='de_DE')
(123.45, 'EUR')

I see that "Locale.parse(locale).currency_symbols" already contains the required mapping for this.

Cheers, Simon

@rojaraniiza
Copy link

---> 21 from babel.numbers import parse_currency
22 # from babel.numbers import get_currency_code
ImportError: cannot import name 'parse_currency'
Can you please help me out to fix this?

@akx
Copy link
Member

akx commented Aug 10, 2018

@rojaraniiza The issue is there is no such function yet. This is a proposal to implement one.

ddormer added a commit to ddormer/babel that referenced this issue Dec 1, 2019
During cldr import the `currency_codes` mapping is created on `data` and
internally exposed by the `Locale.currency_codes` property.
The `numbers.get_currency_code` API is made available to convert a
currency symbol into a currency code.

Partially addresses issue python-babel#141
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants