Skip to main content

Quickstart

import { getI18n } from '@quik/core';
import { QI18n } from '@quik/i18n';

const i18n = new QI18n({ defaultLanguage: 'en', fallbackLanguage: 'en', supportedLanguages: [ 'en', 'fr' ] });
i18n.loadFolder('./locales');
await i18n.setup();

const message = getI18n().translate('app.welcome', { name: 'Quik' });

Notes

  • There is no setLanguage() method. defaultLanguage/fallbackLanguage are settable properties on QI18n, and translate(key, parameters, language) accepts an explicit language per call.
  • loadFolder(folder, recursive?) reads one JSON file per supported language (en.json, fr.json, ...) and ignores files for languages that were not passed to the constructor.
  • setup() initializes the underlying i18next instance and registers the loaded resources; call it once during module boot, after all loadFolder() calls.
  • setupHttpEngine(engine, type) wires the i18next-http-middleware language detector into an express, koa, or fastify server instance.