Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/localescompressed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2022-01-30 08:41:28 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-14 11:38:14 +0300
commit4e2b67f4e694d0248f8ff2db088856b05dea5fd7 (patch)
tree388f15daa2ed91b8f5341081b34b604fb6abba25
parent54f7f59f39c3d6fcf8a532cc4c0f085a7aa14d61 (diff)
Allow hyphens in locale nameHEADv1.0.1v0.16.0v0.15.0main
Fixes gohugoio/hugo#9446
-rw-r--r--locales.go2
-rw-r--r--locales_test.go6
2 files changed, 7 insertions, 1 deletions
diff --git a/locales.go b/locales.go
index c43f1be..b14a70f 100644
--- a/locales.go
+++ b/locales.go
@@ -20,7 +20,7 @@ var (
// GetTranslator gets the Translator for the given locale, nil if not found.
func GetTranslator(locale string) locales.Translator {
- locale = strings.ToLower(locale)
+ locale = strings.ToLower(strings.ReplaceAll(locale, "-", "_"))
mu.RLock()
t, found := translators[locale]
diff --git a/locales_test.go b/locales_test.go
index 44a029f..5f20082 100644
--- a/locales_test.go
+++ b/locales_test.go
@@ -52,6 +52,12 @@ func TestGetTranslator(t *testing.T) {
c.Assert(tnn.MonthWide(d.Month()), qt.Equals, "januar")
})
+ c.Run("BasicWithHyphenatedKey", func(c *qt.C) {
+ tnn := GetTranslator("nn-NO")
+ c.Assert(tnn, qt.Not(qt.IsNil))
+ c.Assert(tnn.MonthWide(d.Month()), qt.Equals, "januar")
+ })
+
// Sample tests; verify that the compression script works correctly.
c.Run("Sample", func(c *qt.C) {
assertSame(c, GetTranslator("en"), en.New())