mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
@@ -41,7 +41,7 @@ func LoadLanguageSettings(cfg config.Provider, oldLangs Languages) (c LanguagesC
|
||||
cfg.Set("defaultContentLanguage", defaultLang)
|
||||
}
|
||||
|
||||
var languages map[string]interface{}
|
||||
var languages map[string]any
|
||||
|
||||
languagesFromConfig := cfg.GetParams("languages")
|
||||
disableLanguages := cfg.GetStringSlice("disableLanguages")
|
||||
@@ -170,7 +170,7 @@ func LoadLanguageSettings(cfg config.Provider, oldLangs Languages) (c LanguagesC
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func toSortedLanguages(cfg config.Provider, l map[string]interface{}) (Languages, error) {
|
||||
func toSortedLanguages(cfg config.Provider, l map[string]any) (Languages, error) {
|
||||
languages := make(Languages, len(l))
|
||||
i := 0
|
||||
|
||||
|
@@ -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):
|
||||
|
@@ -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")
|
||||
|
@@ -21,10 +21,10 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
translators "github.com/gohugoio/localescompressed"
|
||||
"github.com/gohugoio/locales"
|
||||
"github.com/gohugoio/hugo/common/maps"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/gohugoio/locales"
|
||||
translators "github.com/gohugoio/localescompressed"
|
||||
)
|
||||
|
||||
// These are the settings that should only be looked up in the global Viper
|
||||
@@ -70,7 +70,7 @@ type Language struct {
|
||||
|
||||
// These are params declared in the [params] section of the language merged with the
|
||||
// site's params, the most specific (language) wins on duplicate keys.
|
||||
params map[string]interface{}
|
||||
params map[string]any
|
||||
paramsMu sync.Mutex
|
||||
paramsSet bool
|
||||
|
||||
@@ -93,7 +93,7 @@ func (l *Language) String() string {
|
||||
func NewLanguage(lang string, cfg config.Provider) *Language {
|
||||
// Note that language specific params will be overridden later.
|
||||
// We should improve that, but we need to make a copy:
|
||||
params := make(map[string]interface{})
|
||||
params := make(map[string]any)
|
||||
for k, v := range cfg.GetStringMap("params") {
|
||||
params[k] = v
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func (l Languages) IsMultihost() bool {
|
||||
|
||||
// SetParam sets a param with the given key and value.
|
||||
// SetParam is case-insensitive.
|
||||
func (l *Language) SetParam(k string, v interface{}) {
|
||||
func (l *Language) SetParam(k string, v any) {
|
||||
l.paramsMu.Lock()
|
||||
defer l.paramsMu.Unlock()
|
||||
if l.paramsSet {
|
||||
@@ -224,7 +224,7 @@ func (l *Language) SetParam(k string, v interface{}) {
|
||||
// GetLocal gets a configuration value set on language level. It will
|
||||
// not fall back to any global value.
|
||||
// It will return nil if a value with the given key cannot be found.
|
||||
func (l *Language) GetLocal(key string) interface{} {
|
||||
func (l *Language) GetLocal(key string) any {
|
||||
if l == nil {
|
||||
panic("language not set")
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func (l *Language) GetLocal(key string) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Language) Set(k string, v interface{}) {
|
||||
func (l *Language) Set(k string, v any) {
|
||||
k = strings.ToLower(k)
|
||||
if globalOnlySettings[k] {
|
||||
return
|
||||
@@ -244,7 +244,7 @@ func (l *Language) Set(k string, v interface{}) {
|
||||
}
|
||||
|
||||
// Merge is currently not supported for Language.
|
||||
func (l *Language) Merge(key string, value interface{}) {
|
||||
func (l *Language) Merge(key string, value any) {
|
||||
panic("Not supported")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user