A lightweight Node.js translation module that stores language files in JSON format, supporting dynamic on-the-fly string addition. Current stable version is 0.15.3 (last updated July 2024), with a moderate release cadence. Key differentiators include simplicity (no extra parsing), integration with Express via middleware, and support for both singleton and instance patterns. It provides common __('...') syntax for translation lookups, automatic locale detection from Accept-Language headers, and CLI/script usage. Unlike more complex solutions like i18next, this library is minimal with no external dependencies, but it lacks features like pluralization, interpolation, and loading from remote backends.
npm install i18nNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates an HTTP server with i18n instance, initializes per request, and returns translated greeting based on Accept-Language header.
Use const { I18n } = require('i18n') for instances; for singleton, const i18n = require('i18n') still works as default export.Upgrade to >=0.12.0 and use instance or continue with singleton; no breaking change if using require('i18n') as before.Use new I18n() instance per request or call i18n.init(req, res) to scope locale to request.
Manually set locale using i18n.setLocale(req, 'de') before rendering.
Ensure i18n.init() is called for request-bound translations; use res.__() or req.__() helpers.
Run 'npm install i18n' and ensure require/import path is correct.
Use const { I18n } = require('i18n') for constructor; or use singleton pattern without new.Add i18n.init(req, res) before using res.__() in middleware.
Call i18n.configure({...}) or i18n.setLocale(...) before using __().Create the missing JSON file (e.g., locales/en.json) with an empty object {} or your translations.No dependency data recorded yet.