-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
While playing around with Hugo's new multilingual mode, I've encountered the following problems:
-
According to the example configuration in the Multilingual Mode documentation language-specific parameters have to be nested under
params. However, Hugo merges all variables in a language definition into the global site parameters. Solanguages.en.params.subtitleactually ends up as.Site.Params.params.subtitle. -
The documentation states that "all Params are only accessible using all lowercase characters", but this is not enforced by the implementation:
- Global parameter definitions preserve case.
- Language-specific parameter definitions are mapped to lower-case.
- Parameter access is always case-sensitive.
So accidently using upper-case parameter names in your configuration (for example, you have not read the documentation) may give you a hard time. :-)
To see for yourself, you can use the following configuration:
baseurl = "http://localhost"
title = "Multilingual Demo"
defaultContentLanguage = "en"
aparam = "/AParam"
anotherParam = "/AnotherParam"
[Params]
aparam = "/params/AParam"
anotherParam = "/params/AnotherParam"
globalonly = "/globalonly"
globalOnly = "/GlobalOnly"
[Languages]
[Languages.de]
weight = 1
languageName = "Deutsch"
aparam = "/de/AParam"
anotherParam = "/de/AnotherParam"
langOnly = "/de/langOnly"
[Languages.de.Params]
aparam = "/de/params/AParam"
anotherParam = "/de/params/AnotherParam"
[Languages.en]
weight = 2
languageName = "English"
aparam = "/en/AParam"
anotherParam = "/en/AnotherParam"
langOnly = "/en/langOnly"
[Languages.en.Params]
aparam = "/en/params/AParam"
anotherParam = "/en/params/AnotherParam"
and this shortcode:
<pre>
globalonly = {{ .Site.Params.globalonly }}
globalOnly = {{ .Site.Params.globalOnly }}
langOnly = {{ .Site.Params.langOnly }}
langonly = {{ .Site.Params.langonly }}
aparam = {{ .Site.Params.aparam }}
aParam = {{ .Site.Params.aParam }}
anotherparam = {{ .Site.Params.anotherparam }}
anotherParam = {{ .Site.Params.anotherParam }}
</pre>
<hr>
<pre>
{{ range $key, $value := .Site.Params }}{{ $key }} = {{ $value }}
{{ end }}
</pre>
which will generate this result:
globalonly = /globalonly // definition and access are both case-sensitive
globalOnly = /GlobalOnly
langOnly =
langonly = /en/langOnly // language-specific definitions are mapped to lower-case
aparam = /en/AParam // the definition in language.en, not language.en.params, is used
aParam =
anotherparam = /en/AnotherParam // language-specific is mapped to lower-case, ...
anotherParam = /params/AnotherParam // so the global definition is not overridden
----
anotherParam = /params/AnotherParam
anotherparam = /en/AnotherParam
aparam = /en/AParam
globalOnly = /GlobalOnly
globalonly = /globalonly
langonly = /en/langOnly
languagename = English
params = map[anotherParam:/en/params/AnotherParam aparam:/en/params/AParam] // language.en.params --> .Site.Params.params
weight = 2