globalize
globalize copied to clipboard
possible to get the name of a currency
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?
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.
Feel free to include additional comments. We can reopen or use a new issue for improved API ideas.
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.
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?
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.
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 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 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
I am confused: Aren't you trying here to get CLDR information another way?
@diligiant it's not only CLDR information, but processed CLDR information used by the formatter.
How about having separate functions for that and not ending up with swiss army knife's? ;)
Sounds good. We should brainstorm possible APIs. :)
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 ;)