Skip to content

Commit 33e9d79

Browse files
committed
langs/i18n: Add workaround for known language, but missing plural rule error
Closes #7798
1 parent fc6abc3 commit 33e9d79

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

langs/i18n/i18n_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,19 @@ other = "{{ .Count }} minuttar lesing"`),
199199
expected: "3 minuttar lesing",
200200
expectedFlag: "3 minuttar lesing",
201201
},
202+
// https://github.com/gohugoio/hugo/issues/7798
203+
{
204+
name: "known-language-missing-plural",
205+
data: map[string][]byte{
206+
"oc.toml": []byte(`[oc]
207+
one = "abc"`),
208+
},
209+
args: 1,
210+
lang: "oc",
211+
id: "oc",
212+
expected: "abc",
213+
expectedFlag: "abc",
214+
},
202215
// https://github.com/gohugoio/hugo/issues/7794
203216
{
204217
name: "dotted-bare-key",
@@ -292,7 +305,7 @@ func TestI18nTranslate(t *testing.T) {
292305
} else {
293306
expected = test.expected
294307
}
295-
actual = doTestI18nTranslate(t, test, v)
308+
actual = doTestI18nTranslate(c, test, v)
296309
c.Assert(actual, qt.Equals, expected)
297310
})
298311
}

langs/i18n/translationProvider.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package i18n
1515

1616
import (
1717
"encoding/json"
18+
"strings"
1819

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

9697
_, err = bundle.ParseMessageFileBytes(b, name)
9798
if err != nil {
99+
if strings.Contains(err.Error(), "no plural rule") {
100+
// https://github.com/gohugoio/hugo/issues/7798
101+
name = artificialLangTagPrefix + name
102+
_, err = bundle.ParseMessageFileBytes(b, name)
103+
if err == nil {
104+
return nil
105+
}
106+
}
98107
return errWithFileContext(_errors.Wrapf(err, "failed to load translations"), r)
99108
}
100109

0 commit comments

Comments
 (0)