mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
@coderabbitai ignore
## Summary
- Phase 3 of the i18n multilingual initiative — makes the karaoke-gen
frontend fully multilingual (English, Spanish, German)
- Installs `next-intl` with `[locale]` path-based routing,
LanguageSwitcher, and `Accept-Language` API header
- Extracts **1,062 strings** from ~70 components into `messages/en.json`
across 31 namespaces
- Wires `useTranslations()` into all user-facing components (landing,
dashboard, auth, job flow, lyrics review, instrumental review, audio
editor, etc.)
- Admin pages (`/admin/*`) stay outside locale routing — intentionally
excluded from i18n scope
- Static export generates `/en/`, `/es/`, `/de/` directories (45 total
pages) for Cloudflare Pages
- `es.json`/`de.json` are English placeholders — translation via Gemini
pipeline pending
- Translation pipeline (`scripts/translate.py`) and glossary (55
karaoke-specific terms) included
## Key architecture decisions
- Root layout keeps ThemeProvider/TenantProvider (needed by admin pages
outside `[locale]`)
- Only NextIntlClientProvider added to `[locale]/layout.tsx`
- `job-status.ts` labels converted to translation keys; consumers
translate via `useTranslations('jobStatus')`
- Jest mock loads actual `en.json` so existing tests validate i18n
wiring without assertion changes
## Test plan
- [x] All 707 frontend tests pass (39 suites)
- [x] Static build generates all 45 pages across 3 locales
- [x] Admin pages render at `/admin/` without locale prefix
- [x] CodeRabbit review: 4 issues fixed, 7 pre-existing noted
- [ ] Post-deploy: verify `/en/` landing page renders correctly
- [ ] Post-deploy: verify LanguageSwitcher redirects to `/es/` and
`/de/`
- [ ] Post-deploy: verify `/admin/` still works without locale context
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
// Learn more: https://github.com/testing-library/jest-dom
|
|
import '@testing-library/jest-dom'
|
|
|
|
// Mock next-intl — loads actual English strings so tests see real text
|
|
const enMessages = require('./messages/en.json')
|
|
|
|
function getNestedValue(obj, dottedKey) {
|
|
return dottedKey.split('.').reduce((o, k) => (o && typeof o === 'object' ? o[k] : undefined), obj)
|
|
}
|
|
|
|
jest.mock('next-intl', () => ({
|
|
useTranslations: (namespace) => {
|
|
const messages = namespace
|
|
? getNestedValue(enMessages, namespace) || {}
|
|
: enMessages
|
|
const t = (key, params) => {
|
|
const value = getNestedValue(messages, key)
|
|
if (typeof value !== 'string') return key
|
|
if (params) {
|
|
return value.replace(/\{(\w+)(?:,\s*plural,\s*one\s*\{([^}]*)\}\s*other\s*\{([^}]*)\})?\}/g,
|
|
(match, name, one, other) => {
|
|
if (one !== undefined && other !== undefined) {
|
|
return params[name] === 1 ? one : other
|
|
}
|
|
return params[name] !== undefined ? String(params[name]) : match
|
|
})
|
|
}
|
|
return value
|
|
}
|
|
t.rich = (key, params) => t(key, params)
|
|
t.raw = (key) => getNestedValue(messages, key) || key
|
|
return t
|
|
},
|
|
useLocale: () => 'en',
|
|
useMessages: () => enMessages,
|
|
NextIntlClientProvider: ({ children }) => children,
|
|
}))
|
|
|
|
// Mock window.matchMedia
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
writable: true,
|
|
value: jest.fn().mockImplementation(query => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
addEventListener: jest.fn(),
|
|
removeEventListener: jest.fn(),
|
|
dispatchEvent: jest.fn(),
|
|
})),
|
|
})
|
|
|
|
// Mock IntersectionObserver
|
|
global.IntersectionObserver = class IntersectionObserver {
|
|
constructor() {}
|
|
disconnect() {}
|
|
observe() {}
|
|
takeRecords() {
|
|
return []
|
|
}
|
|
unobserve() {}
|
|
}
|
|
|
|
// Mock ResizeObserver
|
|
global.ResizeObserver = class ResizeObserver {
|
|
constructor() {}
|
|
disconnect() {}
|
|
observe() {}
|
|
unobserve() {}
|
|
}
|
|
|