0.0.8 ā€¢ Published 1 year ago

@codeyard/moleculer-i18n v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Moleculer logo

šŸŒ Server side i18n support for Moleculer microservices framework based on Polyglot. NPM version

Install

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

Usage

Add I18nMixin to your service

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

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

PropertyTypeDefaultDescription
dirNamestringoptionalName of the directory that contains localized JSON files.
languagesarrayoptionalArray of supported languages (default: en).

Example en.json file

{
  "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.

Contact

Copyright (c) 2016-2019 MoleculerJS

@moleculerjs @MoleculerJS

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago