Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2025-02-27 - Language Switcher Accessibility and JS Compatibility
**Learning:** Multilingual websites must include `hreflang` and `lang` attributes on language switcher links. Without these, screen readers won't apply the correct pronunciation profiles for the target languages. Furthermore, the `static/js/language-toggle.js` script requires the container to have `id="lang-toggle"` and the links to have a `data-lang` attribute matching the language code (`{{ .Language.Lang }}`) to store and apply user language preferences.
**Action:** When implementing or updating language toggle navigation, always verify that `lang`, `hreflang`, and `data-lang` attributes are present on the links, and the correct container `id` is applied to ensure both robust accessibility and script compatibility.
28 changes: 23 additions & 5 deletions layouts/partials/header/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(dict "key" "library" "path" "library")
}}


<header class="gzen-header">
<a class="gzen-brand" href="{{ "" | relLangURL }}" aria-label="{{ .Site.Title }}">
<span class="gzen-brand-mark" aria-hidden="true">善</span>
Expand All @@ -24,28 +25,45 @@
{{ i18n "nav_ecosystem" | default "生态" }} <span class="gzen-dropdown-arrow">▾</span>
</button>
<div class="gzen-nav-dropdown-menu" role="menu">
<a href="{{ .Site.Params.ecosystem.ki | default "https://ki.gzen.io" }}" target="_blank" rel="noopener" role="menuitem">
<a
href="{{ .Site.Params.ecosystem.ki | default "https://ki.gzen.io" }}"
target="_blank"
rel="noopener"
role="menuitem">
<strong>ki.gzen.io</strong>
<span>{{ i18n "ecosystem_ki_title" | default "机与器" }}</span>
</a>
<a href="{{ .Site.Params.ecosystem.learn | default "https://learn.gzen.io" }}" target="_blank" rel="noopener" role="menuitem">
<a
href="{{ .Site.Params.ecosystem.learn | default "https://learn.gzen.io" }}"
target="_blank"
rel="noopener"
role="menuitem">
<strong>learn.gzen.io</strong>
<span>{{ i18n "ecosystem_learn_title" | default "知与学" }}</span>
</a>
<a href="{{ .Site.Params.ecosystem.invest | default "https://invest.gzen.io" }}" target="_blank" rel="noopener" role="menuitem">
<a
href="{{ .Site.Params.ecosystem.invest | default "https://invest.gzen.io" }}"
target="_blank"
rel="noopener"
role="menuitem">
<strong>invest.gzen.io</strong>
<span>{{ i18n "ecosystem_invest_title" | default "资与财" }}</span>
</a>
</div>
</div>
</nav>


{{ if .IsTranslated }}
<nav class="gzen-languages" aria-label="{{ i18n "read_in" | default "Languages" }}">
<nav
class="gzen-languages"
id="lang-toggle"
aria-label="{{ i18n "read_in" | default "Languages" }}">
{{ range sort .AllTranslations "Language.Weight" }}
<a
href="{{ .RelPermalink }}"
lang="{{ .Language.Lang }}"
hreflang="{{ .Language.Lang }}"
data-lang="{{ .Language.Lang }}"
{{ if eq .Language.Lang $.Site.Language.Lang }}aria-current="page"{{ end }}>
{{ .Language.Params.displayName | default .Language.LanguageName | default .Language.Lang }}
</a>
Expand Down