Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/beliven-it/fastify-polyglot
A plugin to handle i18n
https://github.com/beliven-it/fastify-polyglot
fastify i18n js localization node-polyglot nodejs polyglot
Last synced: 2 days ago
JSON representation
A plugin to handle i18n
- Host: GitHub
- URL: https://github.com/beliven-it/fastify-polyglot
- Owner: beliven-it
- License: mit
- Created: 2020-06-11T14:38:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-23T21:21:51.000Z (8 months ago)
- Last Synced: 2024-04-24T23:41:34.292Z (7 months ago)
- Topics: fastify, i18n, js, localization, node-polyglot, nodejs, polyglot
- Language: JavaScript
- Homepage:
- Size: 513 KB
- Stars: 8
- Watchers: 4
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-polyglot
A plugin to handle i18n using [node-polyglot](https://www.npmjs.com/package/node-polyglot)
[![Node.js CI](https://github.com/beliven-it/fastify-polyglot/actions/workflows/node.js.yml/badge.svg)](https://github.com/beliven-it/fastify-polyglot/actions/workflows/node.js.yml)
## Install
```bash
$ npm i --save fastify-polyglot
```## Usage
```js
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:
```js
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
```bash
$ npm test
```## Acknowledgements
This project is kindly sponsored by:
[![Beliven](https://assets.beliven.com/brand/logo_pos_color.svg)](https://www.beliven.com)
## License
Licensed under [MIT](./LICENSE)