Skip to content

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.json
json
{
  "welcome": "Welcome, {{name}}!",
  "emails": {
    "welcome": {
      "subject": "Welcome to our platform"
    }
  }
}

Language Detection

Languages are detected in this order:

  1. Query string?lang=fr
  2. LocalStoragelang key
  3. Cookielang cookie
  4. 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 csv

The Google Spreadsheet ID is configured via config.i18n.spreadsheet_id.

Released under the ISC license.