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

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/langs
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-10-08 11:21:23 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-10-08 15:20:18 +0300
commit33e9d79b78b32d0cc19693ab3c29ba9941d80f8f (patch)
treee4138fa65aa4ce282846c53a2a3b1c4433fc1dd3 /langs
parentfc6abc39c75c152780151c35bc95b12bee01b09c (diff)
langs/i18n: Add workaround for known language, but missing plural rule error
Closes #7798
Diffstat (limited to 'langs')
-rw-r--r--langs/i18n/i18n_test.go15
-rw-r--r--langs/i18n/translationProvider.go9
2 files changed, 23 insertions, 1 deletions
diff --git a/langs/i18n/i18n_test.go b/langs/i18n/i18n_test.go
index baf16d4a6..10570a4e3 100644
--- a/langs/i18n/i18n_test.go
+++ b/langs/i18n/i18n_test.go
@@ -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",
@@ -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)
})
}
diff --git a/langs/i18n/translationProvider.go b/langs/i18n/translationProvider.go
index e478609c2..07bd9219a 100644
--- a/langs/i18n/translationProvider.go
+++ b/langs/i18n/translationProvider.go
@@ -15,6 +15,7 @@ package i18n
import (
"encoding/json"
+ "strings"
"github.com/gohugoio/hugo/common/herrors"
"golang.org/x/text/language"
@@ -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)
}