<!-- Merge home and current page translations -->
{{ $bookTranslatedOnly := default false .Site.Params.BookTranslatedOnly }}
{{ $translations := dict }}
{{ if (eq $bookTranslatedOnly false ) }}
  {{ range .Site.Home.AllTranslations }}
    {{ $translations = merge $translations (dict .Language.Lang .) }}
  {{ end }}
{{ end }}
{{ range .Translations }}
  {{ $translations = merge $translations (dict .Language.Lang .) }}
{{ end }}

<div class="book-languages" tabindex="0" aria-haspopup="true">
  <ul>
    <li class="flex align-center">
      <img src="{{ "svg/translate.svg" | relURL }}" class="book-icon" alt="Languages" />
      {{ $.Site.Language.LanguageName }}
    </li> 
  </ul>

  <ul class="book-languages-list">
    {{ range .Site.Languages }}{{ with index $translations .Lang }}
    <li class="{{ if (eq $.Site.Language .Language) }}active{{ end }}">
      <a href="{{ .Permalink }}" class="flex align-center">
        <img src="{{ "svg/translate.svg" | relURL }}" class="book-icon" alt="Languages" />
        {{ .Language.LanguageName }}
      </a>
    </li>
    {{ end }}{{ end }}
  </ul>
</div>
