langs/i18n: Fix multiple unknown language codes
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 23 Apr 2021 05:55:52 +0000 (07:55 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 30 Apr 2021 12:26:49 +0000 (14:26 +0200)
This fixes a bug upstream by temporarily using a patched version of go-i18n.

Closes #7838

go.mod
go.sum
langs/i18n/i18n.go
langs/i18n/i18n_test.go
langs/i18n/translationProvider.go

diff --git a/go.mod b/go.mod
index 0ab9e3b31d6a36c159d001a18848142f1f1d4fb7..3d7ccdac268b874d835edfecdcf83d84cb1ea302 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -26,6 +26,8 @@ require (
        github.com/ghodss/yaml v1.0.0
        github.com/gobuffalo/flect v0.2.2
        github.com/gobwas/glob v0.2.3
+       github.com/gohugoio/go-i18n v2.1.3-0.20210430103248-4c28c89f8013+incompatible // indirect
+       github.com/gohugoio/go-i18n/v2 v2.1.3-0.20210430103248-4c28c89f8013
        github.com/gohugoio/testmodBuilder/mods v0.0.0-20190520184928-c56af20f2e95
        github.com/google/go-cmp v0.5.5
        github.com/gorilla/websocket v1.4.2
@@ -39,7 +41,6 @@ require (
        github.com/mitchellh/mapstructure v1.3.3
        github.com/muesli/smartcrop v0.3.0
        github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
-       github.com/nicksnyder/go-i18n/v2 v2.1.2
        github.com/niklasfasching/go-org v1.5.0
        github.com/olekukonko/tablewriter v0.0.5
        github.com/pelletier/go-toml v1.9.0
diff --git a/go.sum b/go.sum
index ab7caec1c0196c649a8c7d73489a8ff32072fe15..f095df4effd83582f5ddadea01a05d90e07d0853 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -227,6 +227,10 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
 github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
+github.com/gohugoio/go-i18n v2.1.3-0.20210430103248-4c28c89f8013+incompatible h1:0d/CxRl9eRy8UOO86f80axTI2TcP1hEEgExnhFKXIkw=
+github.com/gohugoio/go-i18n v2.1.3-0.20210430103248-4c28c89f8013+incompatible/go.mod h1:KyP0P5LEhJdtIq9PYxFiaxeWtFngJO5zLkDvEiqG8gI=
+github.com/gohugoio/go-i18n/v2 v2.1.3-0.20210430103248-4c28c89f8013 h1:Nj29Qbkt0bZ/bJl8eccfxQp3NlU/0IW1v9eyYtQ53XQ=
+github.com/gohugoio/go-i18n/v2 v2.1.3-0.20210430103248-4c28c89f8013/go.mod h1:3Ltoo9Banwq0gOtcOwxuHG6omk+AwsQPADyw2vQYOJQ=
 github.com/gohugoio/testmodBuilder/mods v0.0.0-20190520184928-c56af20f2e95 h1:sgew0XCnZwnzpWxTt3V8LLiCO7OQi3C6dycaE67wfkU=
 github.com/gohugoio/testmodBuilder/mods v0.0.0-20190520184928-c56af20f2e95/go.mod h1:bOlVlCa1/RajcHpXkrUXPSHB/Re1UnlXxD1Qp8SKOd8=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
index 75f0bdaaa68f4c17bc0b3c0c62fb5c90e5cc0ec9..73e54d034d3fa51957e5f0d07d6017100ae46871 100644 (file)
@@ -24,7 +24,7 @@ import (
        "github.com/gohugoio/hugo/config"
        "github.com/gohugoio/hugo/helpers"
 
-       "github.com/nicksnyder/go-i18n/v2/i18n"
+       "github.com/gohugoio/go-i18n/v2/i18n"
 )
 
 type translateFunc func(translationID string, templateData interface{}) string
index 278ab44467960670edf64d6136aae32cd110651c..9618d3adf3946a8e7173f915216bcd4e54dc4403 100644 (file)
@@ -271,6 +271,26 @@ other = "{{ .Count }} minuttar lesing"`),
                expected:     "3 minuttar lesing",
                expectedFlag: "3 minuttar lesing",
        },
+       // Issue #7838
+       {
+               name: "unknown-language-codes",
+               data: map[string][]byte{
+                       "en.toml": []byte(`[readingTime]
+one ="en one"
+other = "en count {{.Count}}"`),
+                       "a1.toml": []byte(`[readingTime]
+one =  "a1 one"
+other = "a1 count {{ .Count }}"`),
+                       "a2.toml": []byte(`[readingTime]
+one =  "a2 one"
+other = "a2 count {{ .Count }}"`),
+               },
+               args:         3,
+               lang:         "a2",
+               id:           "readingTime",
+               expected:     "a2 count 3",
+               expectedFlag: "a2 count 3",
+       },
        // https://github.com/gohugoio/hugo/issues/7798
        {
                name: "known-language-missing-plural",
index e34df7e97273015e55e050a8e7a82ea4ae10e3b8..1151e6e1d0977883c69ce5d55b34942ed19f9b43 100644 (file)
@@ -22,7 +22,7 @@ import (
        yaml "gopkg.in/yaml.v2"
 
        "github.com/gohugoio/hugo/helpers"
-       "github.com/nicksnyder/go-i18n/v2/i18n"
+       "github.com/gohugoio/go-i18n/v2/i18n"
        toml "github.com/pelletier/go-toml"
 
        "github.com/gohugoio/hugo/deps"