Gengo
class
new Gengo()
The core of gengo.js
class Gengo {
constructor
constructor
Gengo.prototype.constructor()
Option name | Type | Description |
---|---|---|
options | Object | The options for each plugin. |
plugins | Object, Array, Function | The plugin(s) for the core. |
defaults | Object | The default plugins for the core. |
constructor(options, plugins, defaults) {
log.debug(`class: ${Gengo.name}`, `process: constructor`)
// Current version
.info('version:', (this.version = pkg.version))
// Options
.info('options: ', this.options = optify(options));
// Set Plugins
this.plugins = plugify(plugins, this.options, defaults);
// Backend plugin
if (!_.isEmpty(this.plugins.backend) && this.plugins.backend)
this.plugins.backend.apply(this);
}
parse
method
Gengo.prototype.parse()
Option name | Type | Description |
---|---|---|
phrase | Object, String | The phrase to i18n. |
args | Array | The arguments to apply to the phrase. |
Parses and i18ns the phrase.
parse(phrase, ...args) {
log.debug(`class: ${Gengo.name}`, `process: parse`);
// Parser plugin
return this.plugins.parser.apply(this, [inputify(phrase, args)]);
}
ship
method
Gengo.prototype.ship()
Option name | Type | Description |
---|---|---|
req | Object | The request object. |
res | Object | The response object. |
next | Function | The next function. |
The Middleware for Node frameworks
ship(req, res, next) {
log.debug(`class: ${Gengo.name}`, `process: ship`);
// Header plugin
this.plugins.header.apply(this, arguments);
// Router plugin
this.plugins.router.apply(this, arguments);
// Localize plugin
this.plugins.localize.apply(this, arguments);
// Apply API to the objects/request/response
servify(this).apply(req, res, next);
}
assign
method
Gengo.prototype.assign()
Option name | Type | Description |
---|---|---|
arguments | arguments | The arguments to apply the API. |
return | Object | The applied object |
Applies the API to req, res, and other objects.
assign() {
log.debug(`class: ${Gengo.name}`, `process: assign`);
// API plugin
return this.plugins.api.apply(this, arguments);
}
}
Creates a new Gengo instance
export default (options, plugins, defaults) => {
'use strict';
return new Gengo(options, plugins, defaults);
};