Skip to content

Commit

Permalink
langs/i18n: Add workaround for known language, but missing plural rul…
Browse files Browse the repository at this point in the history
…e error

Closes #7798
  • Loading branch information
bep committed Oct 8, 2020
1 parent fc6abc3 commit 33e9d79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion langs/i18n/i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ other = "{{ .Count }} minuttar lesing"`),
expected: "3 minuttar lesing",
expectedFlag: "3 minuttar lesing",
},
// https://github.com/gohugoio/hugo/issues/7798
{
name: "known-language-missing-plural",
data: map[string][]byte{
"oc.toml": []byte(`[oc]
one = "abc"`),
},
args: 1,
lang: "oc",
id: "oc",
expected: "abc",
expectedFlag: "abc",
},
// https://github.com/gohugoio/hugo/issues/7794
{
name: "dotted-bare-key",
Expand Down Expand Up @@ -292,7 +305,7 @@ func TestI18nTranslate(t *testing.T) {
} else {
expected = test.expected
}
actual = doTestI18nTranslate(t, test, v)
actual = doTestI18nTranslate(c, test, v)
c.Assert(actual, qt.Equals, expected)
})
}
Expand Down
9 changes: 9 additions & 0 deletions langs/i18n/translationProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package i18n

import (
"encoding/json"
"strings"

"github.com/gohugoio/hugo/common/herrors"
"golang.org/x/text/language"
Expand Down Expand Up @@ -95,6 +96,14 @@ func addTranslationFile(bundle *i18n.Bundle, r source.File) error {

_, err = bundle.ParseMessageFileBytes(b, name)
if err != nil {
if strings.Contains(err.Error(), "no plural rule") {
// https://github.com/gohugoio/hugo/issues/7798
name = artificialLangTagPrefix + name
_, err = bundle.ParseMessageFileBytes(b, name)
if err == nil {
return nil
}
}
return errWithFileContext(_errors.Wrapf(err, "failed to load translations"), r)
}

Expand Down

0 comments on commit 33e9d79

Please sign in to comment.