all: gofmt -w -r 'interface{} -> any' .

Updates #9687
This commit is contained in:
Bjørn Erik Pedersen
2022-03-17 22:03:27 +01:00
parent 423594e03a
commit b80853de90
342 changed files with 2118 additions and 2102 deletions

View File

@@ -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):

View File

@@ -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")