gengo.js
![Join the chat at https://gitter.im/gengojs/gengojs](https://badges.gitter.im/Join%20Chat.svg)
![Version](http://img.shields.io/npm/v/gengojs.svg)
Progress:
Help wanted:
I am looking for maintainers! This project isn't very big and shouldn't be difficult to understand on how it works, so if you are interested, feel free to DM me through Gitter or Twitter (@iwatakeshi). :)
Introduction
gengo.js is a server agnostic i18n/l10n library that is powered by its very small core. Along with the core, it is also managed by six plugins. The combinations of the these create a powerful and a unique library that enables developers to take over the core and extend its capabilities. The core is essentialy an empty shell that provides the basics such as a way of accessing a plugin's options or the plugin itself. As a starter, begin hacking the core and the plugins to find out how you can develop your own plugins and create the ultimate combination to create the best i18n library for Node.js.
Sails.js
gengo.js supports Sails through the use of hooks. Check out the repo of sails-hook-gengojs for documentation.
For an example use of the hook, run npm i && sails lift
under examples/sails/app/
.
Usage
var path = require('path');
var options = {
parser: {
type: '*'
},
backend: {
directory: path.join(__dirname, '/config/locales/')
},
header: {
supported: ['en-US', 'ja']
}
};
var gengo = require('gengojs');
var app = require('express')();
app.use(gengo(options));
var gengo = require('gengojs/koa');
var app = new require('koa')();
app.use(gengo(options));
var server = new require('hapi').Server();
var gengo = require('../../hapi/');
server.register(gengo(options), function(error) {
if (error) console.log('an error occurred: ' + error);
});
Options
These are the complete and default options for the official plugins. Assigning options is quite simple in gengo.js.
[api]
global = "__"
localize = "__l"
[backend]
cache = true
directory = "./locales"
extension = "json"
prefix = ""
[header]
default = "en-US"
supported = ["en-US"]
[header.detect]
cookie = false
header = true
query = false
subdomain = false
url = false
[header.keys]
cookie = "locale"
query = "locale"
[parser]
type = "default"
[parser.keywords]
default = "default"
global = "global"
translated = "translated"
[parser.markdown]
breaks = false
enabled = false
html = false
langPrefix = "language-"
linkify = false
quotes = "“”‘’"
typographer = false
xhtmlOut = false
[parser.sprintf]
enabled = true
[parser.template]
enabled = true
open = "{{"
close = "}}"
[router]
enabled = false
There are three file extensions supported:
Each plugin have their own defaults (if applicable) but to override them simply use one of the following ways:
- Use a path to the options:
gengo('path to options');
- Directly override the options:
gengo({
"parser": {}
});
Test
npm install
gulp test