Advanced Usage
SSR Scenarios
In SSR scenarios, the plugin detects the language on the server, loads translation resources, and injects the result into the page. The client reuses it directly to avoid language flicker.
Complete configuration:
Server-side language detection priority: URL path -> Cookie -> Accept-Language request header -> fallbackLanguage.
Route configuration (file-system routes):
In SSR scenarios, the language detected on the server is written to window._SSR_DATA. The client reads it directly and does not detect again, ensuring both sides use the same language.
Multiple Entries
Different entries can use different language lists, detection methods, and resource paths:
Custom i18next Instance
By default, the plugin uses an internally created i18next instance. If you need deeper customization, such as custom plugins or preconfigured options, pass a custom instance through runtime configuration:
Language Switching Behavior
When changeLanguage is called to switch language:
- Translation update: All components that use
t()re-render automatically. No manual refresh is needed. - URL update (when
localePathRedirectis enabled): Updates the URL withhistory.pushState, without triggering a page refresh and without affecting browser back/forward history. - Cache update: Writes to Cookie or LocalStorage based on the
cachesconfiguration, so the language choice is restored on the next visit. - When path prefixes are not enabled: Only the i18next instance and cache are updated. The URL stays unchanged.