{"record":{"id":"3cb5782d7f14dc8c","repo":"kataras/iris","slug":"s-s-parse-string-w","errorCode":null,"errorMessage":"%s:%s parse string: %w","messagePattern":"(.+?):(.+?) parse string: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"i18n/internal/locale.go","lineNumber":67,"sourceCode":"\tvars := getVars(loc, VarsKey, keyValues)\n\tif isRoot {\n\t\tloc.Vars = vars\n\t} else {\n\t\tvars = removeVarsDuplicates(append(vars, loc.Vars...))\n\t}\n\n\tfor k, v := range keyValues {\n\t\tform, isPlural := loc.Options.PluralFormDecoder(loc, k)\n\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","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/i18n/internal/locale.go#L49-L85","documentation":"When a translation value is a string, locale.setMap parses it with the message printer (template variables, plural forms, funcs). If parsing fails, the error is wrapped as \"localeID:key parse string\" so you can tell which locale and key contained the bad string.","triggerScenarios":"Storing translation maps (via i18n.New loader, catalog.Store or locale.Load) where a value's string uses invalid template syntax — unclosed {{variable}}, unknown function, bad plural form syntax, or a referenced variable not declared in vars.","commonSituations":"Translators editing .yml/.json/.toml locale files introduce a typo like {{naame}} or stray '{{'; a template func was removed but strings still call it; plural form markers malformed after an editor mangled the file.","solutions":["Read the wrapped cause: it names the locale ID, the key, and the template parse error — fix that string in the translation file","Validate all {{...}} placeholders match declared variables and that braces are balanced","Check that any template functions used exist in the i18n options","Add a startup test that loads all locale files to surface parse errors at build/deploy time"],"exampleFix":"// before (en.yml)\ngreeting: \"Hello {{name\"   // unclosed variable\n// after\ngreeting: \"Hello {{name}}!\"","handlingStrategy":"try-catch","validationCode":"func validatePlaceholders(s string, vars []string) error {\n    for _, m := range regexp.MustCompile(`\\{\\{([^}]+)\\}\\}`).FindAllStringSubmatch(s, -1) {\n        if !slices.Contains(vars, strings.TrimSpace(m[1])) { return fmt.Errorf(\"unknown var %q\", m[1]) }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := loc.Load(c, kv); err != nil {\n    var perr *template.Error // or match \"parse string\"\n    if strings.Contains(err.Error(), \"parse string\") {\n        log.Printf(\"bad translation string: %v\", err)\n    }\n    return err\n}","preventionTips":["Add a startup/CI test that loads every locale file","Keep placeholders balanced and matching declared variables","Lint translations with a YAML/JSON schema plus template check","After editing template funcs, grep locale files for their usage"],"tags":["go","i18n","template-parsing","translations"],"backgroundTag":"translation-template-parse-error","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}