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 has

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Set defaultContentLanguage to one of the keys actually present under `languages`.
  2. Or add a `[languages.<defaultContentLanguage>]` entry to the languages map.
  3. 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

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


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/d2d571ca0b9525ec.json. Report an issue: GitHub ↗.