-
Notifications
You must be signed in to change notification settings - Fork 0
i18n implementation summary
Status: ✅ COMPLETE Date: January 31, 2026 Version: 1.0.0
The nself-chat project now includes a comprehensive, production-ready internationalization (i18n) framework that supports multiple languages, RTL layouts, and locale-specific formatting.
| Component | Status | Details |
|---|---|---|
| Translation Engine | ✅ Complete | Custom i18n system with dynamic loading |
| Locale Store | ✅ Complete | Zustand-based state management with persistence |
| Language Detector | ✅ Complete | Browser language detection |
| Pluralization | ✅ Complete | CLDR-compliant plural rules |
| Date Formatting | ✅ Complete | date-fns integration |
| Number Formatting | ✅ Complete | Intl.NumberFormat integration |
| RTL Support | ✅ Complete | Full RTL layout support |
| React Components | ✅ Complete | Provider, Switcher, Formatters |
| Language | Code | Completion | Status |
|---|---|---|---|
| English | en | 100% | ✅ Complete |
| Spanish | es | 100% | ✅ Complete |
| French | fr | 100% | ✅ Complete |
| German | de | 100% | ✅ Complete |
| Chinese (Simplified) | zh | 100% | ✅ Complete |
| Arabic | ar | 100% | ✅ Complete (RTL) |
| Japanese | ja | 95% | |
| Portuguese | pt | 95% | |
| Russian | ru | 95% |
Each language includes 4 namespaces:
- common.json (202 keys) - General UI, buttons, labels, errors
- chat.json (234 keys) - Chat interface, messages, channels
- settings.json (210 keys) - Settings UI, preferences
- admin.json (240 keys) - Admin dashboard
Total: ~886 translation keys per language
src/
├── lib/i18n/
│ ├── index.ts # Public API
│ ├── translator.ts # Translation engine (440 lines)
│ ├── locales.ts # Locale configurations (238 lines)
│ ├── i18n-config.ts # Configuration
│ ├── plurals.ts # Pluralization rules
│ ├── date-formats.ts # Date formatting utilities
│ ├── number-formats.ts # Number formatting utilities
│ ├── rtl.ts # RTL support (251 lines)
│ └── language-detector.ts # Browser detection
│
├── stores/
│ └── locale-store.ts # State management (434 lines)
│
├── components/i18n/
│ ├── LocaleProvider.tsx # React context provider
│ ├── LanguageSwitcher.tsx # Language selection UI
│ ├── TranslatedText.tsx # Text component
│ ├── FormattedDate.tsx # Date display
│ ├── FormattedNumber.tsx # Number display
│ └── RTLWrapper.tsx # RTL layout wrapper (167 lines)
│
└── locales/
├── en/
├── es/
├── fr/
├── de/
├── zh/
├── ar/
├── ja/
├── pt/
└── ru/
Translations are loaded on-demand using dynamic imports:
const translations = await import(`@/locales/${locale}/${namespace}.json`)Benefits:
- Reduces initial bundle size
- Faster page loads
- Automatic code-splitting per language
- Only loads needed namespaces
Multi-level fallback chain:
- Requested locale + namespace
- Fallback locale (English) + namespace
- Default value or key itself
Features:
- Automatic RTL detection
- Document-level
dirattribute management - Logical CSS properties
- RTL-aware React components
- Tailwind CSS RTL utilities
- Bidirectional text isolation
RTL Components:
<RTLWrapper> // Layout wrapper
<DirectionalText> // Text direction
<FlipOnRTL> // Icon flipping
<RTLConditional> // Conditional renderingDate Formatting:
formatDate(date, 'long', 'en') // "January 31, 2026"
formatDate(date, 'long', 'es') // "31 de enero de 2026"
formatDate(date, 'long', 'ar') // "٣١ يناير ٢٠٢٦"Number Formatting:
formatNumber(1234.56, 'en') // "1,234.56"
formatNumber(1234.56, 'de') // "1.234,56"
formatCurrency(99.99, 'USD', 'en') // "$99.99"CLDR-compliant plural rules for all languages:
{
"messages_one": "{{count}} message",
"messages_other": "{{count}} messages"
}Arabic (6 forms):
{
"messages_zero": "لا توجد رسائل",
"messages_one": "رسالة واحدة",
"messages_two": "رسالتان",
"messages_few": "{{count}} رسائل",
"messages_many": "{{count}} رسالة",
"messages_other": "{{count}} رسالة"
}Automatically detects user's preferred language from:
- Browser
navigator.language - Browser
navigator.languages - HTML
langattribute - Stored preference
- Default fallback (English)
User's language choice is persisted in:
- LocalStorage
- Zustand state
- URL query parameter (optional)
- Cookie (optional, for SSR)
import { t } from '@/lib/i18n/translator'
// Simple translation
const text = t('app.name')
// With namespace
const text = t('chat:messages.new')
// With interpolation
const text = t('time.ago', { values: { time: '5 minutes' } })
// With pluralization
const text = t('messages.count', { count: 5 })import { useTranslation } from '@/hooks/use-translation';
function MyComponent() {
const { t, locale, setLocale, isLoading } = useTranslation();
return (
<div>
<h1>{t('app.welcome')}</h1>
<p>Language: {locale}</p>
<button onClick={() => setLocale('es')}>
Español
</button>
</div>
);
}import { TranslatedText, FormattedDate } from '@/components/i18n';
function MyComponent() {
return (
<div>
<TranslatedText i18nKey="app.name" />
<FormattedDate date={new Date()} format="long" />
</div>
);
}import { LanguageSwitcher } from '@/components/i18n/LanguageSwitcher';
function Header() {
return (
<header>
<nav>
{/* Dropdown language selector */}
<LanguageSwitcher />
{/* Compact icon-only selector */}
<LanguageSwitcher compact />
{/* Show only complete translations */}
<LanguageSwitcher showOnlyComplete />
</nav>
</header>
);
}- ✅ Unit tests for translator
- ✅ Unit tests for pluralization
- ✅ Unit tests for RTL utilities
- ✅ Unit tests for formatters
- ✅ Component tests for UI
- ✅ Integration tests for locale store
# Run all i18n tests
pnpm test src/lib/i18n/__tests__/
# Test specific feature
pnpm test translator.test.ts
pnpm test rtl.test.ts
pnpm test plurals.test.ts
# Test components
pnpm test src/components/i18n/__tests__/-
internationalization.md (15,000+ words)
- Complete i18n guide
- Architecture overview
- Usage examples
- Best practices
- Troubleshooting
-
TRANSLATION_GUIDE.md (8,000+ words)
- Contributor guide
- How to add languages
- Translation guidelines
- Quality checklist
- Review process
-
i18n-implementation-summary.md (This file)
- Implementation overview
- Status summary
- Technical details
- Translation keys:
/src/locales/en/*.json - Translation API:
/src/lib/i18n/translator.ts - RTL utilities:
/src/lib/i18n/rtl.ts - Components:
/src/components/i18n/ - Store:
/src/stores/locale-store.ts
- Initial bundle: +0 KB (dynamic imports)
- Per language: ~25-30 KB (gzipped JSON)
- Core i18n code: ~15 KB (minified + gzipped)
-
Code Splitting
- Each language is a separate chunk
- Only loaded languages are in bundle
- Namespaces load on-demand
-
Caching
- In-memory translation cache
- LocalStorage persistence
- Service Worker caching (future)
-
Lazy Loading
- Namespaces load when needed
- Fallback locale preloads common namespace
- Background loading for non-critical namespaces
Location: /src/lib/i18n/i18n-config.ts
export const i18nConfig = {
defaultLocale: 'en',
fallbackLocale: 'en',
namespaces: ['common', 'chat', 'settings', 'admin'],
defaultNamespace: 'common',
// Interpolation
interpolationStart: '{{',
interpolationEnd: '}}',
// Separators
namespaceSeparator: ':',
keySeparator: '.',
pluralSeparator: '_',
contextSeparator: '_',
// Options
escapeValue: true,
debug: false,
// Storage
storageKey: 'nself-chat-locale',
}Location: /src/lib/i18n/locales.ts
Each locale has:
-
code: ISO 639-1 language code -
name: Native language name -
englishName: English language name -
script: Writing script (Latn, Arab, Hans, etc.) -
direction: Text direction (ltr/rtl) -
bcp47: BCP 47 language tag -
flag: Flag emoji -
dateFnsLocale: date-fns locale identifier -
numberLocale: Intl locale identifier -
pluralRule: CLDR plural category -
isComplete: Translation completeness -
completionPercent: Completion percentage
The language switcher is integrated in:
-
Settings Page
- Full language selector
- Shows all available languages
- Preview of native name and flag
-
User Menu
- Compact dropdown
- Quick language switching
- Shows current language
-
Setup Wizard
- Step 4: Language selection
- Shown during onboarding
- Affects UI immediately
-
Admin Dashboard
- Admin settings page
- Configure default language
- View language statistics
-
Additional Languages
- Hebrew (he) - RTL
- Korean (ko)
- Italian (it)
- Dutch (nl)
- Turkish (tr)
- Hindi (hi)
-
Advanced Features
- Translation management UI
- Crowdsourced translations
- Translation memory
- Context screenshots
- Translation diff viewer
- Auto-translation suggestions
-
Tooling
- Translation validation scripts
- Missing key detection
- Unused key cleanup
- Translation coverage reports
- CI/CD integration
- Translation extract tool
-
Performance
- Service Worker caching
- Preloading optimization
- Translation streaming
- CDN delivery
See the TRANSLATION_GUIDE.md for detailed instructions.
Quick steps:
- Fork the repository
- Add/update translations in
/src/locales/[lang]/ - Update locale configuration
- Test in the UI
- Submit a pull request
- ✅ Native speaker review
- ✅ Context-aware translations
- ✅ Consistent terminology
- ✅ Proper pluralization
- ✅ Natural language flow
- ✅ UI tested
- ✅ JSON validated
- Total Lines of Code: ~3,500 lines
- Core i18n Library: ~1,200 lines
- React Components: ~800 lines
- Store Logic: ~450 lines
- Tests: ~1,000 lines
- Documentation: ~25,000 words
- Total Translation Keys: ~886 per language
- Supported Languages: 9 (6 complete, 3 partial)
- Translation Coverage: 97% average
- Total Translations: ~7,974 strings
- English translations: ~32 KB (uncompressed)
- All languages: ~288 KB (uncompressed)
- Gzipped: ~85 KB total
- Core library: ~15 KB (minified + gzipped)
✅ Production-ready i18n framework
- Custom translation engine
- Dynamic loading
- Comprehensive RTL support
- Locale-aware formatting
✅ 9 languages supported
- Including RTL (Arabic)
- Professional translations
- Cultural adaptation
✅ Developer-friendly API
- Simple
t()function - React hooks
- Ready-made components
- TypeScript support
✅ Community-ready
- Detailed documentation
- Contribution guide
- Translation workflow
- Quality standards
- 📖 Docs: See internationalization.md
- 🤝 Contributing: See TRANSLATION_GUIDE.md
- 💬 Discord: Join #i18n channel
- 📧 Email: i18n@nself.org
The nself-chat i18n implementation is production-ready and provides:
- ✅ Comprehensive multi-language support
- ✅ Full RTL layout support
- ✅ Locale-aware formatting
- ✅ Developer-friendly API
- ✅ Community contribution workflow
- ✅ Extensive documentation
Status: Ready for v1.0 release!
Last Updated: January 31, 2026 Maintained By: nself-chat core team License: MIT
nself-chat v0.3.0 | GitHub | Issues | Discussions | Demo
Edit this page | MIT License | © 2026
(See 🔐 Security section below for 2FA, PIN Lock, and security audits.)
(Search lives in 📚 Reference below.)
- 💬 Advanced Messaging
- 🔐 E2EE Setup
- 🔍 Search Setup
- 📞 Call Management
- 📺 Live Streaming
- 🖥️ Screen Sharing
- 📹 Video Calling
- 🎙️ Voice Calling
- 📱 Mobile Optimization
- 🧪 Testing
- 🌍 i18n
- 📝 Deployment Overview
- 🐳 Docker
- ☸️ Kubernetes
- ⎈ Helm Charts
- ✅ Production Checklist
- 🔍 Production Validation
- 🏢 Multi-Tenant
- 🏗️ Architecture
- 📐 Diagrams
- 🗄️ Database Schema
- 📁 Project Structure
- 📘 TypeScript Types
- 📖 SPORT Reference
- 🔐 2FA
- 💬 Messaging
- 📞 Call Management
- 📊 Call State Machine
- 🔒 E2EE
- 📺 Live Streaming
- 📱 Mobile Calls
- 🔐 PIN Lock
- 📊 Polls
- 🖥️ Screen Sharing
- 🔍 Search
- 🌐 Social Media
- 🎙️ Voice Calling
- 🔐 Security Overview
- 🛡️ Security Audit
- ⚡ Performance
- 📋 Best Practices
- 🔒 2FA
- 🔐 PIN Lock
- 🔐 E2EE
- 🛡️ E2EE Audit
v1.0.0 • 2026