Frontend I18n
Table of Contents
- Locale Sources
- Frontend Locale Files
- Use Messages in Components
- SSR and Hydration
- Switch Language
- Cache and Vary
Locale Sources
Backend config.locale remains the full-stack locale foundation. frontend.i18n controls frontend page copy and hydration behavior.
The server should decide the request locale from sources such as:
- URL prefix
- cookie
- user preference
Accept-Language- explicit route logic
Then res.render() sends the resolved locale and messages into the SSR document.
Frontend Locale Files
Put page copy under src/frontend/locales/**.
All locale files should keep the same object shape. Missing keys should be treated as a content error.
Use Messages in Components
Vext's default frontend API is object access, not t("a.b.c").
You can request a specific locale when the component already knows it:
SSR and Hydration
The default mode is:
"current" means the browser loads only the SSR locale for hydration. This keeps the first JS payload smaller.
Use "all" only when the page needs no-reload language switching:
Switch Language
The simplest switching flow is reload-based:
- User chooses a language.
- Store it in a cookie, user preference API, URL prefix, or another server-visible location.
- Navigate or reload the page.
- SSR and hydration use the same locale.
Avoid making the server render one locale while the browser immediately renders another during hydration.
Cache and Vary
If HTML can vary by language, cache keys must include language.
Common strategies:
- keep
Vary: Accept-Language - include locale in CDN key
- use locale path prefixes such as
/enand/zh - include language preference cookie in the reverse-proxy key
JS/CSS files are content-hashed and do not need language-specific cache keys unless you intentionally build separate locale bundles.