Files
karaoke-gen/frontend/jest.setup.js
T
Andrew Beveridge ☄️andClaude Opus 4.6 ab330a3ed6 feat(i18n): scale to 33 languages with RTL support (#666)
## Summary
- Scale i18n from 3 languages (en/es/de) to 33 languages
- Upgrade translation pipeline: async parallel execution (5 concurrent)
+ incremental delta detection
- Add RTL support (`dir="rtl"`) for Arabic and Hebrew
- Replace LanguageSwitcher `<select>` with grouped scrollable dropdown
(flags + native names)
- RTL CSS audit: convert directional properties to logical equivalents
- 30 new frontend translation files (1062 keys each) + 30 backend files
(274 keys each)

### New languages
Portuguese, French, Japanese, Korean, Chinese, Italian, Dutch, Polish,
Turkish, Russian, Thai, Indonesian, Vietnamese, Filipino, Hindi, Arabic,
Swedish, Norwegian, Danish, Finnish, Czech, Romanian, Hungarian, Greek,
Hebrew, Malay, Ukrainian, Croatian, Slovak, Catalan

## Test plan
- [x] `next build` — 285 static pages generated (11 pages x 33 locales -
some deduped)
- [x] All translation files have 100% key parity
- [ ] Post-deploy: verify Japanese, Arabic (RTL), Portuguese render
correctly
- [ ] Post-deploy: verify LanguageSwitcher shows all 33 options

<!-- @coderabbitai ignore -->

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 05:08:47 -04:00

101 lines
2.8 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 @/i18n/routing — locale-aware navigation primitives
jest.mock('@/i18n/routing', () => {
const React = require('react')
return {
routing: {
locales: [
'en', 'es', 'de', 'pt', 'fr', 'ja', 'ko', 'zh', 'it', 'nl',
'pl', 'tr', 'ru', 'th', 'id', 'vi', 'tl', 'hi', 'ar', 'sv',
'nb', 'da', 'fi', 'cs', 'ro', 'hu', 'el', 'he', 'ms', 'uk',
'hr', 'sk', 'ca',
],
defaultLocale: 'en',
},
Link: ({ children, href, ...props }) =>
React.createElement('a', { href, ...props }, children),
redirect: jest.fn(),
usePathname: () => '/',
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
forward: jest.fn(),
refresh: jest.fn(),
}),
}
})
// 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() {}
}