{{- /* Links to this page in the other language; falls back to that language's home. */ -}}
<span class="lang-switch">
  {{- range .Site.Languages -}}
    {{- $lang := . -}}
    {{- if eq $lang.Lang $.Site.Language.Lang -}}
      <span class="lang current" aria-current="true">{{ $lang.LanguageName }}</span>
    {{- else -}}
      {{- $target := "" -}}
      {{- range $.AllTranslations -}}
        {{- if eq .Language.Lang $lang.Lang -}}{{- $target = .RelPermalink -}}{{- end -}}
      {{- end -}}
      {{- if not $target -}}{{- $target = ($lang.Lang | printf "/%s/" | relURL) -}}{{- end -}}
      <a class="lang" href="{{ $target }}" lang="{{ $lang.LanguageCode }}">{{ $lang.LanguageName }}</a>
    {{- end -}}
  {{- end -}}
</span>
