# @codeyard/moleculer-i18n

> I18n package for Moleculer framework

Latest version **0.0.8** (published 2023-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @codeyard/moleculer-i18n
pnpm add @codeyard/moleculer-i18n
yarn add @codeyard/moleculer-i18n
bun add @codeyard/moleculer-i18n
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2023-04-28 |
| First published | 2023-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 2 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | iujlaki |
| Maintainers | iujlaki |
| Keywords | moleculer, nodejs, microservice, javascript |

## Links

- npm: https://www.npmjs.com/package/@codeyard/moleculer-i18n
- Repository: https://github.com/teamcodeyard/moleculer-i18n
- Homepage: https://github.com/teamcodeyard/moleculer-i18n#readme
- Issues: https://github.com/teamcodeyard/moleculer-i18n/issues
- npm.io page: https://npm.io/package/@codeyard/moleculer-i18n

## Dependencies (2)

- [moleculer](https://npm.io/package/moleculer.md) ^0.14.29
- [node-polyglot](https://npm.io/package/node-polyglot.md) ^2.5.0

## Recent versions

- 0.0.8 (latest) — 2023-04-28
- 0.0.7 — 2023-04-28
- 0.0.6 — 2023-04-26
- 0.0.5 — 2023-04-25
- 0.0.4 — 2023-04-25
- 0.0.3 — 2023-04-25

## README

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

<br>

🌐 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)



<br>

# Install

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

<br>

# 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' })
      },
    },
  },
})
```

<br>

## 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(),
    },
  },
})
```

<br>

### 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). |

<br>

### Example en.json file

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

<br>

# 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)

---
_Source: https://npm.io/package/@codeyard/moleculer-i18n · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
