Skip to content

Commit

Permalink
Merge pull request #25 from gengojs/1.0.0-alpha.2
Browse files Browse the repository at this point in the history
1.0.0-alpha.2
  • Loading branch information
iwatakeshi committed Oct 8, 2015
2 parents a3e1f65 + 1b7d850 commit df5da4d
Show file tree
Hide file tree
Showing 21 changed files with 638 additions and 288 deletions.
42 changes: 42 additions & 0 deletions .backup/express/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
version
}
from '../../package';
import core from 'gengojs-core';
import pack from 'gengojs-default-pack';
export default (function() {
'use strict';
/**
* Global scope
* @private
*/
var global;
/**
* @method gengo
* @description Main function for Gengo.
* @param {Object} options The configuration options.
* @return {Function} The middleware for express.
* @public
*/
var gengo = function(options, plugins) {
global = core(options, plugins || pack());
return global.ship.bind(global);
};
/**
* @method clone
* @description Returns the API.
* @return {Function} The API.
* @public
*/
gengo.clone = function() {
return global.assign.apply(global, arguments);
};
/**
* version.
* @type {String}
* @public
*/
gengo.version = version;
// Export
return gengo;
})();
55 changes: 55 additions & 0 deletions .backup/hapi/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
version, name
}
from '../../package';
import core from 'gengojs-core';
import pack from 'gengojs-default-pack';
export default (function() {
'use strict';
/**
* Global scope
* @private
*/
var global;

function hapi(plugin, options, next) {
plugin.ext('onPreHandler', function(request, reply) {
global.ship.bind(global)(request);
reply.continue();
});
plugin.ext('onPreResponse', function(request, reply) {
global.ship.bind(global)(request);
reply.continue();
});
next();
}

var gengo = function(options, plugins) {
global = core(options, plugins || pack());
var register = hapi;
register.attributes = {
name
};
return {
register: register,
options: options || {}
};
};
/**
* @method clone
* @description Returns the API.
* @return {Function} The API.
* @public
*/
gengo.clone = function() {
return global.assign.apply(global, arguments);
};
/**
* version.
* @type {String}
* @public
*/
gengo.version = version;
// Export
return gengo;
})();
47 changes: 47 additions & 0 deletions .backup/koa/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
version
}
from '../../package';
import core from 'gengojs-core';
import pack from 'gengojs-default-pack';
import 'babel/polyfill';
export default (function() {
'use strict';
/**
* Global scope
* @private
*/
var global;
/**
* @method gengo
* @description Main function for Gengo.
* @param {Object} options The configuration options.
* @return {Function} The middleware for express.
* @public
*/
var gengo = function gengo(options, plugins) {
global = core(options, plugins || pack());
return function*(next) {
global.ship.bind(global)(this);
yield next;
};
};
/**
* @method clone
* @description Returns the API.
* @return {Function} The API.
* @public
*/
gengo.clone = function() {
return global.assign.apply(global, arguments);
};

/**
* version
* @type {String}
* @public
*/
gengo.version = version;
// Export
return gengo;
})();
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules/
*.sublime-workspace
*.sublime-project
test/npm-debug.log
test/npm-debug.log
jsconfig.json
lib/
.backup/
.publish/
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: node_js

node_js:
- 4.1
- 0.12
- 0.11
- 0.10
- iojs

before_install: npm install -g grunt-cli
before_install: npm install -g gulp
108 changes: 100 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
gengo.js
========

[![Join the chat at https://gitter.im/iwatakeshi/gengojs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iwatakeshi/gengojs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/gengojs/gengojs.svg?branch=master)](https://travis-ci.org/gengojs/gengojs)
[![Dependency Status](https://david-dm.org/gengojs/gengojs.svg)](https://github.com/gengojs/gengojs/blob/master/package.json)
[![License Status](http://img.shields.io/npm/l/gengojs.svg)](https://github.com/gengojs/gengojs/blob/master/LICENSE)
[![Downloads](http://img.shields.io/npm/dm/gengojs.svg)]()
[![Version](http://img.shields.io/npm/v/gengojs.svg)]()

[![Build Status](https://travis-ci.org/iwatakeshi/gengojs.svg?branch=master)](https://travis-ci.org/iwatakeshi/gengojs) [![Dependency Status](https://david-dm.org/iwatakeshi/gengojs.png)](https://github.com/iwatakeshi/gengojs/blob/master/package.json) [![License Status](http://img.shields.io/npm/l/gengojs.svg)](https://github.com/iwatakeshi/gengojs/blob/master/LICENSE) [![Downloads](http://img.shields.io/npm/dm/gengojs.svg)]() [![Version](http://img.shields.io/npm/v/gengojs.svg)]()

[![NPM](https://nodei.co/npm/gengojs.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/gengojs/)

## News
It's here! It's finally here! Welcome to version 1.0.0-alpha. As the version implies, this version of gengo is not production ready. It's published so that I can get some feedback and of course test it myself. In fact, I already have a couple of thoughts about bringing the core and the plugins into the same repo because individually maintaining them myself is a difficult task. In the meantime, feel free to try it out and report any bugs or suggestions. As far as docs are concerned, it may take a while for me to write as I try to organize everything up and make gengo.js simple enough to extend and make it the best i18n module for Node.

Hey! Sorry for any delays! gengo.js has been through some transitions and hopefully it lead it to a better library but here's what happened:
* gengo.js has moved into [a dedicated GitHub account](https://github.com/gengojs)
* All official plugins have been updated and can be found at the dedicated account.
* All plugins and the core have been documented.

In the coming weeks I will be working on a revamped version of the website/documentation with the updated gengo.js. In the meantime,
please don't hesitate to create issues and/or contribute to this awesome open source project. And to let everyone know, **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](https://twitter.com/iwatakeshi)). :)

~~It's here! It's finally here! Welcome to version 1.0.0-alpha. As the version implies, this version of gengo is not production ready. It's published so that I can get some feedback and of course test it myself. In fact, I already have a couple of thoughts about bringing the core and the plugins into the same repo because individually maintaining them myself is a difficult task. In the meantime, feel free to try it out and report any bugs or suggestions. As far as docs are concerned, it may take a while for me to write as I try to organize everything up and make gengo.js simple enough to extend and make it the best i18n module for Node.~~

## Introduction

**gengo.js** is an i18n/l10n library that is powered by it's very small [core](github.com/gengojs/core). Along with the core, it is also managed by six [plugins](https://github.com/gengojs?utf8=%E2%9C%93&query=plugin). 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.

## Usage

```javascript
// Modules used in example
var path = require('path');
var root = require('app-root-path');

// Options used in example
var options = {
parser: {
type: '*'
},
backend: {
directory: path.join(root.path, '/config/locales/')
directory: path.join(__dirname, '/config/locales/')
},
header: {
supported: ['en-US', 'ja']
Expand Down Expand Up @@ -52,12 +65,91 @@ server.register(gengo(options), function(error) {

```

## Options

These are the complete option for the official plugins. Loading options is quite simple in gengo.js.

```json
{
"api" : {
"global": "__",
"localize": "__l"
},
"backend": {
"directory": "./locales",
"extension": "json",
"prefix": "",
"cache": true
},
"header": {
"detect": {
"query": false,
"subdomain": false,
"url": false,
"cookie": false,
"header": true
},
"keys": {
"cookie": "locale",
"query": "locale"
},
"supported": ["en-US"],
"default": "en-US"
},
"parser": {
"type": "default",
"markdown": {
"enabled": false,
"html": false,
"xhtmlOut": false,
"breaks": false,
"langPrefix": "language-",
"linkify": false,
"typographer": false,
"quotes": "“”‘’"
},
"template": {
"enabled": true,
"open": "{{",
"close": "}}"
},
"sprintf": { "enabled": true },
"keywords": {
"default": "default",
"translated": "translated",
"global": "global"
}
},
"router": { "enabled": true }
}
```

There are three file extensions supported:
* JSON
* YAML
* JS

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:

```javascript
gengo('path to options');
```
* Directly override the options:

```javascript
gengo({
"parser": {/* ... */}
});
```

## Test

```bash
# make sure to install the node modules
npm install

# run test
grunt
gulp test
```
41 changes: 41 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"beautify":{
"indent_size": 2,
"indent_char": " ",
"eol": "\n",
"indent_level": 0,
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 10,
"jslint_happy": false,
"space_after_anon_function": false,
"brace_style": "collapse",
"keep_array_indentation": false,
"keep_function_indentation": false,
"space_before_conditional": true,
"break_chained_methods": false,
"eval_code": false,
"unescape_strings": false,
"wrap_line_length": 0,
"wrap_attributes": "auto",
"wrap_attributes_indent_size": 4,
"end_with_newline": false
},
"jshint":{
"browser": false,
"jquery": false,
"node": true,
"esnext": true,
"camelcase": true,
"eqeqeq": true,
"indent": 2,
"latedef": true,
"maxlen": 120,
"newcap": true,
"quotmark": "single",
"strict": true,
"undef": true,
"unused": true,
"eqnull": true
}
}
10 changes: 7 additions & 3 deletions examples/hapi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ var options = {
}
};

server.views(options);
server.register(require('vision'), function (error) {
if(error) console.log('An error occurred');
else
server.views(options);
});

server.register(gengo({
parser: {
Expand All @@ -30,9 +34,9 @@ server.register(gengo({
header: {
supported: ['en-US', 'ja']
}
}), function(err) {
}), function(error) {
'use strict';
if (err) console.log('an error occurred');
if (error) console.log('An error occurred');
});


Expand Down

0 comments on commit df5da4d

Please sign in to comment.