Where to set the currency symbol used in FormatCurrency?

{{ 5120.5032 | lang.FormatCurrency 2 "USD" }} ---> $5,120.50
{{ 5120.5032 | lang.FormatCurrency 2 "GBP" }} ---> GBP5,120.50

Where do I set this to be £ symbol instead of GBP?

I don’t think you can set that with Hugo. The library used to take care of the formatting should be this one here: gotranslators/currencies.autogen.go at main · bep/gotranslators · GitHub - but that is where it stops :slight_smile: In the end it looks to me that some external library decides if a triplet or a currency symbol is used.

But fret not. A solution would be: Don’t use lang.FormatCurrency. Use lang.FormatNumber and then use printf to use your own kind of whatever you wish to have in the front:

In your config

ukp = "£"
usd = "USD"

In your layout:

{{ $value := 5120.5032 }}
{{ $currency := "ukp" }}
{{ printf "%s%s" (index site.Params.mytheme.currency $currency) ($value | langFormatNumber 2) }} ---> £5,120.50

This will work, BUT you will mess with currencies that require a space between symbol and value or the value in front of the symbol etc… so this will only be a solution if you don’t have too many currencies.

1 Like

We localize with a forked version of github.com/go-playground/locales.

Localization of a particular date, number, percentage, or currency depends on the language tag in your site configuration. For example, when localizing a currency value:

With language fr-ca:

With language en-gb:

With fr-ca, if you scroll right to where GBP should be, you’ll see the £ symbol. That is correct.

With en-gb, if you scroll right to where GBP should be, you’ll see the GBP symbol. That is wrong, and a known issue. I just bumped the issue, but it’s been open a while…


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.