fastify-polyglot

1.2.0 • Public • Published

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

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.

Test

$ npm test

Acknowledgements

This project is kindly sponsored by:

Beliven

License

Licensed under MIT

Package Sidebar

Install

npm i fastify-polyglot

Weekly Downloads

30

Version

1.2.0

License

MIT

Unpacked Size

34.7 kB

Total Files

13

Last publish

Collaborators

  • beliven.dev