Iteration languages get parameter

Hello,

I would like to iterate over all translations to build a language switching div.
I would like to define the icon definition within the config.yml under

languages:
    de:
        icon: "de"
    en:
        icon: "gb"

In my HTML file I’m using

 {{ .Site.Home.AllTranslations }}
 <a href="/{{- .Lang -}}/"<span class="flag-icon flag-icon-{{- ?? -}}"></span></a>
 {{ end }}

So my question is, how can I get the “icon” key and value of the language section within the config? So I need the code for the ??

Thanks

We are lenient in the config parsing and support a few variations, but I think your problem will be easier to undertand if you follow the example in the docs:

[languages]
  [languages.en]
    title = "My blog"
    weight = 1
    [languages.en.params]
      linkedin = "https://linkedin.com/whoever"
  [languages.fr]
    title = "Mon blogue"
    weight = 2
    [languages.fr.params]
      linkedin = "https://linkedin.com/fr/whoever"
      [languages.fr.params.navigation]
        help = "Aide"

Custom Params will be available in the language’s Site’s ´.Params`. So:

{{ .Site.Home.AllTranslations }}{{ .Lang }} {{ .Site.Params.icon }}{{ end }}

Etc.

Also note that we have made this simpler in Hugo 0.53 with the config dir support, as you can have params.de.toml etc.

thanks, that’s a nice and easy solution

Maybe off-topic, but please, don’t use flags to represent languages.

http://www.flagsarenotlanguages.com/blog/why-flags-do-not-represent-language/

2 Likes

Thanks for this off-topic hint, but I think it is a good idea

Surely unlike me, you don’t leave in a country (hint: flag) where several official languages (hint: no flag) are spoken. We have so to agree that we disagree.