chore(i18n): 🌐 Add internationalization (i18n) support with database-backed translations, admin UI, and expanded locale files

This commit is contained in:
Lilith 2026-01-18 09:20:45 -08:00
parent d17bfd3083
commit 0e3cecaf3e
15 changed files with 0 additions and 126 deletions

View file

@ -1,126 +0,0 @@
# i18n Feature Migration Plan
## Migration Status: 80% Complete
### Completed
- [x] Directory structure created (react, ml-service, frontend-admin, shared, locales)
- [x] React package moved from `@packages/@infrastructure/i18n`
- [x] ML service copied from external `@ml/i18n-service`
- [x] Frontend-admin package created
- [x] Shared types package created
- [x] Locales moved to feature directory
- [x] pnpm-workspace.yaml updated
- [x] Platform-admin imports updated
### Remaining Tasks
#### Phase 1: React Package - Two-Layer Architecture
1. **Port ml-backend.ts from egirl-platform**
- localStorage cache (24h TTL) → static API → ML fallback
- `{{variable}}` placeholder preservation during translation
- Source tracking: static vs ML-generated
- Fire-and-forget persist to server
2. **Port i18next integration**
- `makeI18n` factory with ML backend option
- `I18nProvider` with locale detection
- `useT` hook with namespace support
- Language detection: URL → localStorage → browser
#### Phase 2: ML Service - Multi-Provider Routing
1. **Implement 6 translation providers**
```python
PROVIDERS = {
'claude': ClaudeProvider(), # WMT24 winner, general quality
'deepl': DeepLProvider(), # European, glossary support
'aya': AyaProvider(), # Self-hosted 8B model
'towerinstruct': TowerProvider(),# European specialist
'nllb': NLLBProvider(), # Meta's 200-language
'madlad400': MADLADProvider(), # 400+ languages
}
```
2. **Language-pair routing configuration**
```python
PROVIDER_ROUTING = {
'es': ['claude', 'deepl', 'nllb'],
'de': ['deepl', 'towerinstruct', 'claude'],
'ja': ['claude', 'nllb', 'madlad'],
'sw': ['nllb', 'madlad'],
}
```
3. **Automatic fallback chain**
- Primary fails → try next in chain
- Track which provider succeeded
- Log failures for monitoring
4. **Batch translation with JSON flattening**
```python
# Input: nested namespace
{"nav": {"home": "Home", "about": "About"}}
# Flatten for LLM
{"nav.home": "Home", "nav.about": "About"}
# Translate all keys in single request
# Unflatten result back to nested
```
#### Phase 3: Caching Layer
1. **Redis cache implementation**
- Key format: `i18n:{locale}:{namespace}:{key}`
- TTL: 7 days
- Track source provider in metadata
2. **Cache invalidation**
- On glossary update → clear affected translations
- On config change → clear domain translations
#### Phase 4: Frontend Admin
1. **Translation management**
- View translations by locale/namespace
- Edit with live preview
- Bulk import/export CSV
2. **Provider dashboard**
- Provider health status
- Usage statistics per provider
- Cost tracking (API calls)
3. **Glossary management**
- Domain-specific terms
- Preferred translations
#### Phase 5: Integration
1. **Truth service validation**
- POST to truth-service before returning
- Auto-correct terminology violations
- Flag economic claim errors
2. **Static file generation**
- Auto-persist ML translations to `/api/translations/{locale}/{namespace}`
- Next user gets static (no LLM cost)
## Integration Dependencies
```
i18n-service
├── depends on: llama-service (LLM inference)
├── depends on: truth-service (content validation)
└── registers with: service-registry
```
## Verification Checklist
- [ ] `pnpm install` succeeds
- [ ] `pnpm -F @lilith/i18n build` succeeds
- [ ] ML service starts: `python -m lilith_i18n_service`
- [ ] `/health` returns healthy with provider status
- [ ] `/api/i18n/translate` returns translation
- [ ] `/api/i18n/translate/batch` handles namespace
- [ ] Fallback chain works (disable primary, verify secondary)
- [ ] React hook caches in localStorage
- [ ] ML translations auto-persist to static
- [ ] Admin UI loads in platform-admin
- [ ] Truth validation catches "85%" error

0
features/i18n/README.md Normal file → Executable file
View file

0
features/i18n/database/init.sql Normal file → Executable file
View file

0
features/i18n/frontend-admin/src/TranslationsPage.tsx Normal file → Executable file
View file

0
features/i18n/frontend-admin/src/index.ts Normal file → Executable file
View file

0
features/i18n/locales/en/age-gate.json Normal file → Executable file
View file

0
features/i18n/locales/en/common.json Normal file → Executable file
View file

0
features/i18n/locales/en/company-investor.json Normal file → Executable file
View file

0
features/i18n/locales/en/company-scop.json Normal file → Executable file
View file

View file

View file

View file

View file

View file

0
features/i18n/locales/en/company-values-privacy.json Normal file → Executable file
View file