Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/teamcodeyard/moleculer-i18n

🌐 Server side i18n support for Moleculer microservices framework based on Polyglot
https://github.com/teamcodeyard/moleculer-i18n

codeyard codeyardfactory devcontainer fancy i18n microservices moleculer moleculerjs nodejs typescript vitest vscode

Last synced: 2 months ago
JSON representation

🌐 Server side i18n support for Moleculer microservices framework based on Polyglot

Awesome Lists containing this project

README

        

[![Moleculer logo](http://moleculer.services/images/banner.png)](https://github.com/moleculerjs/moleculer)


🌐 Server side i18n support for [Moleculer](https://moleculer.services/) microservices framework based on [Polyglot](https://www.npmjs.com/package/node-polyglot). [![NPM version](https://img.shields.io/npm/v/@codeyard/moleculer-i18n.svg)](https://www.npmjs.com/package/@codeyard/moleculer-i18n)


# Install

```bash
$ npm install @codeyard/moleculer-i18n --save
```


# Usage

## Add I18nMixin to your service

```js
const { I18nMixin } = require('@codeyard/moleculer-i18n')

broker.createService({
name: 'greeter',
mixins: [I18nMixin],
actions: {
welcome: {
handler(ctx) {
return this.t(ctx, 'greeter.welcome.message', { name: 'Jon' })
},
},
},
})
```


## Configurations

```js
const { I18nMixin } = require('moleculer-i18n')
const Polyglot = require('node-polyglot')

broker.createService({
name: 'greeter',
mixins: [I18nMixin],
settings: {
i18n: {
dirName: 'translations',
languages: ['en', 'es'],
polyglot: new Polyglot(),
},
},
})
```


### Setting fields
| Property | Type | Default | Description |
| -------- | ---- | ------- | ----------- |
| `dirName` | `string` | **optional** | Name of the directory that contains localized JSON files. |
| `languages` | `array` | **optional** | Array of supported languages (default: en). |


### Example en.json file

```json
{
"greeter": {
"welcome": {
"message": "Hello there!"
}
},
"errors.general.message": "Ooops, somethig went wrong!",
"greeter.farewell": "Good bye %{name}!"
}
```


# License

The project is available under the [MIT license](./LICENSE).

# Contact

Copyright (c) 2016-2019 MoleculerJS

[![@moleculerjs](https://img.shields.io/badge/github-moleculerjs-green.svg)](https://github.com/moleculerjs) [![@MoleculerJS](https://img.shields.io/badge/twitter-MoleculerJS-blue.svg)](https://twitter.com/MoleculerJS)