{{ 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?
{{ 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 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
[params.mytheme.currency]
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.
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
:
https://github.com/go-playground/locales/blob/master/fr_CA/fr_CA.go#L59
With language en-gb
:
https://github.com/go-playground/locales/blob/master/en_GB/en_GB.go#L58
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.