globalize icon indicating copy to clipboard operation
globalize copied to clipboard

possible to get the name of a currency

Open EXC-BAD-ACCESS opened this issue 8 years ago • 13 comments

right now i'm doing this in order to get the pluralized name "US dollars": Globalize.currencyFormatter('USD', {style:'name', minimumFractionDigits:0, maximumFractionDigits:0,})(2).replace('2','')

is there some simpler way?

EXC-BAD-ACCESS avatar Apr 05 '16 01:04 EXC-BAD-ACCESS

Good hack. You could add a .trim() to remove the leading space.

Anyway, there's no public method/attribute to grab this info from. Another hack would be to grab this info at the runtimeArgs object:

// Another hack
var formatter = Globalize.currencyFormatter('USD', {style:'name'});
console.log(formatter.runtimeArgs[2].displayNames.displayName);
// > 'US Dollar'

Possibly this info should be made available in a more useful way... Similar to an ecma-402 .resolvedOptions() thing. I'm open for API ideas.

rxaviers avatar Apr 05 '16 13:04 rxaviers

Feel free to include additional comments. We can reopen or use a new issue for improved API ideas.

rxaviers avatar Apr 05 '16 13:04 rxaviers

This seems like a necessary addition for complete support for currency, doesn't it? Has anyone floated this up to the ECMA committee?

I recommend reopening this to increase exposure.

jcrben avatar Dec 13 '16 23:12 jcrben

Hi @jcrben, I'll be happy to reopen this issue if we have a more solid direction to go. The two first things I expect are: pulling in references of other implementations and come up with an API suggestion to retrieve that information, would you like to champion this please?

rxaviers avatar Dec 14 '16 01:12 rxaviers

I probably can't champion it but I'd be willing to explore it a bit and come up with some ideas, possibly. I put a message in the IRC channel #globalize if you're interested in syncing up sometime.

jcrben avatar Dec 14 '16 01:12 jcrben

I'd be willing to explore it a bit and come up with some ideas

Sounds good to me. Reopening then and looking forward to it :)

I put a message in the IRC channel #globalize if you're interested in syncing up sometime.

Ok, thanks. I definitely am and I've replied you now.

rxaviers avatar Dec 15 '16 11:12 rxaviers

@rxaviers I think it would be incredibly helpful to have something like

Globalize.locale('en');
const formatter = Globalize.currencyFormatter('USD', {
	style: 'name'
});

// End user may need to get the symbol $, the code USD, the name etc
console.log(formatter.SYMBOL);
console.log(formatter.CODE);
console.log(formatter.NAME);

Don't you think? I am stumbling into this sort of need as I work with creating and as-you-type formatter. It seems related to this ticket

netpoetica avatar Aug 18 '17 18:08 netpoetica

@netpoetica yeap that's definitely helpful. Would you like to get this change going? First, let's define the API. I don't usually see uppercased constants in JavaScript. In Ecma-402, we have resolvedOptions. Let's polish the API, define what we can expose for different formatters, and get this going...

Thanks

rxaviers avatar Sep 01 '17 11:09 rxaviers

I am confused: Aren't you trying here to get CLDR information another way?

diligiant avatar Sep 01 '17 12:09 diligiant

@diligiant it's not only CLDR information, but processed CLDR information used by the formatter.

rxaviers avatar Sep 01 '17 12:09 rxaviers

How about having separate functions for that and not ending up with swiss army knife's? ;)

diligiant avatar Sep 01 '17 12:09 diligiant

Sounds good. We should brainstorm possible APIs. :)

rxaviers avatar Sep 01 '17 12:09 rxaviers

I haven't looked but knowing how you write code, it's probably already there, waiting for a simple function to grab all the pieces ;)

diligiant avatar Sep 01 '17 12:09 diligiant