feat(i18n): detect browser language, drive locales from one table - #5
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe PR centralizes locale metadata and utilities. It adds multi-locale switching, browser-language redirects, localized badges, metadata-driven configuration, and documentation for adding languages and storing language preferences locally. ChangesLocale support
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Browser
participant BaseLayout
participant RedirectTargets
participant LocalizedPage
Browser->>BaseLayout: Load default-locale page
BaseLayout->>RedirectTargets: Read locale redirect candidates
RedirectTargets-->>BaseLayout: Return localized URLs
BaseLayout->>Browser: Match stored or browser language
Browser->>LocalizedPage: Navigate with query and hash preserved
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/components/LangSwitch.astro (1)
93-126: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove
is:inlinefrom theLangSwitchscript.This script does not run before paint or require verbatim output. Use a processed
<script>to enable Astro’s TypeScript diagnostics and script deduplication. Type the queried elements and event values as needed.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/LangSwitch.astro` around lines 93 - 126, Remove is:inline from the LangSwitch script so Astro processes it, then add the necessary TypeScript annotations for queried menu/link elements and event targets or values while preserving the existing behavior. Keep the click, storage, menu-closing, and Escape-key handling unchanged, relying on Astro’s processed-script deduplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/layouts/Base.astro`:
- Around line 60-68: Update the langRedirect condition in Base.astro to require
noLangSwitch to be disabled before creating browser redirect targets. Preserve
the existing DEFAULT_LOCALE and noindex checks, and ensure pages marked
noLangSwitch produce no redirect configuration.
---
Nitpick comments:
In `@src/components/LangSwitch.astro`:
- Around line 93-126: Remove is:inline from the LangSwitch script so Astro
processes it, then add the necessary TypeScript annotations for queried
menu/link elements and event targets or values while preserving the existing
behavior. Keep the click, storage, menu-closing, and Escape-key handling
unchanged, relying on Astro’s processed-script deduplication.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 789bc8f6-b662-45cd-9374-ea30b1b5873a
📒 Files selected for processing (12)
README.mdastro.config.tssrc/components/LangSwitch.astrosrc/components/ui/StoreBadges.astrosrc/i18n/de.tssrc/i18n/en.tssrc/i18n/locales.tssrc/i18n/utils.tssrc/layouts/Base.astrosrc/layouts/Legal.astrosrc/pages/de/privacy.mdxsrc/pages/privacy.mdx
GitHub Pages serves static files, so there is no Accept-Language to branch on: an inline pre-paint script in Base.astro redirects instead. Only the unprefixed URLs redirect — a prefixed one is an explicit choice, which keeps shared links in their language and makes a loop impossible. Using the header switch records the choice in localStorage, where it outranks detection from then on; without that the redirect would trap anyone whose browser language isn't the one they want. The same change generalises the locale handling, because a third language would otherwise have rendered while being invisible to detection, the switch, og:locale, date formatting and the Play badge. src/i18n/locales.ts is now the only place a language is declared, and astro.config.ts derives its routes and sitemap from it rather than repeating the list. The switch turns into a dropdown from three languages on; LOCALIZED_SLUGS became Partial so that translated slugs stay opt-in instead of a type error. Both privacy pages now name the second localStorage key, since they claimed the theme preference was the only thing this site stores.
e0d3c8c to
98f9273
Compare
GitHub Pages serves static files, so there is no Accept-Language to branch on: an inline pre-paint script in Base.astro redirects instead. Only the unprefixed URLs redirect — a prefixed one is an explicit choice, which keeps shared links in their language and makes a loop impossible. Using the header switch records the choice in localStorage, where it outranks detection from then on; without that the redirect would trap anyone whose browser language isn't the one they want.
The same change generalises the locale handling, because a third language would otherwise have rendered while being invisible to detection, the switch, og:locale, date formatting and the Play badge. src/i18n/locales.ts is now the only place a language is declared, and astro.config.ts derives its routes and sitemap from it rather than repeating the list. The switch turns into a dropdown from three languages on; LOCALIZED_SLUGS became Partial so that translated slugs stay opt-in instead of a type error.
Both privacy pages now name the second localStorage key, since they claimed the theme preference was the only thing this site stores.
Summary by CodeRabbit
New Features
Documentation
Bug Fixes