chill_hugoplate/layouts/partials/components/language-switcher.html

29 lines
887 B
HTML
Raw Normal View History

2023-05-25 10:41:54 +00:00
<!-- Language List -->
{{ $class := .Class }}
{{ $context := .Context }}
2023-06-04 05:07:38 +00:00
{{ $siteLanguages := site.Home.AllTranslations }}
{{ $pageLang := $context.Lang }}
{{ $pageLink := replace $context.RelPermalink $pageLang "" }}
{{ $pageLink = replace $pageLink "//" "/" }}
2023-05-25 10:41:54 +00:00
{{ if $context.IsTranslated }}
<select class="{{ $class }}" onchange="location = this.value">
{{ range $siteLanguages }}
{{ if eq (string $pageLang) (string .Language) }}
2023-06-04 05:07:38 +00:00
<option
id="{{ .Language }}"
value="{{ replace (add .RelPermalink $pageLink) `//` `/` }}"
selected>
2023-05-25 10:41:54 +00:00
{{ .Language.LanguageName }}
</option>
{{ else }}
2023-06-04 05:07:38 +00:00
<option
id="{{ .Language }}"
value="{{ replace (add .RelPermalink $pageLink) `//` `/` }}">
2023-05-25 10:41:54 +00:00
{{ .Language.LanguageName }}
</option>
{{ end }}
{{ end }}
</select>
{{ end }}