gohugoio/hugo · error
defaultContentLanguage %q not found in languages configurati
Error message
defaultContentLanguage %q not found in languages configuration
What it means
Raised in LanguagesInternal.init (langs/config.go:202) when the user explicitly set defaultContentLanguage but no key in the languages map matches it. Hugo only auto-picks a default (first sorted language, preferring "en") when defaultContentLanguage is unset; an explicit value that matches nothing is treated as a config mistake rather than silently ignored.
Source
Thrown at langs/config.go:202
return true
}
if ri.Weight == 0 {
return false
}
return ri.Weight < rj.Weight
})
for i, l := range ls.Sorted {
if l.Name == en {
enIdx = i
break
}
}
if !defaultSeen {
if defaultContentLanguage != "" {
// Set by the user, but not found in the config.
return "", fmt.Errorf("defaultContentLanguage %q not found in languages configuration", defaultContentLanguage)
}
// Not set by the user, so we use the first language in the config.
defaultIdx := 0
if enIdx != -1 {
defaultIdx = enIdx
}
d := ls.Sorted[defaultIdx]
d.Default = true
ls.LanguageConfigs[d.Name] = d.LanguageConfig
ls.Sorted[defaultIdx] = d
defaultContentLanguage = d.Name
}
// Apply root-level locale to the default content language if it has none.
// Done after defaultContentLanguage is resolved and Sorted is built so both
// are updated consistently. Other languages fall back to their Lang key.
// Priority: per-lang locale > root locale > per-lang languageCode > root
// languageCode. Root languageCode only applies when the default language hasView on GitHub ↗ (pinned to 8a468df065)
Solutions
- Set defaultContentLanguage to one of the keys actually present under `languages`.
- Or add a `[languages.<defaultContentLanguage>]` entry to the languages map.
- Check for exact-string mismatches (case, hyphens) between the two settings.
Example fix
# before defaultContentLanguage = "en" [languages.nb] label = "Norsk" # after defaultContentLanguage = "nb" [languages.nb] label = "Norsk"
Defensive patterns
Strategy: validation
Validate before calling
def := cfg.GetString("defaultContentLanguage")
langs := cfg.GetStringMap("languages")
if len(langs) > 0 {
if _, ok := langs[def]; !ok {
return fmt.Errorf("defaultContentLanguage %q missing from [languages]", def)
}
} Prevention
- If you define a [languages] map, always include a section for defaultContentLanguage
- Remember defaultContentLanguage defaults to "en" — add [languages.en] or change the default
- When renaming a language key, update defaultContentLanguage in the same commit
When it happens
Trigger: `defaultContentLanguage = "en"` while the `languages` map only defines other keys (e.g. only `[languages.nb]`), or a typo/case mismatch between defaultContentLanguage and the language key (keys are matched exactly).
Common situations: Adding a languages block to a previously monolingual site without adding the default "en" entry, renaming a language key (en → en-us) without updating defaultContentLanguage, or theme configs assuming a language the site doesn't define.
Related errors
- failed to create config: %w
- language name cannot be empty
- language name %q is invalid: %s
- default language %q is disabled
- redirects must have either From or FromRe set
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/d2d571ca0b9525ec.json.
Report an issue: GitHub ↗.