i18n
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@messageformat/core | 3.3.0 | 59.83 kB | MIT | prod | 1 |
debug | 4.3.4 | 12.94 kB | MIT | prod | |
fast-printf | 1.6.9 | 6.44 kB | BSD-3-Clause | prod | |
make-plural | 7.4.0 | 359 kB | Unicode-DFS-2016 | prod | 1 |
math-interval-parser | 2.0.1 | 2.88 kB | MIT | prod | |
mustache | 4.2.0 | 33.77 kB | MIT | prod |
i18n is a lightweight translation module with dynamic JSON storage. It is designed to work with plain vanilla Node.js applications and just about any Node.js framework, such as Express or Restify. Its main function is to facilitate smooth and efficient language translations within your JavaScript codebase, which is critical in the creation of multi-language applications. The i18n package uses a common __('...')
syntax in apps and templates, and dynamically adds new strings to your language file.json when first used in your application.
To use i18n, first, install it with npm install i18n --save
. Here's an example of how to wire up this package using the Node.js HTTP module:
const http = require('http')
const path = require('path')
const { I18n } = require('i18n')
const i18n = new I18n({
locales: ['en', 'de'],
directory: path.join(__dirname, 'locales')
})
const app = http.createServer((req, res) => {
i18n.init(req, res)
res.end(res.__('Hello'))
})
app.listen(3000, '127.0.0.1')
In the above example, based on the browser's 'Accept-Language', the server will return "Hello" in either English ('en') or German ('de'). There are also examples showing usage as an instance or singleton, and many other configuration options are available to fit different requirements.
In terms of documentation, all documentation for i18n is available directly in the README file at the GitHub project page for the i18n Node.js package. The URL