next-international for internationalization (i18n), providing seamless multi-language support across the application.
Overview
The internationalization system supports:- Client-side translations: For dynamic React components
- Server-side translations: For Next.js server components
- Multiple locales: Currently English (en) and French (fr)
- Type-safe translations: Full TypeScript support
- Lazy loading: Translations loaded on-demand for performance
Current Supported Languages
English
Default language (en)
French
Secondary language (fr)
Setup
Client-Side Configuration
The client i18n setup is defined in/locales/client.ts:
Server-Side Configuration
The server i18n setup is in/locales/server.ts:
Translation Files Structure
Translations are organized by feature:Main Translation File
The main file (en.ts) imports and exports all translations:
Using Translations
In Client Components
Use theuseI18n hook for client-side translations:
With Variables
Pass variables to translations:Scoped Translations
Use scoped translations for feature-specific keys:In Server Components
Use the server-side API in server components:Changing Locale
Allow users to change language:Adding Translations
Step 1: Add English Translation
Add your key to the appropriate file in/locales/en/:
Step 2: Add French Translation
Add the corresponding French translation:Step 3: Use the Translation
Use your new translation key in components:Translation Patterns
Nested Keys
Organize translations hierarchically:Pluralization
Handle singular and plural forms:Complex Objects
Use objects for related translations:Real-World Examples
Statistics Widget
Rithmic Sync
Import Process
Currency Formatting
Handle locale-specific number and currency formatting:Best Practices
- Consistent Keys: Use dot notation for nested keys (e.g.,
dashboard.title) - Descriptive Names: Make key names self-explanatory
- Feature Organization: Group translations by feature in separate files
- Complete Translations: Ensure all locales have matching keys
- Type Safety: Leverage TypeScript for translation key validation
- Context: Provide context in key names (e.g.,
button.savevsbutton.cancel) - Reusability: Use common translations (like
common.save) for repeated text
Common Translation Keys
Adding a New Language
Create Translation Files
Create new directories:
/locales/es.ts(main file)/locales/es/(feature files)
Troubleshooting
Missing Translation Keys
If a key is missing, the system falls back to the key name:Type Errors
Ensure all translation files export objects with matching structure:Hydration Mismatches
Ensure server and client translations match:Related Resources
next-international
Official next-international documentation
Request New Language
Contact us to request a new language