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

29 lines
924 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-04 09:18:31 +00:00
{{ $pageLink := replace (replace (replace $context.RelPermalink $pageLang "") "//" "/") $base.Path "/" }}
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 }}