Internationalization (i18n) & Localization
Overview
StockEase Frontend supports multiple languages using i18next. The application provides English and German with automatic language detection and user preferences.
Supported Languages
| Language | Code | Status |
|---|---|---|
| English | en |
β Primary |
| Deutsch | de |
β Supported |
Quick Start
Using Translations in Components
import { useTranslation } from 'react-i18next';
const MyComponent = () => {
const { t, i18n } = useTranslation();
return (
<div>
<h1>{t('common.appName')}</h1>
<button onClick={() => i18n.changeLanguage('de')}>
Deutsch
</button>
</div>
);
};Key Translation Patterns
// Simple: t('key')
t('common.appName') // β "StockEase"
// Nested: t('section.key')
t('login.title') // β "Login"
// Interpolation: t('key', { var })
t('welcome', { name: 'John' }) // β "Welcome, John!"Architecture
graph TB
App["App.tsx
i18nextProvider"] Config["src/i18n.ts
Configuration"] Detector["Language Detector
localStorage β Browser"] Resources["Translation Resources
en.json, de.json,
help_en.json, help_de.json"] Components["Components
useTranslation()"] App -->|Setup| Config Config -->|Load| Detector Detector -->|Priority| Resources Resources -->|use in| Components
i18nextProvider"] Config["src/i18n.ts
Configuration"] Detector["Language Detector
localStorage β Browser"] Resources["Translation Resources
en.json, de.json,
help_en.json, help_de.json"] Components["Components
useTranslation()"] App -->|Setup| Config Config -->|Load| Detector Detector -->|Priority| Resources Resources -->|use in| Components
Key Components
Configuration
(src/i18n.ts)
- i18next initialization
- Language detection setup
- Resource loading
Translation Files
- en.json, de.json - App UI translations
- help_en.json, help_de.json - Help modal content
Language Detection
- Checks localStorage first (user preference)
- Falls back to browser language
- Final fallback: English
Component Usage
useTranslation()hookuseTranslation('namespace')for specific namespaces- Automatic language switching
Language Detection Priority
1. localStorage['i18nextLng'] (user's choice)
β
2. navigator.language (browser language)
β
3. Fallback: 'en' (English)
When user changes language, it persists to localStorage.
File Structure
src/
βββ i18n.ts # i18next configuration
βββ locales/
βββ en.json # English translations
βββ de.json # German translations
βββ help_en.json # English help content
βββ help_de.json # German help content
docs/architecture/src/i18n/
βββ overview.md # This file
βββ configuration.md # i18n.ts setup guide
βββ translation-files.md # JSON file structure & sections
βββ language-detection.md # How language is detected
βββ component-patterns.md # Using i18n in components
βββ testing.md # Testing i18n functionality
Quick Links
- βοΈ Configuration Guide - i18n setup
- π Translation Files - JSON structure
- π Language Detection - Automatic language selection
- π» Component Patterns - Using in React
- π§ͺ Testing i18n - Test patterns
Common Tasks
Add New Translation
- Add key to en.json
- Add German translation to de.json
- Use in component:
t('section.key')
See Translation Files for detailed sections.
Switch Language
const { i18n } = useTranslation();
i18n.changeLanguage('de'); // Automatically saves to localStorageGet Current Language
const { i18n } = useTranslation();
const current = i18n.language; // 'en' or 'de'Test Translation
const { t } = useTranslation();
expect(t('common.appName')).toBe('StockEase');Performance & Best Practices
β Do's
- β Use nested keys for organization
- β Keep translation files organized by feature
- β Always provide default values in tests
- β Use TypeScript for type safety
- β Test both languages
β Don'ts
- β Hardcode text in components
- β Mix multiple languages in one key
- β Skip translating new features
- β Use auto-translation tools (use human translators)
Related Documentation
Last Updated: November 2025
Languages: English, German
Framework: i18next
Status: Production Ready