A plugin to handle i18n using node-polyglot
$ npm i --save fastify-polyglot
const path = require('path')
fastify.register(require('fastify-polyglot'), {
defaultLocale: 'it',
locales: {
it: require(path.join(__dirname, './locales/it'))
}
})
console.log(fastify.i18n.t('Hello!'))
// 'Ciao!'
Alternatively, you can pass a path lo load locales from:
const path = require('path')
fastify.register(require('fastify-polyglot'), {
defaultLocale: 'it',
localesPath: path.join(__dirname, './locales')
})
Name | Description |
---|---|
defaultLocale |
The default locale code to be used (en by default). |
localesPath |
The folder from where to load locale dictionaries (./locales by default). |
locales |
A map of locales, where keys are locale codes and values are translation dictionaries. |
NOTE: if both localesPath
and locales
are passed, dictionaries will be merged together.
$ npm test
This project is kindly sponsored by:
Licensed under MIT