Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/teamcodeyard/moleculer-i18n
- Owner: teamcodeyard
- License: mit
- Created: 2023-04-13T13:20:20.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-28T11:01:30.000Z (over 1 year ago)
- Last Synced: 2024-11-07T14:06:28.201Z (2 months ago)
- Topics: codeyard, codeyardfactory, devcontainer, fancy, i18n, microservices, moleculer, moleculerjs, nodejs, typescript, vitest, vscode
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@codeyard/moleculer-i18n
- Size: 319 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-moleculer - moleculer-i18n - Server side i18n support based on [Polyglot](https://www.npmjs.com/package/node-polyglot) (Services / Others)
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)