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

Add symbol to currency code mapping #677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ddormer
Copy link

@ddormer ddormer commented 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 #141

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
Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth it to actually store the inverse mapping in the .dat file, since it's exactly the same data as currency_symbols, but keys and values reversed.

I think we should just synthesize currency_codes when first accessed within the Locale object.

@ericzolf
Copy link

ericzolf commented Oct 1, 2021

I personally use the following workaround in the meantime:

import babel.numbers as babelnum

CURRENCY_MAP = { babelnum.get_currency_symbol(x): x
                 for x in babelnum.list_currencies()
                 if x != babelnum.get_currency_symbol(x) }

def get_currency_code(currency_symbol):
    return CURRENCY_MAP.get(currency_symbol, currency_symbol)

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

Successfully merging this pull request may close these issues.

None yet

3 participants