Permalink
Browse files

updated readme

  • Loading branch information...
1 parent dc465b3 commit 86bfcafb0a9392f0fce56d31317724fd83880390 @larafale committed Sep 18, 2012
Showing with 42 additions and 17 deletions.
  1. +41 −16 README.md
  2. +1 −1 package.json
View
@@ -3,21 +3,35 @@ node-i18n
i18n for node with expressJS
+- key => value Style
+- Deep file structure
+- View helpers
+
+#### Start
+
+
```
-var i18n = require('node-i18n')({
- default : 'en'
- , enabled : ['en', 'fr']
- , 'dir' : './assets/private/i18n'
- , 'helper_translate' : '__'
-})
+var i18n_options = {}
+var i18n = require('node-i18n')(i18n_options)
-app.use(i18n.middleware)
+app.use(i18n.middleware) //call before app.use(app.router)
+```
-//call before app.use(app.router)
+#### Options (default)
+```
+{
+ default : 'en'
+ , enabled : ['en']
+ , 'dir' : './assets/private/i18n'
+ , 'helper_translate' : '__'
+ , 'helper_path' : '__p'
+ , 'helper_locale' : '__l'
+}
```
-`dir` start on the same level as your express application file
+`dir` is where translation files are stored. Relative to your express application file.
+`helper*` are the avaible function in Jade templates
<br/>
#### Express route
@@ -39,11 +53,17 @@ app.get(i18n.route('products'), function(req, res){
```
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
+Now this route will match `/products` and `/en/products`
<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
+#### Translation files
+Every translation file is JSON and must end with .json
+You can have as many file you want for each locale. This let you seperate content.
+For example : `en.json` `header_en.json` `footer_en.json`
+<br/>
+Each file start with the `locale` key.
+You can now write your definition going how deep as you like in objects.
```
{ "en": {
@@ -52,7 +72,7 @@ As `en` is set to be the default, when making a request to `/en/products` you wi
, "header": {
"menu": {
- "h1" : "Hello {{person}} !"
+ "h1" : "Hello {{name}} !"
, "h2" : "What's up"
}
}
@@ -64,21 +84,26 @@ As `en` is set to be the default, when making a request to `/en/products` you wi
}}
```
+To make a dynamic definition, put the key of the object you are going to pass later on between double brackets `{{name}}`
+
#### Jade template
```
-p __('baseline')
+p= __('baseline')
+p Current locale is #{__l}
div.header
- h1= __('header.menu.h1', 'Batman')
+ h1= __('header.menu.h1', { name: 'Batman' })
h2= __('header.menu.h2')
div.footer
- a(href="#") __('footer.who')
-
+ a(href="#{__p('/contact')}")= __('footer.who')
```
+`__l` return current locale
+`__p('/contact')` return given path prefixed with locale
+<br/><br/>
## Tests
View
@@ -1,6 +1,6 @@
{
"name": "node-i18n",
- "description": "i18n for node",
+ "description": "i18n for node with expressJS",
"main": "./index",
"author": "Larafale & silently",
"version": "0.0.9",

0 comments on commit 86bfcaf

Please sign in to comment.