chill_hugoplate/layouts/partials/components/language-switcher.html
2023-06-04 11:07:38 +06:00

29 lines
887 B
HTML

<!-- Language List -->
{{ $class := .Class }}
{{ $context := .Context }}
{{ $siteLanguages := site.Home.AllTranslations }}
{{ $pageLang := $context.Lang }}
{{ $pageLink := replace $context.RelPermalink $pageLang "" }}
{{ $pageLink = replace $pageLink "//" "/" }}
{{ if $context.IsTranslated }}
<select class="{{ $class }}" onchange="location = this.value">
{{ range $siteLanguages }}
{{ if eq (string $pageLang) (string .Language) }}
<option
id="{{ .Language }}"
value="{{ replace (add .RelPermalink $pageLink) `//` `/` }}"
selected>
{{ .Language.LanguageName }}
</option>
{{ else }}
<option
id="{{ .Language }}"
value="{{ replace (add .RelPermalink $pageLink) `//` `/` }}">
{{ .Language.LanguageName }}
</option>
{{ end }}
{{ end }}
</select>
{{ end }}