1.2.0 • Published 1 month ago

fastify-polyglot v1.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
1 month ago

fastify-polyglot

A plugin to handle i18n using node-polyglot

Node.js CI

Install

$ npm i --save fastify-polyglot

Usage

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')
})

Options

NameDescription
defaultLocaleThe default locale code to be used (en by default).
localesPathThe folder from where to load locale dictionaries (./locales by default).
localesA 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.

Test

$ npm test

Acknowledgements

This project is kindly sponsored by:

Beliven

License

Licensed under MIT