Internationalization
Igo.js uses i18next for multi-language support.
Configuration
Default configuration in app/config.js:
js
config.i18n = {
whitelist: ['en', 'fr'],
preload: ['en', 'fr'],
fallbackLng: 'en',
backend: {
loadPath: 'locales/{{lng}}/{{ns}}.json',
},
detection: {
order: ['querystring', 'localStorage', 'cookie'],
lookupQuerystring: 'lang',
lookupLocalStorage: 'lang',
lookupCookie: 'lang',
caches: ['localStorage', 'cookie'],
},
};Translation Files
Translations are stored in locales/{lang}/translation.json:
locales/
├── en/
│ └── translation.json
└── fr/
└── translation.jsonjson
{
"welcome": "Welcome, {{name}}!",
"emails": {
"welcome": {
"subject": "Welcome to our platform"
}
}
}Language Detection
Languages are detected in this order:
- Query string —
?lang=fr - LocalStorage —
langkey - Cookie —
langcookie - Fallback — configured fallback language
Invalid languages are automatically reset to the fallback.
Usage in Templates
The current language is available as res.locals.lang. Use the t helper for translations:
dust
<h1>{t key="welcome" name=user.name /}</h1>Usage in Controllers
js
const { i18next } = require('@igojs/server');
const message = i18next.t('welcome', { name: 'John', lng: 'fr' });CLI: Managing Translations
Igo provides CLI commands for translation management:
bash
# Import translations from a Google Spreadsheet
npx igo i18n update
# Export translations to CSV
npx igo i18n csvThe Google Spreadsheet ID is configured via config.i18n.spreadsheet_id.