i18n
Technical notes on web development, DevOps, and AI integration.
2 articles
- 11:46frontend
A Next.js Locale Switcher That Doesn't Lose Your Visitor
Build a Next.js App Router locale switcher that preserves the current path with usePathname and a regex swap, plus an accessible active state.
TL;DR: A naive locale switcher sent users to the locale homepage instead of the same page. The fix: a small client component that swaps the /en or /id prefix while preserving the rest of the pathname, plus aria-current for the active state. Stick with this for simple sites; adopt next-intl once routing grows complex.
#nextjs#i18n#accessibility - 11:00frontend
The /en/about Bug: When Next.js Pages Ignore Route Params
The /en page kept showing Indonesian content while the build stayed green: synchronous page components that ignore params. The fix is obvious once you see it.
TL;DR: The /en pages rendered Indonesian because four page components were synchronous and returned hardcoded locale content, so they never touched params at all. The fix: make each page async, await params, map locales to content, and guard unknown locales with hasLocale plus a 404. Green builds only prove components render, not that locale content is correct.
#nextjs#i18n#routing