i18n implementation summary - nself-org/nchat GitHub Wiki
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: [email protected]
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