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 | |
| parent | f8541ef965ca22e746b523eb418e47cb4f78f2d8 (diff) | |
Replaced deprecated language methods & settings from hugo v0.156.0 & v0.158.0
| -rw-r--r-- | hugo.toml | 10 | ||||
| -rw-r--r-- | layouts/_partials/select-language.html | 32 | ||||
| -rw-r--r-- | layouts/baseof.html | 2 | ||||
| -rw-r--r-- | layouts/rss.xml | 2 |
4 files changed, 22 insertions, 24 deletions
@@ -1,5 +1,5 @@ baseURL = "https://example.org/" -languageCode = "en-US" +locale = "en" title = "Your Website Name" enableRobotsTXT = true # Copy this line to your project's hugo.toml @@ -16,8 +16,8 @@ disableDefaultLanguageRedirect = false [languages] [languages.de] contentDir = "content/de" - languageCode = "de-DE" - languageName = "Deutsch" + locale = "de" + label = "Deutsch" weight = 2 [[languages.de.menus.main]] @@ -41,8 +41,8 @@ disableDefaultLanguageRedirect = false [languages.en] contentDir = "content/en" - languageCode = "en-US" - languageName = "English" + locale = "en" + label = "English" weight = 1 [menus] 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> diff --git a/layouts/baseof.html b/layouts/baseof.html index 99f09d9..a6a1439 100644 --- a/layouts/baseof.html +++ b/layouts/baseof.html @@ -1,5 +1,5 @@ <!DOCTYPE html> -<html lang="{{ .Language.LanguageCode }}" dir="{{ .Language.LanguageDirection | default "ltr" }}"> +<html lang="{{ .Language.Locale }}" dir="{{ .Language.Direction | default "ltr" }}"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> diff --git a/layouts/rss.xml b/layouts/rss.xml index 9f70eb5..ea4ddc0 100644 --- a/layouts/rss.xml +++ b/layouts/rss.xml @@ -37,7 +37,7 @@ <link>{{ .Permalink }}</link> <description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ .Site.Title }}</description> <generator>Hugo</generator> - <language>{{ site.Language.LanguageCode }}</language> + <language>{{ site.Language.Locale }}</language> {{- with $authorName }}<managingEditor>{{ . }}</managingEditor>{{ end }} {{- with $authorName }}<webMaster>{{ . }}</webMaster>{{ end }} {{- with .Site.Copyright }}<copyright>{{ . }}</copyright>{{ end }} |
