Skip to content

Commit

Permalink
Allow hyphens in locale name
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored and bep committed Feb 14, 2022
1 parent 54f7f59 commit 4e2b67f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions locales_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 4e2b67f

Please sign in to comment.