Under Construction!

Introduction

gengo.js is a server agnostic i18n/l10n library that is powered by it's 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 essentially a unit that provides the basics such as a way of accessing a plugin's options or the plugin itself.

Usage

#npm install
sudo npm install gengojs --save

Initialize

You can simply initialize gengo.js by requiring and configuring it. See Options.

Express

var gengo = require('gengojs');
var app = require('express')();

app.use(gengo({
	'backend': { 'directory': __dirname + '/config/locales' },
	'header' : { 'default': 'en-us', supported: ['ja'] },
	'router': { 'enabled': true }
}));

Koa

var gengo = require('gengojs/koa');
var app = require('koa')();

app.use(gengo({
	'backend': { 'directory': __dirname + '/config/locales' },
	'header' : { 'default': 'en-us', supported: ['ja'] },
	'router': { 'enabled': true }
}));

Hapi

var gengo = require('gengojs/hapi');
var server = new require('hapi').Server();

server.register(gengo({
	'backend': { 'directory': __dirname + '/config/locales' },
	'header' : { 'default': 'en-us', supported: ['ja'] },
	'router': { 'enabled': true }
}), function(error) {
  if (error) console.log('An error occurred: ' + error);
});

API

The following API is respect to the default plugins and may vary. Please refer the the developer's plugin documentation.

i18n

API

// String
__('Hello');
// Object
__({ phrase:'Hello', locale: 'ja', parser:'format' });

// Array
__('Hello %s, is today %s?', ['Bob', 'sunny']);
// Object
__('Hello {{name}}, is today {{weather}}?', { name:'Bob', weather: 'sunny' });

Notations

Phrase Notation

// Assuming the locale === 'ja':

// A basic phrase returns 'こんにちは'
__('Hello');

// A basic phrase with sprintf returns 'Bob こんにちは'
__('Hello %s', 'Bob');

// A basic phrase with interpolation returns 'Bob こんにちは'
 __('Hello {{name}}', {name:'Bob'});

Bracket Notation

// Assuming the locale === 'ja':

// A basic bracket phrase returns 'こんにちは'
__('[Hello]');

// A basic bracket phrase with nested keys returns 'おっす'
__('[Hello].informal');

// A basic bracket phrase with sprintf returns 'Bob おっす'
__('[Hello %].informal', 'Bob');

// A basic bracket phrase with interpolation returns 'Bob おっす'
__('[Hello {{name}}].informal', {name:'Bob'});

Dot Notation

// Assuming the locale === 'ja':

// A basic dot phrase returns 'おっす'
__('greeting.hello.informal');

// A basic dot phrase with sprintf returns 'Bob おっす'
__('greeting.hello.person.informal', 'Bob');

// A basic dot phrase with interpolation returns 'Bob おっす'
__('greeting.hello.person.informal', { name:'Bob' });

Message Format

Because plurality is not supported, the default parser uses message-format to overcome the problem.

To use message-format, simply set the parser using the API or in the options.

// Assuming the locale === 'en-us':

// A basic phrase with message formatting
// returns 'You took 4,000 pictures since Jan 1, 2015 9:33:04 AM'
__('You took {n,number} pictures since {d,date} {d,time}', { n:4000, d:new Date() }, { parser: 'format' });

// A basic bracket phrase with message formatting
// returns 'You took 4,000 pictures since Jan 1, 2015 9:33:04 AM'
__('[You took {n,numbers} pictures].since.date', { n:4000, d:new Date() }, { parser: 'format' });

// A basic dot phrase with message formatting
// returns 'You took 4,000 pictures since Jan 1, 2015 9:33:04 AM'
__('pictures.since.date', { n:4000, d:new Date() }, { format: 'parser' });

l10n

API

The following API is respect to the default localization plugin. Please refer the the developer's plugin documentation.

// Returns the date, time, number, or moment in the current locale
__l().[API Method]()
// Returns the date, time, number, or moment with a specified locale
__l(locale: String).[API Method]()

date()

// Returns an instance of Tokei
__l().date();

time()

// Returns an instance of Tokei
__l().time();

number()

// Returns an instance of Tokei
__l().number();

moment()

// Returns an instance of Moment
__l().moment();

now()


// Returns the current date
__l().date().now();
// Returns the current time
__l().time().now();

format()

// Formats the date
__l().date().format(/* date: Date */);
// Formats the time
__l().time().format(/* date: Date */);
// Formats the number
__l().number().format(/* number: Number */);