aboutsummaryrefslogtreecommitdiffhomepage
path: root/langs/i18n
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2022-03-17 22:03:27 +0100
committerBjørn Erik Pedersen <[email protected]>2022-03-17 22:03:27 +0100
commitb80853de90b10171155b8f3fde47d64ec7bfa0dd (patch)
tree435d3dbf7a495a0c6ce64c9769e037179aa0d27b /langs/i18n
parent423594e03a906ef4150f433666ff588b022c3c92 (diff)
downloadhugo-b80853de90b10171155b8f3fde47d64ec7bfa0dd.tar.gz
hugo-b80853de90b10171155b8f3fde47d64ec7bfa0dd.zip
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
Diffstat (limited to 'langs/i18n')
-rw-r--r--langs/i18n/i18n.go12
-rw-r--r--langs/i18n/i18n_test.go26
2 files changed, 19 insertions, 19 deletions
diff --git a/langs/i18n/i18n.go b/langs/i18n/i18n.go
index 64340c857..5594c84cb 100644
--- a/langs/i18n/i18n.go
+++ b/langs/i18n/i18n.go
@@ -28,7 +28,7 @@ import (
"github.com/gohugoio/go-i18n/v2/i18n"
)
-type translateFunc func(translationID string, templateData interface{}) string
+type translateFunc func(translationID string, templateData any) string
var i18nWarningLogger = helpers.NewDistinctErrorLogger()
@@ -58,7 +58,7 @@ func (t Translator) Func(lang string) translateFunc {
}
t.logger.Infoln("i18n not initialized; if you need string translations, check that you have a bundle in /i18n that matches the site language or the default language.")
- return func(translationID string, args interface{}) string {
+ return func(translationID string, args any) string {
return ""
}
}
@@ -71,7 +71,7 @@ func (t Translator) initFuncs(bndl *i18n.Bundle) {
// This may be pt-BR; make it case insensitive.
currentLangKey := strings.ToLower(strings.TrimPrefix(currentLangStr, artificialLangTagPrefix))
localizer := i18n.NewLocalizer(bndl, currentLangStr)
- t.translateFuncs[currentLangKey] = func(translationID string, templateData interface{}) string {
+ t.translateFuncs[currentLangKey] = func(translationID string, templateData any) string {
pluralCount := getPluralCount(templateData)
if templateData != nil {
@@ -134,7 +134,7 @@ const countFieldName = "Count"
// getPluralCount gets the plural count as a string (floats) or an integer.
// If v is nil, nil is returned.
-func getPluralCount(v interface{}) interface{} {
+func getPluralCount(v any) any {
if v == nil {
// i18n called without any argument, make sure it does not
// get any plural count.
@@ -142,7 +142,7 @@ func getPluralCount(v interface{}) interface{} {
}
switch v := v.(type) {
- case map[string]interface{}:
+ case map[string]any:
for k, vv := range v {
if strings.EqualFold(k, countFieldName) {
return toPluralCountValue(vv)
@@ -172,7 +172,7 @@ func getPluralCount(v interface{}) interface{} {
}
// go-i18n expects floats to be represented by string.
-func toPluralCountValue(in interface{}) interface{} {
+func toPluralCountValue(in any) any {
k := reflect.TypeOf(in).Kind()
switch {
case hreflect.IsFloat(k):
diff --git a/langs/i18n/i18n_test.go b/langs/i18n/i18n_test.go
index be20ca3c8..b1ff748f4 100644
--- a/langs/i18n/i18n_test.go
+++ b/langs/i18n/i18n_test.go
@@ -41,7 +41,7 @@ var logger = loggers.NewErrorLogger()
type i18nTest struct {
name string
data map[string][]byte
- args interface{}
+ args any
lang, id, expected, expectedFlag string
}
@@ -179,7 +179,7 @@ one = "One minute to read"
other = "{{ .Count }} minutes to read"
`),
},
- args: map[string]interface{}{"Count": 1},
+ args: map[string]any{"Count": 1},
lang: "en",
id: "readingTime",
expected: "One minute to read",
@@ -207,7 +207,7 @@ one = "One minute to read"
other = "{{ .Count }} minutes to read"
`),
},
- args: map[string]interface{}{"Count": 21},
+ args: map[string]any{"Count": 21},
lang: "en",
id: "readingTime",
expected: "21 minutes to read",
@@ -426,7 +426,7 @@ func doTestI18nTranslate(t testing.TB, test i18nTest, cfg config.Provider) strin
}
type countField struct {
- Count interface{}
+ Count any
}
type noCountField struct {
@@ -436,21 +436,21 @@ type noCountField struct {
type countMethod struct {
}
-func (c countMethod) Count() interface{} {
+func (c countMethod) Count() any {
return 32.5
}
func TestGetPluralCount(t *testing.T) {
c := qt.New(t)
- c.Assert(getPluralCount(map[string]interface{}{"Count": 32}), qt.Equals, 32)
- c.Assert(getPluralCount(map[string]interface{}{"Count": 1}), qt.Equals, 1)
- c.Assert(getPluralCount(map[string]interface{}{"Count": 1.5}), qt.Equals, "1.5")
- c.Assert(getPluralCount(map[string]interface{}{"Count": "32"}), qt.Equals, "32")
- c.Assert(getPluralCount(map[string]interface{}{"Count": "32.5"}), qt.Equals, "32.5")
- c.Assert(getPluralCount(map[string]interface{}{"count": 32}), qt.Equals, 32)
- c.Assert(getPluralCount(map[string]interface{}{"Count": "32"}), qt.Equals, "32")
- c.Assert(getPluralCount(map[string]interface{}{"Counts": 32}), qt.Equals, nil)
+ c.Assert(getPluralCount(map[string]any{"Count": 32}), qt.Equals, 32)
+ c.Assert(getPluralCount(map[string]any{"Count": 1}), qt.Equals, 1)
+ c.Assert(getPluralCount(map[string]any{"Count": 1.5}), qt.Equals, "1.5")
+ c.Assert(getPluralCount(map[string]any{"Count": "32"}), qt.Equals, "32")
+ c.Assert(getPluralCount(map[string]any{"Count": "32.5"}), qt.Equals, "32.5")
+ c.Assert(getPluralCount(map[string]any{"count": 32}), qt.Equals, 32)
+ c.Assert(getPluralCount(map[string]any{"Count": "32"}), qt.Equals, "32")
+ c.Assert(getPluralCount(map[string]any{"Counts": 32}), qt.Equals, nil)
c.Assert(getPluralCount("foo"), qt.Equals, nil)
c.Assert(getPluralCount(countField{Count: 22}), qt.Equals, 22)
c.Assert(getPluralCount(countField{Count: 1.5}), qt.Equals, "1.5")