How It Works
The i18n implementation uses Next.js dynamic routes with language-specific dictionaries stored as JSON files. The system provides:- Server-side translations with zero client-side JavaScript overhead
- Type-safe dictionary access
- Dynamic locale switching
- SEO-friendly URLs with language prefixes
Configuration
The i18n configuration is defined insrc/i18n-config.ts:
Available Options
defaultLocale: The fallback language when no locale is specifiedlocales: Array of supported language codes
Dictionary Structure
Translations are stored insrc/dictionaries/ as JSON files. The project includes:
src/dictionaries/en.json- English translations (configured)src/dictionaries/es.json- Spanish translations (configured, default)src/dictionaries/ru.json- Russian translations (available, not configured)
The Russian dictionary file exists but is not currently configured in
i18n-config.ts. See Adding a New Language below to enable it.Configured Dictionaries
The following dictionaries are active in the i18n configuration:- Spanish (Default)
- English
Loading Dictionaries
ThegetDictionary function in src/lib/dictionaries.ts loads the appropriate dictionary based on the current locale:
- Uses dynamic imports for code splitting
- Falls back to Spanish if the requested locale doesn’t exist
- Is marked with
"server-only"to prevent accidental client-side usage
Using Translations in Components
Server Components
Load translations in server components usinggetDictionary:
Metadata Generation
Generate localized metadata inlayout.tsx:
Language Switcher
TheLocaleSwitcher component allows users to change languages:
Enabling Russian
The project includes a complete Russian dictionary (src/dictionaries/ru.json) that is not currently enabled. To activate it:
Adding a New Language
To add a language that doesn’t have a dictionary file yet:Step 1: Create Dictionary File
Create a new JSON file insrc/dictionaries/ (e.g., fr.json for French):
Step 2: Update i18n Configuration
Add the new locale tosrc/i18n-config.ts:
Step 3: Update Dictionary Loader
Add the import insrc/lib/dictionaries.ts:
Step 4: Test
Navigate to/fr to see your new language in action.
URL Structure
The i18n system uses locale-prefixed URLs:/es- Spanish (default)/en- English/fr- Example for adding French (not configured by default)
Static Generation
All locale routes are statically generated at build time usinggenerateStaticParams: