Confused about multilang parameters (site.Params) in new 0.112.3

I have a working flag/language management up to 0.111.3. FIne.

I read about the new 0.112.0 language management and somme previous error we made not using correctly the .site.Params parameters.

So I moved the reported problematic parameters in the right sections and change the code accordingly. No more warning.
But In one place I have a flaw in the flag/language logic.
After testing the productions code i couldn’t understand the problem. So I stripped down to something simple.

So I still do not understand why site.Params.languageFlag is now the same when I iterate on site.Languages. while .Params.languageFlag change accordingly to what I expected in my code.

Sorry to be a dumb one but any light / tip / link would be welcome.

## site.Languages : {{ site.Languages }}
{{- range .Page.AllTranslations }}
  {{- range site.Languages }}
##  site.Language               : {{ site.Language}}<br>
##  site.Language.Lang          : {{ site.Language.Lang }}<br>
##  site.Language.LanguageName  : {{ site.Language.LanguageName}}<br>
##      .Params.languageFlag : {{ .Params.languageFlag }}<br>
##  site.Params.languageFlag : {{ site.Params.languageFlag }}<br>
##             .LanguageName : {{.LanguageName}}<br>
##      .Params.languageName : {{ .Params.languageName }}<br>
##  site.Params.languageName : {{ site.Params.languageName }}<br>
##  site.Title               : {{ site.Title }}<br>
##      .Title               : {{ .Title }}<br>
##  site.Params.Title        : {{ site.Params.Title }}<br>
##      .Params.Title        : {{ .Params.Title }}<br>
##  site.Params.languageReserver  : {{ site.Params.languageReserver }}<br>
##      .Params.languageReserver  : {{ .Params.languageReserver }}<br>

<hr>
  {{ end }}
{{ end }}

languages.toml

[fr]
title = "Grand Hôtel & Kurhaus, Arolla : Hôtel Historique Suisse"
languageCode = "fr-fr"
languageName = "Français"
weight = 1

[fr.params]
languageFlag = "fr.png"
languageReserver = "francais"

[en]
title = "Grand Hotel & Kurhaus - Arolla : a Swiss Historic Hotel"
languageCode = "en-us"
languageName = "English"
weight = 2

[en.params]
languageFlag = "en.png"
languageReserver = "anglais"

###1 Output

## site.Languages : [fr en]
##  site.Language               : fr<br>
##  site.Language.Lang          : fr<br>
##  site.Language.LanguageName  : Français<br>
##      .Params.languageFlag : fr.png<br>
##  site.Params.languageFlag : fr.png<br>
##             .LanguageName : Français<br>
##      .Params.languageName : <br>
##  site.Params.languageName : <br>
##  site.Title               : Grand Hôtel &amp; Kurhaus, Arolla : Hôtel Historique Suisse<br>
##      .Title               : Grand Hôtel &amp; Kurhaus, Arolla : Hôtel Historique Suisse<br>
##  site.Params.Title        : <br>
##      .Params.Title        : <br>
##  site.Params.languageReserver  : francais<br>
##      .Params.languageReserver  : francais<br>

<hr>
  
##  site.Language               : fr<br>
##  site.Language.Lang          : fr<br>
##  site.Language.LanguageName  : Français<br>
##      .Params.languageFlag : en.png<br>
##  site.Params.languageFlag : fr.png<br>
##             .LanguageName : English<br>
##      .Params.languageName : <br>
##  site.Params.languageName : <br>
##  site.Title               : Grand Hôtel &amp; Kurhaus, Arolla : Hôtel Historique Suisse<br>
##      .Title               : Grand Hotel &amp; Kurhaus - Arolla : a Swiss Historic Hotel<br>
##  site.Params.Title        : <br>
##      .Params.Title        : <br>
##  site.Params.languageReserver  : francais<br>
##      .Params.languageReserver  : anglais<br>

<hr>
  

##  site.Language               : fr<br>
##  site.Language.Lang          : fr<br>
##  site.Language.LanguageName  : Français<br>
##      .Params.languageFlag : fr.png<br>
##  site.Params.languageFlag : fr.png<br>
##             .LanguageName : Français<br>
##      .Params.languageName : <br>
##  site.Params.languageName : <br>
##  site.Title               : Grand Hôtel &amp; Kurhaus, Arolla : Hôtel Historique Suisse<br>
##      .Title               : Grand Hôtel &amp; Kurhaus, Arolla : Hôtel Historique Suisse<br>
##  site.Params.Title        : <br>
##      .Params.Title        : <br>
##  site.Params.languageReserver  : francais<br>
##      .Params.languageReserver  : francais<br>

<hr>
  
##  site.Language               : fr<br>
##  site.Language.Lang          : fr<br>
##  site.Language.LanguageName  : Français<br>
##      .Params.languageFlag : en.png<br>
##  site.Params.languageFlag : fr.png<br>
##             .LanguageName : English<br>
##      .Params.languageName : <br>
##  site.Params.languageName : <br>
##  site.Title               : Grand Hôtel &amp; Kurhaus, Arolla : Hôtel Historique Suisse<br>
##      .Title               : Grand Hotel &amp; Kurhaus - Arolla : a Swiss Historic Hotel<br>
##  site.Params.Title        : <br>
##      .Params.Title        : <br>
##  site.Params.languageReserver  : francais<br>
##      .Params.languageReserver  : anglais<br>

<hr>

page and site are global function that always point to page and language currently being executed. It doesnt care whether it’s called inside range or with scope.

Thanks pamubay.
Yes, but we where using .Params.languageFlag and could not do it anymore with the deprecation.
The new syntax behave diffrently.

Original code is this for dealing with language flags options

{{ if .IsTranslated }}
          <div class="col-2 col-lg-2 mt-lg-0 text-white d-flex item-center">
            <ul class="list-inline lang-list">
              <li class="list-inline-item">
                <i class="fa-solid fa-globe me-0 me-sm-1"></i>
              </li>
              {{ $siteLanguages := site.Languages }}
              {{ $pageLang := .Page.Lang }}
              {{ range .Page.AllTranslations }}
                {{ $translation := . }}
                {{ range $siteLanguages }}
                  {{ if eq $translation.Lang .Lang }}
                    {{ $selected := false }}
                    <li
                      class="list-inline-item {{ if eq $pageLang .Lang }}
                        active
                      {{ end }}"
                      onclick="location={{ $translation.RelPermalink }}"
                      title="{{ .LanguageName }}">
                      <img
                        class="mb-0"
                        src="{{ .Params.languageFlag | absURL }}"
                        alt="{{ .LanguageName }}" />
                    </li>
                  {{ end }}
                {{ end }}
              {{ end }}
            </ul>
          </div>
        {{ end }}

Yes, i think it’s a bug, the WARN triggered if site .Params accessed via .Language.Params, meanwhile the site.Languages iterating *langs.Language collection.

In case you’re not aware, @divinerites: Why flags do not represent languages – Flags are not languages

2 Likes

It’s not a bug, but I’m having second thoughts, see

There are ways to rewrite @divinerites ’ template above (and probably make it simpler), but I guess there are many situations where having .Language.Params (as an alias to .Site.Params) be practical … I will ponder about this over the weekend and do a patch release with misc. on Monday.

Sorry for the confusion …

3 Likes

I guess you’re kidding Bep !!

Thanks Pamubai & bep for explanations. I will look at the code (from a theme) and see If i can do better … Thanks.

So, this isn’t tested, but should be logically correct (I think):

{{ if .IsTranslated }}
  <div class="col-2 col-lg-2 mt-lg-0 text-white d-flex item-center">
    <ul class="list-inline lang-list">
      <li class="list-inline-item">
        <i class="fa-solid fa-globe me-0 me-sm-1"></i>
      </li>
      {{ $page := .Page }}
      {{ range .Page.AllTranslations }}
        <li
          class="list-inline-item {{ if eq . $page }}active{{ end }}"
          onclick="location={{ .RelPermalink }}"
          title="{{ .Language.LanguageName }}">
          <img
            class="mb-0"
            src="{{ .Site.Params.languageFlag | absURL }}"
            alt="{{ .Language.LanguageName }}" />
        </li>
      {{ end }}
    </ul>
  </div>
{{ end }}

I had a similar encounter. What I did was to switch to .Site.Params instead of site.Params.

So now my language selectors are something like this:

<a href="{{ .Permalink }}" lang="{{ .Site.LanguageCode }}" class="translation-active" title="{{ .Site.Language.LanguageName }}"><span class="lang-flag-large">{{ .Site.Params.languageFlag }}</span></a>

{{ if .IsTranslated }}
  {{ range .Translations }}
    <a href="{{ .Permalink }}" lang="{{ .Site.LanguageCode }}" class="translation-alt" title="{{ .Site.Language.LanguageName }}" rel="alternate"><span class="lang-flag-large">{{ .Site.Params.languageFlag }}</span></a>
  {{ end }}
{{ else }}
  {{ range .Site.Languages }}
    {{ if ne .Lang $.Site.Language.Lang }}
      <span class="translation-none lang-flag-large" title="{{ .LanguageName }}">{{ $.Site.Params.languageFlag }}</span>
    {{ end }}
  {{ end }}
{{ end }}