diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-07-28 12:28:52 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-07-29 16:40:06 +0200 |
commit | 7907d24ba16fc5a80930c1aabf5144e684ff7f29 (patch) | |
tree | 7f4a9500a0167f4ea5b9c41a1113288ffb8f1c95 /hugolib/language_test.go | |
parent | 726fe9c3c97a9c979dc7862e7f226fc5ec1341de (diff) | |
download | hugo-7907d24ba16fc5a80930c1aabf5144e684ff7f29.tar.gz hugo-7907d24ba16fc5a80930c1aabf5144e684ff7f29.zip |
tpl/lang: Add new localized versions of lang.FormatNumber etc.
Fixes #8820
Diffstat (limited to 'hugolib/language_test.go')
-rw-r--r-- | hugolib/language_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/hugolib/language_test.go b/hugolib/language_test.go index da8ecd22b..1de422620 100644 --- a/hugolib/language_test.go +++ b/hugolib/language_test.go @@ -79,3 +79,52 @@ name = "foo-a" }) } + +func TestLanguageNumberFormatting(t *testing.T) { + + b := newTestSitesBuilder(t) + b.WithConfigFile("toml", ` +baseURL = "https://example.org" + +defaultContentLanguage = "en" +defaultContentLanguageInSubDir = true + +[languages] +[languages.en] +timeZone="UTC" +weight=10 +[languages.nn] +weight=20 + +`) + + b.WithTemplates("index.html", ` + +FormatNumber: {{ 512.5032 | lang.FormatNumber 2 }} +FormatPercent: {{ 512.5032 | lang.FormatPercent 2 }} +FormatCurrency: {{ 512.5032 | lang.FormatCurrency 2 "USD" }} +FormatAccounting: {{ 512.5032 | lang.FormatAccounting 2 "NOK" }} +FormatNumberCustom: {{ lang.FormatNumberCustom 2 12345.6789 }} + +# We renamed this to FormatNumberCustom in 0.87.0. +NumFmt: {{ -98765.4321 | lang.NumFmt 2 }} + + +`) + b.WithContent("p1.md", "") + + b.Build(BuildCfg{}) + + b.AssertFileContent("public/en/index.html", ` +FormatNumber: 512.50 +FormatPercent: 512.50% +FormatCurrency: $512.50 +FormatAccounting: NOK512.50 +FormatNumberCustom: 12,345.68 + +NumFmt: -98,765.43 +`, + ) + + b.AssertFileContent("public/nn/index.html", "FormatNumber: 512,50\nFormatPercent: 512,50\u00a0%\nFormatCurrency: 512,50\u00a0USD\nFormatAccounting: 512,50\u00a0kr") +} |