From a0016f50f6b9c80a1e2cf0bc8f9855db137a12a7 Mon Sep 17 00:00:00 2001 From: Haris Trgo Date: Mon, 13 Feb 2023 21:32:40 +0100 Subject: [PATCH] feat: new language switch behaviour, always listing all languages by weight but linking to translations if available feat: if language switch shows language codes (instead of full language name), those codes are now uppercase feat: translation list in post headers are replaced by links to translations in page headers - the old translation list in the post header can still be enabled using the boolean parameter "showTranslationListInPosts" (i.e. to turn it back on, add the parameter to your hugo.toml and set it to true) --- README.md | 2 +- layouts/_default/search.html | 8 ++--- layouts/_default/single.html | 4 ++- layouts/partials/header.html | 57 +++++++++++++++++++++++------------- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 51787750..1083dd51 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ - Social Icons (home-info and profile-mode) - Social-Media Share buttons on posts. - Menu location indicator. -- Multilingual support. (with language selector) +- Multilingual support (with improved language selector) - Taxonomies - Cover image for each post (with Responsive image support). - Light/Dark theme (automatic theme switch a/c to browser theme and theme-switch button). diff --git a/layouts/_default/search.html b/layouts/_default/search.html index 2349587b..7addf257 100644 --- a/layouts/_default/search.html +++ b/layouts/_default/search.html @@ -13,10 +13,10 @@ {{ .Description }} {{- end }} - {{- if not (.Param "hideMeta") }} -
- {{- partial "translation_list.html" . -}} -
+ {{- if and (.Param "showTranslationListInPosts") (not (.Param "hideMeta")) }} +
+ {{- partial "translation_list.html" . -}} +
{{- end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index b7497255..ef4dfad2 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -15,7 +15,9 @@ {{- if not (.Param "hideMeta") }}
{{- partial "post_meta.html" . -}} - {{- partial "translation_list.html" . -}} + {{- if .Param "showTranslationListInPosts" }} + {{- partial "translation_list.html" . -}} + {{- end }} {{- partial "edit_post.html" . -}} {{- partial "post_canonical.html" . -}}
diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 4a7291e2..2135456b 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -96,27 +96,42 @@ {{- end }} - {{- $lang := .Lang}} - {{- $separator := or $label_text (not site.Params.disableThemeToggle)}} - {{- with site.Home.AllTranslations }} - - {{- end }} + {{/* LANGUAGE SELECTOR */}} + {{ if .Site.IsMultiLingual }} + {{/* set vars with page data */}} + {{ $currentLang := .Lang }} + {{ $allTranslations := .Translations }} + + {{ $separator := or $label_text (not site.Params.disableThemeToggle)}} + + + {{ end }} {{- $currentPage := . }}