twitter/twitter-cldr-js

Get Currency Display Name of Currency Code

Opened this issue · 3 comments

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

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

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.

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.

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.