Skip to content

feat: add multilingual fallback and locale detection#703

Merged
AnnabelJoe merged 2 commits into
AnnabelJoe:mainfrom
jessicanath:feat/535-i18n-locale-detection
Jul 3, 2026
Merged

feat: add multilingual fallback and locale detection#703
AnnabelJoe merged 2 commits into
AnnabelJoe:mainfrom
jessicanath:feat/535-i18n-locale-detection

Conversation

@jessicanath

Copy link
Copy Markdown
Contributor

Summary

Closes #535

Adds a zero-dependency i18n layer: locale is detected from the browser's Accept-Language header, 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

File What
src/middleware.ts Detects locale from Accept-Language, reads/writes locale cookie, forwards x-locale header
src/lib/i18n.ts Message catalogue (en, es, fr, de, pt) + getTranslations(locale) helper with English fallback
src/app/layout.tsx Reads x-locale header, sets <html lang> dynamically
src/app/api/locale/route.ts POST /api/locale — lets the client explicitly switch locale

Supported locales

en (default), es, fr, de, pt

Design decisions

  • No external i18n package added — avoids next-intl/i18next bundle weight; can migrate later
  • Cookie locale overrides header detection so user preference persists across sessions
  • getTranslations() falls back to English per-key, not per-locale — so partial translations don't break the UI
  • Locale switching API (POST /api/locale) is ready to wire up to a language picker component

jessicanath and others added 2 commits June 27, 2026 17:30
- 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
@drips-wave

drips-wave Bot commented Jul 3, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@AnnabelJoe AnnabelJoe merged commit 16c5362 into AnnabelJoe:main Jul 3, 2026
3 of 19 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.

Add multilingual fallback and locale detection

2 participants