kataras/iris · error
%s:%s parse string: %w
Error message
%s:%s parse string: %w
What it means
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.
Source
Thrown at i18n/internal/locale.go:67
vars := getVars(loc, VarsKey, keyValues)
if isRoot {
loc.Vars = vars
} else {
vars = removeVarsDuplicates(append(vars, loc.Vars...))
}
for k, v := range keyValues {
form, isPlural := loc.Options.PluralFormDecoder(loc, k)
if isPlural {
k = key
} else if !isRoot {
k = key + "." + k
}
switch value := v.(type) {
case string:
if err := loc.setString(c, k, value, vars, form); err != nil {
return fmt.Errorf("%s:%s parse string: %w", loc.ID, key, err)
}
case Map:
// fmt.Printf("%s is map\n", fullKey)
if err := loc.setMap(c, k, value); err != nil {
return fmt.Errorf("%s:%s parse map: %w", loc.ID, key, err)
}
default:
return fmt.Errorf("%s:%s unexpected type of %T as value", loc.ID, key, value)
}
}
return nil
}
func (loc *Locale) setString(c *Catalog, key string, value string, vars []Var, form PluralForm) (err error) {
isPlural := form != nil
View on GitHub (pinned to 7bedaf55a0)
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
Example fix
// before (en.yml)
greeting: "Hello {{name" // unclosed variable
// after
greeting: "Hello {{name}}!" Defensive patterns
Strategy: try-catch
Validate before calling
func validatePlaceholders(s string, vars []string) error {
for _, m := range regexp.MustCompile(`\{\{([^}]+)\}\}`).FindAllStringSubmatch(s, -1) {
if !slices.Contains(vars, strings.TrimSpace(m[1])) { return fmt.Errorf("unknown var %q", m[1]) }
}
return nil
} Try / catch
if err := loc.Load(c, kv); err != nil {
var perr *template.Error // or match "parse string"
if strings.Contains(err.Error(), "parse string") {
log.Printf("bad translation string: %v", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- %s:%s parse map: %w
- %s:%s unexpected type of %T as value
- nil loader
- catalog: empty languages
- expected language index to be lower or equal than %d but got
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/3cb5782d7f14dc8c.
Report an issue: GitHub.