Skip to content

Add zh-hans translation for accessibility guide, filter language switcher to translated articles - #3736

Open
czllll wants to merge 3 commits into
github:mainfrom
czllll:fix/a11y-zh-hans-and-language-switcher
Open

Add zh-hans translation for accessibility guide, filter language switcher to translated articles#3736
czllll wants to merge 3 commits into
github:mainfrom
czllll:fix/a11y-zh-hans-and-language-switcher

Conversation

@czllll

@czllll czllll commented Aug 22, 2026

Copy link
Copy Markdown
  • Have you followed the contributing guidelines?
  • Have you explained what your changes do, and why they add value to the Guides?

What this does

  1. Adds a zh-hans translation of accessibility-best-practices-for-your-project.md, following the process in docs/translations.md: front matter field names and non-string values unchanged, title/description/body translated, untranslated field removed.
  2. Fixes the language switcher (_includes/nav.html) and the hreflang alternate tags (_includes/head.html) so, on article pages, only locales that actually have a translation of the current article are offered/linked. Both used the same unconditional loop over every locale, matched via site.articles | where: 'lang' | where: 'class' — the same lookup already used for related-article links in _layouts/article.html.

Why it adds value

accessibility-best-practices-for-your-project currently has no translation in any locale, and picking any language from the nav selector on that article 404s — that's how I found this. The underlying bug isn't specific to this one article: any under-translated article will 404 the same way when a reader switches languages, and (per html-proofer, see below) also ships dead hreflang links for SEO crawlers. This fixes the mechanism for all articles, not just this one, and adds one more translated article in the process.

Test plan

  • Verified with curl that /accessibility-best-practices-for-your-project/ returned 200 in English and 404 in ~10 other locales before this change.
  • Could not run script/test locally (this environment's Ruby is newer than the github-pages gem in the Gemfile supports, so bundle install fails to resolve). The first commit's fix (nav.html only) went through CI instead: html-proofer failed the build with 27 dead internal links from the new zh-hans page — one hreflang tag per locale still lacking the translation, coming from _includes/head.html, which had the identical unconditional-loop bug. That's what the second fix commit addresses.

czllll added 2 commits August 23, 2026 03:29
Follows the process in docs/translations.md: translated title/description
and body, kept front matter field names and non-string values unchanged,
and removed the untranslated field now that the translation exists.
The language switcher listed every locale regardless of whether the
current article had a translation in it. Picking an untranslated
language for an article-type page sent the reader to a 404, since
loadLanguage() in assets/js/locale.js rewrites the URL's language
segment without checking the target page exists.

Filter the dropdown at render time using the same
site.articles | where: 'lang' / where: 'class' lookup already used in
_layouts/article.html for related-article links, so only languages that
actually carry a translation of the current article are offered. Non-article
pages (index, static pages) are unaffected since every locale ships those.
@czllll
czllll requested a review from a team as a code owner August 22, 2026 19:37
_includes/head.html has the same bug as _includes/nav.html: it builds
an hreflang link for every locale unconditionally, so an under-translated
article ships <link rel="alternate" hreflang="..."> tags pointing at pages
that 404. CI caught this via html-proofer's internal-link check on the new
zh-hans article (27 dead links, one per locale lacking the translation).

Apply the same site.articles | where: 'lang' / where: 'class' guard used
in nav.html and in the existing related-article lookup in article.html.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant