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

29 lines
927 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
{{ $pageLang := $context.Lang }}
2023-06-04 06:41:48 +00:00
{{ $base:= urls.Parse site.BaseURL }}
{{ $siteLanguages := site.Home.AllTranslations }}
2023-06-05 10:48:12 +00:00
{{ $pageLink := replace (replace $context.RelPermalink (add $pageLang "/") "") $base.Path "/" }}
2023-05-25 10:41:54 +00:00
{{ if $context.IsTranslated }}
2024-01-29 11:13:42 +00:00
<select class="{{ $class }} lang-select" onchange="location = this.value">
2023-05-25 10:41:54 +00:00
{{ 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 }}