33 lines
1.7 KiB
HTML
33 lines
1.7 KiB
HTML
{{- /* language-switcher.html — content LANGUAGE switcher (distinct from the region
|
|
switcher). The region switcher (locale-switcher.html) changes compliance
|
|
chrome (age/RG/currency) client-side; THIS switcher navigates to the
|
|
translated page of the SAME content (linked via front-matter translationKey).
|
|
Renders nothing on single-language builds. */ -}}
|
|
{{- if gt (len site.Languages) 1 -}}
|
|
<div class="relative">
|
|
<label for="language-switcher" class="sr-only">{{ i18n "selectLanguage" | default "Language" }}</label>
|
|
<select id="language-switcher" data-language-switcher
|
|
onchange="if(this.value){window.location.href=this.value;}"
|
|
class="rounded-md border border-secondary/20 bg-white py-1.5 pl-2 pr-7 text-sm text-secondary focus-visible:outline-primary">
|
|
{{- $cur := . -}}
|
|
{{- range site.Languages -}}
|
|
{{- $lang := . -}}
|
|
{{- $isCurrent := eq $lang.Lang $cur.Language.Lang -}}
|
|
{{- $href := "" -}}
|
|
{{- /* Prefer the direct translation of the current page… */ -}}
|
|
{{- range $cur.AllTranslations -}}
|
|
{{- if eq .Language.Lang $lang.Lang -}}{{- $href = .RelPermalink -}}{{- end -}}
|
|
{{- end -}}
|
|
{{- /* …otherwise fall back to that language's home page. */ -}}
|
|
{{- if not $href -}}
|
|
{{- with site.Home.AllTranslations -}}
|
|
{{- range . -}}{{- if eq .Language.Lang $lang.Lang -}}{{- $href = .RelPermalink -}}{{- end -}}{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- if not $href -}}{{- $href = "/" -}}{{- end -}}
|
|
<option value="{{ $href }}"{{ if $isCurrent }} selected{{ end }}>{{ $lang.LanguageName | default (upper $lang.Lang) }}</option>
|
|
{{- end -}}
|
|
</select>
|
|
</div>
|
|
{{- end -}}
|