mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-12-06 09:57:39 +09:00
## Summary
- **P1**: Replace 5 duplicate non-locale route pages (`/app`,
`/app/jobs`, `/auth/verify`, `/payment/success`, `/order/success`) with
thin `LocaleRedirect` component — detects locale from
localStorage/navigator and redirects to `/{locale}/...`
- **P2**: Localize all user-facing email bodies (7 inline types + 4
template defaults + shared footer). Adds ~80 translation keys to
en/es/de.json. Template service now tries locale-specific GCS paths
before falling back to localized defaults.
- Fix admin dropdown link using locale-aware Link (should use NextLink
since `/admin` is outside locale routing)
### Email types localized
Magic link, welcome, credits added, review reminder, review expired,
made-for-you order confirmation, credit denied, action reminder alert,
job completion/action needed/YouTube upload template defaults, shared
footer
### Not localized (intentionally)
Admin-only: feedback notification, credit review, admin order
notification
## Test plan
- [x] Backend: 2668 tests pass (139 skipped)
- [x] Frontend: `next build` succeeds with all locale directories
- [x] CodeRabbit: 1 finding fixed (admin dropdown link)
- [ ] Post-deploy: verify Spanish user receives localized email body
(magic link flow)
- [ ] Post-deploy: verify `/app` redirects to `/{locale}/app`
<!-- @coderabbitai ignore -->
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect } from 'react';
|
|
import { routing } from '@/i18n/routing';
|
|
|
|
/**
|
|
* Detects the user's preferred locale and redirects to the locale-prefixed
|
|
* version of the current URL. Preserves path, query string, and hash.
|
|
*
|
|
* Used by legacy non-locale routes (e.g., /app → /en/app) to redirect
|
|
* to the proper [locale] routes.
|
|
*/
|
|
export function LocaleRedirect() {
|
|
useEffect(() => {
|
|
const locale = detectLocale();
|
|
const { pathname, search, hash } = window.location;
|
|
window.location.replace(`/${locale}${pathname}${search}${hash}`);
|
|
}, []);
|
|
|
|
return null;
|
|
}
|
|
|
|
function detectLocale(): string {
|
|
// 1. Check localStorage for saved preference
|
|
try {
|
|
const saved = localStorage.getItem('locale');
|
|
if (saved && routing.locales.includes(saved as typeof routing.locales[number])) {
|
|
return saved;
|
|
}
|
|
} catch {
|
|
// localStorage not available
|
|
}
|
|
|
|
// 2. Detect from browser language
|
|
const browserLangs = navigator.languages || [navigator.language];
|
|
for (const lang of browserLangs) {
|
|
const prefix = lang.split('-')[0].toLowerCase();
|
|
if (routing.locales.includes(prefix as typeof routing.locales[number])) {
|
|
return prefix;
|
|
}
|
|
}
|
|
|
|
// 3. Fallback to default
|
|
return routing.defaultLocale;
|
|
}
|