{"record":{"id":"3f6441e52760ef32","repo":"kataras/iris","slug":"s-s-unexpected-type-of-t-as-value","errorCode":null,"errorMessage":"%s:%s unexpected type of %T as value","messagePattern":"(.+?):(.+?) unexpected type of %T as value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"i18n/internal/locale.go","lineNumber":76,"sourceCode":"\t\tif isPlural {\n\t\t\tk = key\n\t\t} else if !isRoot {\n\t\t\tk = key + \".\" + k\n\t\t}\n\n\t\tswitch value := v.(type) {\n\t\tcase string:\n\t\t\tif err := loc.setString(c, k, value, vars, form); err != nil {\n\t\t\t\treturn fmt.Errorf(\"%s:%s parse string: %w\", loc.ID, key, err)\n\t\t\t}\n\t\tcase Map:\n\t\t\t// fmt.Printf(\"%s is map\\n\", fullKey)\n\t\t\tif err := loc.setMap(c, k, value); err != nil {\n\t\t\t\treturn fmt.Errorf(\"%s:%s parse map: %w\", loc.ID, key, err)\n\t\t\t}\n\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"%s:%s unexpected type of %T as value\", loc.ID, key, value)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (loc *Locale) setString(c *Catalog, key string, value string, vars []Var, form PluralForm) (err error) {\n\tisPlural := form != nil\n\n\t// fmt.Printf(\"setStringVars: %s=%s\\n\", key, value)\n\tmsgs, vars := makeSelectfVars(value, vars, isPlural)\n\tmsgs = append(msgs, catalog.String(value))\n\n\tm := &Message{\n\t\tLocale: loc,\n\t\tKey:    key,\n\t\tValue:  value,\n\t\tVars:   vars,","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/i18n/internal/locale.go#L58-L94","documentation":"Each value in a translation Map must be either a string (message) or another Map (section). Any other Go type (int, bool, slice, struct, nil) is rejected with this error identifying the locale, key and offending type via %T.","triggerScenarios":"Storing kv maps where values came from an untyped source: JSON numbers/booleans, YAML scalars decoded as int/bool, or slices where the i18n API expects string or Map — e.g. count: 5 or items: [a, b] in a locale file.","commonSituations":"YAML locale files with unquoted numbers or booleans decoded to non-string types; JSON translation files with numeric values; dynamically generated maps fed into catalog.Store from configs or databases with non-string columns.","solutions":["Convert all leaf values to string (or nested Map) before storing — fmt.Sprint or explicit quoting in YAML/JSON","Quote numeric/boolean values in locale files so decoders produce strings","Validate the kv structure with a recursive check before calling Store/Load","Fix data sources (DB/config) to emit strings for translation values"],"exampleFix":"// before (values.yml)\nmax_items: 5\nenabled: yes\n// after\nmax_items: \"5\"\nenabled: \"yes\"","handlingStrategy":"type-guard","validationCode":"func stringsOnly(m map[string]any) error {\n    for k, v := range m {\n        switch t := v.(type) {\n        case string:\n        case map[string]any:\n            if err := stringsOnly(t); err != nil { return err }\n        default:\n            return fmt.Errorf(\"key %s: unsupported type %T\", k, v)\n        }\n    }\n    return nil\n}","typeGuard":"func isTranslatableValue(v any) bool {\n    switch v.(type) {\n    case string, map[string]any:\n        return true\n    default:\n        return false\n    }\n}","tryCatchPattern":"if err := loc.Load(c, kv); err != nil {\n    if strings.Contains(err.Error(), \"unexpected type\") {\n        log.Printf(\"non-string translation value: %v\", err)\n    }\n    return err\n}","preventionTips":["Quote numbers and booleans in YAML/JSON locale files","Coerce DB/config values to strings before building kv maps","Validate maps with stringsOnly before Store/Load","Decode YAML/JSON with strict typing or post-process scalars to strings"],"tags":["go","i18n","type-error","translations"],"backgroundTag":"translation-value-type-mismatch","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}