๐ Server side i18n support for Moleculer microservices framework based on Polyglot.
$ npm install @codeyard/moleculer-i18n --save
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' })
},
},
},
})
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(),
},
},
})
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). |
{
"greeter": {
"welcome": {
"message": "Hello there!"
}
},
"errors.general.message": "Ooops, somethig went wrong!",
"greeter.farewell": "Good bye %{name}!"
}
The project is available under the MIT license.
Copyright (c) 2016-2019 MoleculerJS