{"id":"ee3ced071a4fb2c1","repo":"gohugoio/hugo","slug":"language-name-cannot-be-empty","errorCode":null,"errorMessage":"language name cannot be empty","messagePattern":"language name cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"langs/config.go","lineNumber":155,"sourceCode":"\t\tif defaultContentLanguage == \"\" {\n\t\t\tdefaultContentLanguage = en\n\t\t}\n\t\tls.LanguageConfigs[defaultContentLanguage] = LanguageConfig{}\n\t}\n\n\tvar (\n\t\tdefaultSeen bool\n\t\tenIdx       int = -1\n\t)\n\tfor k, v := range ls.LanguageConfigs {\n\t\tif !v.Disabled && slices.Contains(disabledLanguages, k) {\n\t\t\t// This language is disabled.\n\t\t\tv.Disabled = true\n\t\t\tls.LanguageConfigs[k] = v\n\t\t}\n\n\t\tif k == \"\" {\n\t\t\treturn \"\", errors.New(\"language name cannot be empty\")\n\t\t}\n\n\t\tif err := paths.ValidateIdentifier(k); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"language name %q is invalid: %s\", k, err)\n\t\t}\n\n\t\tvar isDefault bool\n\t\tif k == defaultContentLanguage {\n\t\t\tisDefault = true\n\t\t\tdefaultSeen = true\n\t\t}\n\n\t\tif isDefault && v.Disabled {\n\t\t\treturn \"\", fmt.Errorf(\"default language %q is disabled\", k)\n\t\t}\n\n\t\tif !v.Disabled {\n\t\t\tls.Sorted = append(ls.Sorted, LanguageInternal{Name: k, Default: isDefault, LanguageConfig: v})","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/langs/config.go#L137-L173","documentation":"Raised in LanguagesInternal.init (langs/config.go:155) when a key in the languages config map is the empty string. Language keys become path segments, filesystem identifiers, and lookup keys throughout Hugo, so an empty language name is unusable and rejected outright during config compilation.","triggerScenarios":"A `languages` config map containing an empty-string key — e.g. YAML `languages: { \"\": {...} }`, a templated/generated config emitting an empty key, or programmatic config (config.Provider.Set) inserting an empty language name.","commonSituations":"Generated or scripted configs (environment substitution producing an empty value for the language key), YAML quirks where a key resolves to empty, or accidental stray entries when restructuring a multilingual config.","solutions":["Find and remove or rename the empty key in the `languages` section of your config.","If the config is generated, guard the generator so the language key variable is non-empty before writing.","Validate merged config with `hugo config | grep -A5 languages` after fixing."],"exampleFix":"# before (hugo.yaml)\nlanguages:\n  \"\": \n    label: English\n# after\nlanguages:\n  en:\n    label: English","handlingStrategy":"validation","validationCode":"// Reject empty language keys before passing config to Hugo\nfor lang := range cfg.GetStringMap(\"languages\") {\n    if strings.TrimSpace(lang) == \"\" {\n        return errors.New(\"empty language key in [languages]\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never write [languages.\"\"] or a blank key in YAML languages maps","Generate language config from a validated list of language codes","Lint config files for empty map keys in CI"],"tags":["hugo","config","multilingual","validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}