Complete examples for implementing internationalization (i18n) in web applications using JSON key-value pairs
Experience localization in action! Explore all components with real-time language switching:
Features:
- 5 languages: English, Spanish, French, German, Japanese
- Currency formatting: See prices in different locales
- Product states: In stock, low stock, out of stock
- Accessibility: ARIA labels, screen reader support
- Documentation: Auto-generated component docs
This repository contains working code examples from the CrashBytes Localization Tutorial.
- React + i18next Example: Product catalog with language switching, currency formatting, and accessibility
- Next.js 14 + next-intl Example: Blog application with localized routing and server components
- Translation Files: 6 languages (en-US, es-ES, fr-FR, de-DE, ja-JP, ar-SA)
- Storybook Demo: Interactive component testing with 5 languages (en-US, es-ES, fr-FR, de-DE, ja-JP)
- Validation Scripts: Automated translation completeness checking
- Accessibility Examples: ARIA labels, form validation, screen reader announcements
- CI/CD Integration: GitHub Actions workflow for translation validation
- Performance Benchmarks: Loading time comparisons across strategies
cd react-i18next-example
npm install
npm run devExplore and test all localization components interactively:
# From the repository root
npm run storybook
# Or from the react-i18next-example directory
cd react-i18next-example
npm run storybookStorybook provides:
- Interactive component testing - Try all components with different props and languages
- Language switcher - Toggle between all supported locales in real-time
- Accessibility testing - Verify ARIA labels and screen reader behavior
- Documentation - Auto-generated docs for each component
- Edge cases - Test scenarios like low stock, out of stock, different currencies
Complete Storybook Setup Guide →
cd nextjs-next-intl-example
npm install
npm run devlocalization-tutorial/
├── react-i18next-example/ # React + i18next product catalog
│ ├── src/
│ │ ├── components/ # UI components
│ │ ├── i18n/ # i18n configuration
│ │ └── locales/ # Translation JSON files
│ └── package.json
├── nextjs-next-intl-example/ # Next.js 14 + next-intl blog
│ ├── app/
│ │ ├── [locale]/ # Localized routes
│ │ └── i18n.ts # i18n configuration
│ ├── messages/ # Translation JSON files
│ ├── middleware.ts # Locale detection
│ └── package.json
├── accessibility-examples/ # Standalone accessibility components
│ ├── SearchBar.tsx # Localized ARIA labels
│ ├── SignupForm.tsx # Accessible form validation
│ ├── ScreenReaderAnnouncements.tsx
│ └── AccessibleImage.tsx
├── scripts/ # Utility scripts
│ ├── validate-translations.ts # Check translation completeness
│ └── extract-keys.js # Extract translation keys
├── .github/
│ └── workflows/
│ └── validate-translations.yml # CI/CD pipeline
└── README.md
- en-US: English (United States)
- es-ES: Spanish (Spain)
- fr-FR: French (France)
- de-DE: German (Germany)
- ja-JP: Japanese (Japan)
- ar-SA: Arabic (Saudi Arabia)
This tutorial includes a full Storybook setup that lets you test localization components interactively in your browser. Perfect for:
- Testing components without running the full application
- Demonstrating localization to stakeholders
- Verifying translations across all supported languages
- Accessibility testing with screen readers
- Learning by example through documented stories
-
ProductCard - Demonstrates currency formatting, plural forms, and stock status
- In Stock, Low Stock, Single Item, Out of Stock scenarios
- Multiple currencies (USD, EUR)
- Price range examples
-
LanguageSwitcher - Shows language selection across all 5 languages
- English, Spanish, French, German, Japanese variants
- Real-time language switching
-
SearchBar - Illustrates accessible search with localized ARIA labels
- Placeholder text localization
- Screen reader announcements
- Loading states
- Results count pluralization
Storybook includes a global language switcher in the toolbar. Change the locale and watch all components update in real-time:
- English (en-US)
- Español (es-ES)
- Français (fr-FR)
- Deutsch (de-DE)
- 日本語 (ja-JP)
- JSON key-value translation files
- Nested namespace organization
- Variable interpolation (
{{name}}) - Pluralization handling
- Language detection and switching
- TypeScript type safety
- Date formatting with
Intl.DateTimeFormat - Number formatting with
Intl.NumberFormat - Currency formatting (locale-aware)
- Relative time formatting
- Localized ARIA labels and attributes
- Screen reader announcements (
aria-liveregions) - Accessible form validation
- Image alt text localization
- Keyboard navigation in RTL layouts
- WCAG 2.1 Level AA compliance
- CSS logical properties
- Automatic layout flipping
- RTL language detection (Arabic, Hebrew)
- Code splitting by locale
- CDN caching strategies
- Translation validation in CI/CD
- Missing translation detection
- SEO optimization (hreflang tags)
Each example includes:
- Unit tests for translation utilities
- Integration tests for language switching
- Accessibility tests with @testing-library
- E2E tests with Playwright
# Run all tests
npm test
# Run accessibility tests
npm run test:a11y
# Run E2E tests
npm run test:e2eIncluded benchmarks compare:
- Direct import vs dynamic import
- Lazy loading strategies
- CDN caching impact
- Bundle size by locale
Run benchmarks:
npm run benchmarkCheck all translation files for completeness:
npm run validate-translationsValidates:
- Missing keys compared to base language (en-US)
- Extra keys (potentially outdated)
- Proper JSON formatting
- Variable consistency
Automatically extract translation keys from source code:
npm run extract-keysSee react-i18next-example/src/i18n/config.ts for:
- Language detection setup
- Resource loading
- Fallback language configuration
- Interpolation options
See nextjs-next-intl-example/app/i18n.ts for:
- Locale validation
- Message loading
- Middleware configuration
- Routing strategies
Full tutorial: Building Multilingual Web Applications
Topics covered:
- Localization fundamentals (i18n vs l10n)
- JSON key-value architecture
- React implementation with i18next
- Next.js App Router with next-intl
- Date, number, and currency formatting
- RTL language support
- Accessibility integration
- Production best practices
- Performance optimization
- SEO for multilingual sites
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
See CONTRIBUTING.md for detailed guidelines including how to add new Storybook stories.
MIT License - see LICENSE file for details
- i18next Documentation
- next-intl Documentation
- MDN Intl API Reference
- WCAG 2.1 Guidelines
- BCP 47 Language Tags
- Blog: crashbytes.com
- Tutorial: Localization Guide
Built by CrashBytes