diff options
| author | Arne Rief <riearn@proton.me> | 2026-04-09 18:31:14 +0200 |
|---|---|---|
| committer | Arne Rief <riearn@proton.me> | 2026-04-10 14:22:04 +0200 |
| commit | e9f46b1e5a2c41bfe1da702b3823d64fb3d64017 (patch) | |
| tree | 3e4ce3b6037ebb2283b008bb4524c3b65b099d75 /layouts/_partials/select-language.html | |
| parent | f8541ef965ca22e746b523eb418e47cb4f78f2d8 (diff) | |
Replaced deprecated language methods & settings from hugo v0.156.0 & v0.158.0
Diffstat (limited to 'layouts/_partials/select-language.html')
| -rw-r--r-- | layouts/_partials/select-language.html | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/layouts/_partials/select-language.html b/layouts/_partials/select-language.html index 6efcc61..5cb4a25 100644 --- a/layouts/_partials/select-language.html +++ b/layouts/_partials/select-language.html @@ -1,32 +1,30 @@ {{- /* Selection of available languages. -Dynamically links to corresponding page/post if a translated version exists, otherwise to homepage of that language as fallback. +Dynamically links to corresponding versions of a page/post in other languages if translations exists. -Note: `$activeLang` and `$allTranslationsForPage` are technically unnecessary variables, their values could be called with `$.Lang` and `$.Translations` respectively. -These variables - together with the explicit naming of `.` context variables in other cases - were chosen for better readability and understandability of the code. +Note: `.Site.Language.Name` and `.Site.Language.Locale` are interchangable with Argo's default hugo.toml configuration of `locale = "en"`. +Yet the differentiation is deliberately maintained here in case a user defines their locale to e.g. "en-US"; */ -}} -{{- if gt (len site.Languages) 1 }} -{{- $activeLang := .Lang }} -{{- $allTranslationsForPage := .Translations }} +{{- $pageVersionsList := .Rotate "language" }} +{{- if gt (len $pageVersionsList) 1 }} <div class="language-select"> <ul class="language-select__language-list"> - {{- range site.Languages }} - {{- $currLangSlice := . }} - {{- if ne $currLangSlice.Lang $activeLang }} - {{- $targetPage := index (where site.Home.Translations "Lang" $currLangSlice.Lang) 0 }} - {{- $translatedPage := index (where $allTranslationsForPage "Lang" $currLangSlice.Lang) 0 }} - {{- if $translatedPage }}{{- $targetPage = $translatedPage }}{{- end }} + {{- range $pageVersionsList }} + {{- $activeLang := $.Site.Language }} + {{- $currentLang := .Site.Language }} + {{- if ne $activeLang $currentLang }} <li class="language-select__language-item"> <a - href="{{ $targetPage.RelPermalink }}" - hreflang="{{ $targetPage.Lang }}" - aria-label="{{ $targetPage.LinkTitle }} ({{ or $targetPage.Language.LanguageName $targetPage.Lang }})" + href="{{ .RelPermalink }}" + hreflang="{{ $currentLang.Locale }}" + aria-label="{{ .LinkTitle }} ({{ or $currentLang.Label $currentLang.Name }})" + title="{{ or $currentLang.Label $currentLang.Name }}" > <img - src="/flags/{{ $targetPage.Lang }}.svg" + src="/flags/{{ $currentLang.Name }}.svg" class="icon icon-flag" - alt="{{ $targetPage.LinkTitle }} ({{ or $targetPage.Language.LanguageName $targetPage.Lang }})" + alt="{{ .LinkTitle }} ({{ or $currentLang.Label $currentLang.Name }})" aria-hidden="true" /> </a> |
