bojanz / currency

Currency handling for Go.
https://pkg.go.dev/github.com/bojanz/currency
MIT License
533 stars 44 forks source link

Introduce currency.ForCountryCode() for getting a country's currency #23

Closed mboudraa closed 11 months ago

mboudraa commented 1 year ago

It would be very useful to expose a function like

fun currency.getCode(countryCode string) (string, error) 

it would allow to retrieve the currency used by default for a given country

bojanz commented 1 year ago

That does sound useful.

We have the data available in https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-core/supplemental/currencyData.json, we could parse it into a currencyCountries / countryCurrencies of type map[string][string] that maps country codes to currency codes.

mboudraa commented 1 year ago

Yes that would be great. Also at the risk of being to demanding 😅, Having the ability to have the currency full name would be also extremely useful for building drop downs of available currencies for selection for example

mboudraa commented 1 year ago

we could parse it into a currencyCountries / countryCurrencies of type map[string][string] that maps country codes to currency codes.

yes I build a local map of country to currency map[string]string that would allow me to do something like

currencyCode := countryCurrency["CA"]
digits, err := currency.GetDigits(countryCode)

Not having to maintain that map would be fantastic.

If I can help in any way, let me know

bojanz commented 1 year ago

Having the ability to have the currency full name would be also extremely useful for building drop downs of available currencies for selection for example

This is covered in the README:

Currency names are not included because they are rarely shown, but need significant space. Instead, they can be fetched on the frontend via Intl.DisplayNames.