summaryrefslogtreecommitdiff
path: root/layouts/_partials/select-language.html
blob: 5cb4a25df23362f26cc96c0edff2702690b01f8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{{- /*
Selection of available languages.
Dynamically links to corresponding versions of a page/post in other languages if translations exists.

Note: `.Site.Language.Name` and `.Site.Language.Locale` are interchangable with Argo's default hugo.toml configuration of `locale = "en"`.
Yet the differentiation is deliberately maintained here in case a user defines their locale to e.g. "en-US";
*/ -}}

{{- $pageVersionsList := .Rotate "language" }}
{{- if gt (len $pageVersionsList) 1 }}
    <div class="language-select">
        <ul class="language-select__language-list">
        {{- range $pageVersionsList }}
            {{- $activeLang := $.Site.Language }}
            {{- $currentLang := .Site.Language }}
            {{- if ne $activeLang $currentLang }}
                <li class="language-select__language-item">
                    <a
                        href="{{ .RelPermalink }}"
                        hreflang="{{ $currentLang.Locale }}"
                        aria-label="{{ .LinkTitle }} ({{ or $currentLang.Label $currentLang.Name }})"
                        title="{{ or $currentLang.Label $currentLang.Name }}"
                    >
                        <img
                            src="/flags/{{ $currentLang.Name }}.svg"
                            class="icon icon-flag"
                            alt="{{ .LinkTitle }} ({{ or $currentLang.Label $currentLang.Name }})"
                            aria-hidden="true"
                        />
                    </a>
                </li>
            {{- end }}
        {{- end }}
        </ul>
    </div>
{{- end }}