Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,85 @@ | ||
node-i18n | ||
========= | ||
|
||
i18n for node with deep level objects | ||
i18n for node with expressJS | ||
|
||
module developers | ||
================= | ||
``` | ||
var i18n = require('node-i18n')({ | ||
default : 'en' | ||
, enabled : ['en', 'fr'] | ||
, 'dir' : './assets/private/i18n' | ||
, 'helper_translate' : '__' | ||
}) | ||
type 'npm test' to launch vows | ||
app.use(i18n.middleware) | ||
//call before app.use(app.router) | ||
``` | ||
|
||
`dir` start on the same level as your express application file | ||
<br/> | ||
|
||
#### Express route | ||
|
||
let's say you have a route `/products` where you want to implement i18n | ||
Before implementing i18n your route would have look like so : | ||
|
||
``` | ||
app.get('/products', function(req, res){ | ||
res.end() | ||
}) | ||
``` | ||
After | ||
|
||
``` | ||
app.get(i18n.route('products'), function(req, res){ | ||
res.end() | ||
}) | ||
``` | ||
Note that the argument that `i18n.route()` takes is a `RegExp`, and we ommitted the `/` before `products` | ||
<br/> | ||
Now `/products`, `/en/products` and `/fr/products` will match the route | ||
<br/> | ||
As `en` is set to be the default, when making a request to `/en/products` you will be redirected to `/products` | ||
|
||
#### exemple of en.json | ||
|
||
``` | ||
{ "en": { | ||
"baseline" : "Welcome to my site" | ||
, "header": { | ||
"menu": { | ||
"h1" : "Hello {{person}} !" | ||
, "h2" : "What's up" | ||
} | ||
} | ||
, "footer": { | ||
"who": "Who are we ?" | ||
} | ||
}} | ||
``` | ||
|
||
#### Jade template | ||
|
||
``` | ||
p __('baseline') | ||
div.header | ||
h1= __('header.menu.h1', 'Batman') | ||
h2= __('header.menu.h2') | ||
div.footer | ||
a(href="#") __('footer.who') | ||
``` | ||
|
||
|
||
## Tests | ||
|
||
|
||
`npm test` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters