Skip to content

fix: language switch matches translated page, translate TOC, fix 404#34

Merged
usarral merged 2 commits into
mainfrom
claude/language-switch-page-match-I8NQG
May 24, 2026
Merged

fix: language switch matches translated page, translate TOC, fix 404#34
usarral merged 2 commits into
mainfrom
claude/language-switch-page-match-I8NQG

Conversation

@usarral
Copy link
Copy Markdown
Owner

@usarral usarral commented May 24, 2026

$(cat <<'EOF'

Summary

  • Language switcher now navigates to the correct translated page: LangToggle reads <link rel="alternate" hreflang> from the document head instead of doing a naive path substitution. For blog posts, the [...slug].astro page computes the translated post slug at build time and passes the correct alternate URLs down through BlogPost → Base → BaseHead, which emits accurate hreflang tags (e.g. /en/posts/docker-installation//es/posts/docker-installation-es/). This also improves SEO.
  • TOC title is now translated: The TOC component was hardcoded to "Table of Contents". It now accepts a locale prop and uses the i18n t("toc.title") translation key ("Tabla de contenidos" in Spanish).
  • Root 404 no longer shows both languages: A client-side script detects the user's locale (from URL prefix, lang cookie, or browser language) and redirects to the locale-specific 404 page (/en/404 or /es/404).

Test plan

  • Visit /en/posts/docker-installation/, click the language switcher → should navigate to /es/posts/docker-installation-es/ (not 404)
  • Visit /es/posts/docker-installation-es/, click the language switcher → should navigate to /en/posts/docker-installation/
  • Language switcher on non-post pages (home, about, tags) still works as before
  • TOC on an English post shows "Table of Contents", on a Spanish post shows "Tabla de contenidos"
  • Visiting a non-existent URL under /es/... shows the Spanish 404 (not both languages)

https://claude.ai/code/session_01Ue6yERWgLpZpLmVfqqSY3E
EOF
)


Generated by Claude Code

- LangToggle now reads <link rel="alternate" hreflang> from the DOM
  instead of doing a naive path substitution, so switching language on
  a blog post navigates to the correct translated slug
  (e.g. /en/posts/docker-installation/ → /es/posts/docker-installation-es/)
- [...slug].astro computes the translated post at build time and passes
  the correct alternate URLs through BlogPost → Base → BaseHead, which
  emits accurate hreflang tags (also a SEO improvement)
- TOC component now uses the i18n translation system ("toc.title")
  instead of the hardcoded English string "Table of Contents"
- Root 404 redirects client-side to the locale-specific 404 page
  (detected from URL prefix, lang cookie, or browser language) instead
  of displaying both languages at once

https://claude.ai/code/session_01Ue6yERWgLpZpLmVfqqSY3E
@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
usarral-2026-site Ready Ready Preview, Comment May 24, 2026 12:18pm

@usarral usarral marked this pull request as ready for review May 24, 2026 12:24
@usarral usarral merged commit 3398129 into main May 24, 2026
3 checks passed
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.

2 participants