Skip to content

Commit

Permalink
Restore language.disabled config
Browse files Browse the repository at this point in the history
Fixes #11219
  • Loading branch information
bep committed Jul 8, 2023
1 parent 0f921ac commit a481942
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
}
disabledLangs[lang] = true
}
for lang, language := range c.Languages {
if language.Disabled {
disabledLangs[lang] = true
if lang == c.DefaultContentLanguage {
return fmt.Errorf("cannot disable default content language %q", lang)
}
}
}

ignoredErrors := make(map[string]bool)
for _, err := range c.IgnoreErrors {
Expand Down
27 changes: 27 additions & 0 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,3 +1384,30 @@ Home.
})

}

func TestLanguagesDisabled(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
[languages]
[languages.en]
title = "English Title"
[languages.sv]
title = "Swedish Title"
disabled = true
-- layouts/index.html --
Home.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()

b.Assert(len(b.H.Sites), qt.Equals, 1)

}
3 changes: 3 additions & 0 deletions langs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type LanguageConfig struct {
// The language weight. When set to a non-zero value, this will
// be the main sort criteria for the language.
Weight int

// Set to true to disable this language.
Disabled bool
}

func DecodeConfig(m map[string]any) (map[string]LanguageConfig, error) {
Expand Down

0 comments on commit a481942

Please sign in to comment.