16
Internationalization (i18n)
Nxpress includes built-in multi-language routing, automatic locale detection (URL prefix, cookies, Accept-Language), and translation helpers.
Translation Dictionaries (locales/)
Store translation dictionaries as JSON or TS/JS files in the locales/ folder.
locales/fr.json
{
"welcome": "Bienvenue {{name}} !",
"nav": {
"home": "Accueil",
"about": "À propos"
}
}locales/en.json
{
"welcome": "Welcome {{name}}!",
"nav": {
"home": "Home",
"about": "About"
}
}Translation Helper (tr)
The tr(key, [params]) helper translates dictionary keys with variable replacement and automatic fallback to defaultLocale.
Usage in View Templates (EJS / HBS / NJK / Liquid)
<%= tr('welcome', { name: 'Alex' }) %>
Template Injections & Resolution Priority
- Template & Request Injections: lang (current code), R.locale (active locale), R.locales (supported locales), R.defaultLocale (fallback).
- SSR Resolution Priority: 1. URL Path Prefix (/fr/...) -> 2. Query Parameter (?lang=fr) -> 3. Cookie (lang=fr) -> 4. Accept-Language Header -> 5. defaultLocale.
- SSG Multi-language Export: Running nxpress export automatically compiles every page for each configured locale (e.g. out/index.html and out/fr/index.html) with pre-rendered translations.