feat: add multilingual fallback and locale detection#703
Merged
AnnabelJoe merged 2 commits intoJul 3, 2026
Conversation
- middleware.ts: detect locale from Accept-Language header, persist as cookie, forward as x-locale header to server components; fallback to 'en' - lib/i18n.ts: message catalogue (en/es/fr/de/pt) + getTranslations() with English fallback for missing keys - layout.tsx: reads x-locale header, sets <html lang> dynamically - api/locale/route.ts: POST endpoint to switch locale via cookie
|
@jessicanath Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #535
Adds a zero-dependency i18n layer: locale is detected from the browser's
Accept-Languageheader, persisted in a cookie, and forwarded to server components via a custom header. A message catalogue covers 5 locales with English fallback for missing keys.Changes
src/middleware.tsAccept-Language, reads/writeslocalecookie, forwardsx-localeheadersrc/lib/i18n.tsgetTranslations(locale)helper with English fallbacksrc/app/layout.tsxx-localeheader, sets<html lang>dynamicallysrc/app/api/locale/route.tsPOST /api/locale— lets the client explicitly switch localeSupported locales
en(default),es,fr,de,ptDesign decisions
next-intl/i18nextbundle weight; can migrate laterlocaleoverrides header detection so user preference persists across sessionsgetTranslations()falls back to English per-key, not per-locale — so partial translations don't break the UIPOST /api/locale) is ready to wire up to a language picker component