Fix language params handling

This fixes some issues with language params handling by separating params from configuration values per language.

This means that you can now do this:

```toml
[languages]
[languages.en]
languageName = "English"
weight = 1
title = "My Cool Site"
[languages.en.params]
myParam = "Hi!"
```

This is not a breaking change, but the above is a less suprising way of configuring custom params.

It also fixes some hard-to-debug corner-cases in multilingual sites.

Fixes #4356
Fixes #4352
This commit is contained in:
Bjørn Erik Pedersen
2018-01-30 17:51:18 +01:00
parent feeed073c3
commit ae742cb1bd
4 changed files with 67 additions and 23 deletions

View File

@@ -111,10 +111,20 @@ func toSortedLanguages(cfg config.Provider, l map[string]interface{}) (helpers.L
language.LanguageName = cast.ToString(v)
case "weight":
language.Weight = cast.ToInt(v)
case "params":
m := cast.ToStringMap(v)
// Needed for case insensitive fetching of params values
helpers.ToLowerMap(m)
for k, vv := range m {
language.SetParam(k, vv)
}
}
// Put all into the Params map
language.SetParam(loki, v)
// Also set it in the configuration map (for baseURL etc.)
language.Set(loki, v)
}
langs[i] = language