Merge pull request #1606 from gethinode/develop

feat: enable optional inline language selector
This commit is contained in:
Mark Dumay
2025-10-04 10:22:17 +02:00
committed by GitHub
3 changed files with 35 additions and 15 deletions

View File

@@ -392,3 +392,17 @@
.form-control.is-search { .form-control.is-search {
border: 1px solid var(--bs-border-color) !important; border: 1px solid var(--bs-border-color) !important;
} }
.inline-menu li {
display: inline-block;
padding: 0.5rem;
color: var(--bs-nav-link-color);
}
.inline-menu li .active, .inline-menu li>a:hover {
box-shadow: inset 0 -1px 0 var(--bs-navbar-hover-color);
}
ul.inline-menu {
padding: 0;
}

View File

@@ -61,6 +61,7 @@
maxNumHeadings = 9 maxNumHeadings = 9
[navigation.language] [navigation.language]
icon = "fas globe" icon = "fas globe"
inline = false
[navigation.padding] [navigation.padding]
x = 4 x = 4
y = 4 y = 4

View File

@@ -4,34 +4,39 @@
{{- $pretty := .pretty -}} {{- $pretty := .pretty -}}
{{- $icon := .icon | default "fas globe" -}} {{- $icon := .icon | default "fas globe" -}}
{{- $fs := .fs | default 6 -}} {{- $fs := .fs | default 6 -}}
{{- $inline := site.Params.navigation.language.inline | default false -}}
{{- $class := cond $inline "inline-menu" "dropdown-menu dropdown-menu-end" }}
{{- $lang := $page.Language.Lang -}} {{- $lang := $page.Language.Lang -}}
<li class="nav-item dropdown me-auto"> <li class="nav-item dropdown me-auto">
<a class="nav-link dropdown-toggle d-{{ $breakpoint }}-none" role="button" data-bs-toggle="dropdown" {{ if not $inline }}
aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false"> <a class="nav-link dropdown-toggle d-{{ $breakpoint }}-none" role="button" data-bs-toggle="dropdown"
{{- partial "assets/icon.html" (dict "icon" (printf "%s fa-fw" $icon) "spacing" true) }}{{ T "languageSwitcherLabel" }} aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false">
</a> {{- partial "assets/icon.html" (dict "icon" (printf "%s fa-fw" $icon) "spacing" true) }}{{ T "languageSwitcherLabel" }}
<a class="nav-link dropdown-toggle d-none d-{{ $breakpoint }}-block" role="button" data-bs-toggle="dropdown" </a>
aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false"> <a class="nav-link dropdown-toggle d-none d-{{ $breakpoint }}-block" role="button" data-bs-toggle="dropdown"
{{- partial "assets/icon.html" (dict "icon" (printf "%s fa-fw" $icon) "spacing" false) }} aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false">
</a> {{- partial "assets/icon.html" (dict "icon" (printf "%s fa-fw" $icon) "spacing" false) }}
<ul id="language-selector" class="dropdown-menu dropdown-menu-end navbar-fs-{{ $fs }} navbar-{{ $breakpoint }}-fs" data-translated="{{ $page.IsTranslated }}"> </a>
{{ end }}
<ul id="language-selector" class="{{ $class }} navbar-fs-{{ $fs }} navbar-{{ $breakpoint }}-fs" data-translated="{{ $page.IsTranslated }}">
{{- if $page.IsTranslated -}} {{- if $page.IsTranslated -}}
{{- range $page.AllTranslations -}} {{- range $page.AllTranslations -}}
<li> <li>
{{- $state := cond (eq .Language.Lang $lang) "active" "" }} {{- $state := cond (eq .Language.Lang $lang) "active" "" }}
<a class="dropdown-item {{ $state }}" hreflang="{{ .Language.Lang }}" href="{{ .RelPermalink }}"> <a class="dropdown-item {{ $state }}" hreflang="{{ .Language.Lang }}" href="{{ .RelPermalink }}">
{{- .Language.LanguageName -}} {{- cond $inline (upper .Language.Lang) .Language.LanguageName -}}
</a> </a>
</li> </li>
{{- end -}} {{- end -}}
{{- else -}} {{- else -}}
{{- range site.Languages -}} {{- range site.Languages -}}
{{ $dest := partial "utilities/URLJoin.html" (dict "base" $baseURL "path" .Lang) }} <li>
{{ if and $pretty (not (hasSuffix $dest "/")) }} {{- $state := cond (eq .Lang $lang) "active" "disabled" }}
{{ $dest = printf "%s/" $dest }} <a class="dropdown-item {{ $state }}" href="{{ cond (eq $state "active") $page.RelPermalink "#!" }}" hreflang="{{ .Lang }}">
{{ end }} {{- cond $inline (upper .Lang) (default .Lang .LanguageName) -}}
<li><a class="dropdown-item" href="{{ $dest }}" hreflang="{{ .Lang }}">{{ default .Lang .LanguageName }}</a></li> </a>
</li>
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
</ul> </ul>