@@ -142,12 +142,15 @@ type Config struct {
142142 // The outputformats configuration sections maps a format name (a string) to a configuration object for that format.
143143 OutputFormats * config.ConfigNamespace [map [string ]output.OutputFormatConfig , output.Formats ] `mapstructure:"-"`
144144
145- // The roles configuration section contains the top level roles configuration options .
146- Roles * config.ConfigNamespace [map [string ]roles. RoleConfig , roles. RolesInternal ] `mapstructure:"-"`
145+ // The languages configuration sections maps a language code (a string) to a configuration object for that language .
146+ Languages * config.ConfigNamespace [map [string ]langs. LanguageConfig , langs. LanguagesInternal ] `mapstructure:"-"`
147147
148148 // The versions configuration section contains the top level versions configuration options.
149149 Versions * config.ConfigNamespace [map [string ]versions.VersionConfig , versions.VersionsInternal ] `mapstructure:"-"`
150150
151+ // The roles configuration section contains the top level roles configuration options.
152+ Roles * config.ConfigNamespace [map [string ]roles.RoleConfig , roles.RolesInternal ] `mapstructure:"-"`
153+
151154 // The outputs configuration section maps a Page Kind (a string) to a slice of output formats.
152155 // This can be overridden in the front matter.
153156 Outputs map [string ][]string `mapstructure:"-"`
@@ -209,9 +212,6 @@ type Config struct {
209212 // <docsmeta>{"refs": ["config:languages:params"] }</docsmeta>
210213 Params maps.Params `mapstructure:"-"`
211214
212- // The languages configuration sections maps a language code (a string) to a configuration object for that language.
213- Languages map [string ]langs.LanguageConfig `mapstructure:"-"`
214-
215215 // UglyURLs configuration. Either a boolean or a sections map.
216216 UglyURLs any `mapstructure:"-"`
217217}
@@ -328,18 +328,6 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
328328 for _ , lang := range c .DisableLanguages {
329329 disabledLangs [lang ] = true
330330 }
331- for lang , language := range c .Languages {
332- if ! language .Disabled && disabledLangs [lang ] {
333- language .Disabled = true
334- c .Languages [lang ] = language
335- }
336- if language .Disabled {
337- disabledLangs [lang ] = true
338- if lang == c .DefaultContentLanguage {
339- return fmt .Errorf ("cannot disable default content language %q" , lang )
340- }
341- }
342- }
343331
344332 for i , s := range c .IgnoreLogs {
345333 c .IgnoreLogs [i ] = strings .ToLower (s )
@@ -821,51 +809,10 @@ func (c *Configs) IsZero() bool {
821809func (c * Configs ) Init () error {
822810 var languages langs.Languages
823811
824- var langKeys []string
825- var hasEn bool
826-
827- const en = "en"
828-
829- for k := range c .LanguageConfigMap {
830- langKeys = append (langKeys , k )
831- if k == en {
832- hasEn = true
833- }
834- }
835-
836- // Sort the LanguageConfigSlice by language weight (if set) or lang.
837- sort .Slice (langKeys , func (i , j int ) bool {
838- ki := langKeys [i ]
839- kj := langKeys [j ]
840- lki := c .LanguageConfigMap [ki ]
841- lkj := c .LanguageConfigMap [kj ]
842- li := lki .Languages [ki ]
843- lj := lkj .Languages [kj ]
844- if li .Weight != lj .Weight {
845- return li .Weight < lj .Weight
846- }
847- return ki < kj
848- })
849-
850- // See issue #13646.
851- defaultConfigLanguageFallback := en
852- if ! hasEn {
853- // Pick the first one.
854- defaultConfigLanguageFallback = langKeys [0 ]
855- }
856-
857- if c .Base .DefaultContentLanguage == "" {
858- c .Base .DefaultContentLanguage = defaultConfigLanguageFallback
859- }
860-
861- for _ , k := range langKeys {
862- v := c .LanguageConfigMap [k ]
863- if v .DefaultContentLanguage == "" {
864- v .DefaultContentLanguage = defaultConfigLanguageFallback
865- }
866- c .LanguageConfigSlice = append (c .LanguageConfigSlice , v )
867- languageConf := v .Languages [k ]
868- language , err := langs .NewLanguage (k , c .Base .DefaultContentLanguage , v .TimeZone , languageConf )
812+ // TODO1 more cleanups, please.
813+ for _ , f := range c .Base .Languages .Config .Sorted {
814+ v := c .LanguageConfigMap [f .Name ]
815+ language , err := langs .NewLanguage (f .Name , c .Base .DefaultContentLanguage , v .TimeZone , f .LanguageConfig )
869816 if err != nil {
870817 return err
871818 }
@@ -968,7 +915,7 @@ func (c Configs) GetFirstLanguageConfig() config.AllProvider {
968915
969916func (c Configs ) GetByLang (lang string ) config.AllProvider {
970917 for _ , l := range c .configLangs {
971- if l .Language ().Lang == lang {
918+ if l .Language ().( * langs. Language ). Lang == lang {
972919 return l
973920 }
974921 }
0 commit comments