Hi, I’m confused by merging the multilingual parameters, it seems that the params
defined in following files, will replace the responding key of params
instead of deep merging.
languages.toml
params.[lang].toml
// path/to/modules/foo/config.toml
[params.foo]
foo = 1
// ------------
// config/_default/config.toml
[[module.imports]]
path = "path/to/modules/foo"
// ------------
// config/_default/params.toml
[foo]
bar = 2
// ------------
// config/_defualt/languages.toml
[en]
title = "English site"
[zh]
title = "Chinese site"
{{ warnf "%v" .Site.Params.foo }}
#1 Everything is OK when using params.toml
, expected messages as following.
map[bar:2 foo:1]
map[bar:2 foo:1]
#2 When defining params in languages.toml
[en]
title = "English site"
[en.params.foo]
lang = "en"
[zh]
title = "Chinese site"
[zh.params.foo]
lang = "zh"
Got
map[lang:en]
map[lang:zh]
The foo
param was overridden.
#3 When using params.[lang].toml
.
// config/_default/params.en.toml
[foo]
lang = "en"
// config/_default/params.zh.toml
[foo]
lang = "zh"
Same as #2.
Use case
Similar to the description
and the copyright
parameters, there are some parameters of module/component related to their language, but in this case, it’s unable to define others parameters that have default value in module’s configuration file, I have to define the default value inside template like this, to ensure getting the correct default value.
{{ $width := default 20 .Site.Params.foo.width }}
<div style="width: {{ . }}%;"></div>
If we can deep merging the parameters from languages
and params.[lang]
.
<div style="width: {{ .Site.Params.foo.width }}%;"></div>