Skip to content

teamcodeyard/moleculer-i18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

38 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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

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

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