{{ $bookTranslatedOnly := default false .Site.Params.BookTranslatedOnly }}
{{ $translations := dict }}
{{ if (eq $bookTranslatedOnly false ) }}
  {{ range .Site.Home.Translations }}
    {{ $translations = merge $translations (dict .Language.Lang .) }}
  {{ end }}
{{ end }}
{{ range .Translations }}
  {{ $translations = merge $translations (dict .Language.Lang .) }}
{{ end }}

<ul class="book-languages">
  <li>
    <input type="checkbox" id="languages" class="toggle" />
    <label for="languages" class="flex">
      <a role="button">
        <img src="{{ partial "docs/icon" "translate" }}" class="book-icon" alt="{{ partial "docs/text/i18n" "Languages" }}" />
        {{ $.Site.Language.LanguageName }}
      </a>
      <img src="{{ partial "docs/icon" "chevron-right" }}" class="book-icon" alt="{{ partial "docs/text/i18n" "Expand" }}" />
    </label>

    <ul>
      {{ range .Site.Languages }}{{ with index $translations .Lang }}
      <li>
        <a href="{{ cond hugo.IsMultihost .Permalink .RelPermalink }}" class="flex flex-auto">
          {{ .Language.LanguageName }}
        </a>
      </li>
      {{ end }}{{ end }}
    </ul>
  </li>
</ul>
