twitter-cldr-js icon indicating copy to clipboard operation
twitter-cldr-js copied to clipboard

Get Currency Display Name of Currency Code

Open deerawan opened this issue 9 years ago • 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

deerawan avatar Apr 04 '16 07:04 deerawan

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.

camertron avatar Apr 04 '16 19:04 camertron

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.

deerawan avatar Apr 05 '16 23:04 deerawan

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.

camertron avatar Apr 06 '16 01:04 camertron