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

Get Currency Display Name of Currency Code #72

Open
deerawan opened this issue Apr 4, 2016 · 3 comments
Open

Get Currency Display Name of Currency Code #72

deerawan opened this issue Apr 4, 2016 · 3 comments

Comments

@deerawan
Copy link

deerawan commented Apr 4, 2016

is it possible if we can retrieve currency display name of a given currency code?

e.g.
USD => US Dollar
IDR => indonesia rupiah

@camertron
Copy link
Collaborator

Hey @deerawan. Yes, this is possible. Unfortunately I just noticed the currency data API isn't documented at all in the README. I'll see what I can do to change that. In the meantime, you can retrieve currency information this way:

var TwitterCldr = require('twitter_cldr/core.js');
var usd = TwitterCldr.Currencies.for_code('USD');
// returns { country: 'USD', cldr_symbol: '$', symbol: '$', currency: 'USD' }

Now, that doesn't give you the display name as you requested because the for_code function filters the available fields for compatibility reasons. You can get the full list of fields manually like so:

var usd = TwitterCldr.Currencies.currencies['USD'];
// returns { currency: 'USD', name: 'US dollar', cldr_symbol: '$', symbol: '$', code_points: [36] }

Notice the name field in the return object. I don't remember why we decided to filter out name, but it makes sense to return it. I'll see what I can do.

@deerawan
Copy link
Author

deerawan commented Apr 5, 2016

Hi @camertron

Thank you for your response. I will try what you suggest to me.

One more question, for the currency name.

Does it support currency name in other languages? e.g. if english, it is US Dollar but for Spain it should be Dólar estadounidense.

@camertron
Copy link
Collaborator

Hey @deerawan. Unfortunately the current currencies implementation does not support currencies in multiple languages (only English). It shouldn't be too difficult to support this however. Would you mind filing an issue?

Also, see this pull request which should address exposing display names.

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

2 participants