gohugoio/hugo · error

language %q not found

Error message

language %q not found

What it means

Raised by `hugo config` when the value passed via `--lang` is not a key in the site's LanguageConfigMap (commands/config.go:70-73). Hugo builds one merged config per configured language; if the requested language code was never declared in the site configuration, there is no config object to display, so the command fails fast instead of printing the wrong language's settings.

Source

Thrown at commands/config.go:72

func (c *configCommand) Commands() []simplecobra.Commander {
	return c.commands
}

func (c *configCommand) Name() string {
	return "config"
}

func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args []string) error {
	conf, err := c.r.ConfigFromProvider(configKey{counter: c.r.configVersionID.Load()}, flagsToCfg(cd, nil))
	if err != nil {
		return err
	}
	var config *allconfig.Config
	if c.lang != "" {
		var found bool
		config, found = conf.configs.LanguageConfigMap[c.lang]
		if !found {
			return fmt.Errorf("language %q not found", c.lang)
		}
	} else {
		config = conf.configs.LanguageConfigMap[conf.configs.Base.DefaultContentLanguage]
	}

	var buf bytes.Buffer
	dec := json.NewEncoder(&buf)
	dec.SetIndent("", "  ")
	dec.SetEscapeHTML(false)

	if err := dec.Encode(parser.ReplacingJSONMarshaller{Value: config, KeysToLower: true, OmitEmpty: !c.printZero}); err != nil {
		return err
	}

	format := strings.ToLower(c.format)

	switch format {
	case "json":

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Check the declared language keys: run `hugo config | grep -A5 languages` or inspect the `languages` section of your site config, and pass one of those exact keys to --lang.
  2. Fix the language key spelling/case — the lookup is an exact map-key match against your config's language identifiers.
  3. If the language should exist, add it under `[languages.<code>]` in hugo.toml before querying it.
  4. Omit --lang to display the config for defaultContentLanguage.

Example fix

# before
hugo config --lang en-US   # config declares [languages.en]
# after
hugo config --lang en
Defensive patterns

Strategy: validation

Validate before calling

// Verify the language key exists in config before requesting it
langs := conf.Languages
found := false
for _, l := range langs {
    if l.Lang == wantedLang {
        found = true
        break
    }
}
if !found {
    // handle: list valid languages to the user
}

Try / catch

if err != nil && strings.Contains(err.Error(), "not found") {
    // report valid languages from config and exit non-zero
}

Prevention

When it happens

Trigger: Running `hugo config --lang <code>` where <code> does not match any key under `languages` in hugo.toml/hugo.yaml (e.g. `hugo config --lang en-us` when the config declares `en`). Also triggered when the site has no `languages` block at all and any --lang other than the default content language is requested.

Common situations: Typos or case/region mismatches in language codes (`en-US` vs `en`); running the command in a monorepo directory whose config doesn't define the expected language; a language recently removed or renamed in config; confusing `defaultContentLanguage` with a declared language entry.

Related errors


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