Skip to content

Commit

Permalink
make i18n works with express
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunlee committed May 5, 2011
1 parent ba06237 commit 1e7ffa7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
16 changes: 11 additions & 5 deletions examples/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
* Module dependencies.
*/

var express = require('express');
var express = require('express'),
jst = require('jst');

var app = module.exports = express.createServer();

// Configuration

jst.configure({
locales: {locales: __dirname + '/locales'}
});

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jst');
// Uncomment if you want to use .html instead of .jst'
// app.register('.html', require('jst'))
//app.set('view engine', 'jst');
app.register('.html', jst); // Use this for i18n
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(function(req, res, next) { req.lang = 'zh_CN'; next(); });
app.use(jst.detector);
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
Expand All @@ -31,7 +37,7 @@ app.configure('production', function(){
// Routes

app.get('/', function(req, res){
res.render('index', {
res.render('index.html', {
title: 'Express'
});
});
Expand Down
5 changes: 5 additions & 0 deletions examples/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Hello {name}": "你好 {name}",
"There is a car": "有一辆车",
"There are {n} cars": "有{n}辆车"
}
File renamed without changes.
7 changes: 7 additions & 0 deletions examples/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>{{ title }}</h1>
<p>Welcome to {{ title }}</p>

<h2>i18n</h2>
<p>{{ _('Hello {name}', {name: 'JST'}) }}</p>
<p>{{ _n('There is a car', 'There are {n} cars', 1) }}</p>
<p>{{ _n('There is a car', 'There are {n} cars', 3) }}</p>
2 changes: 0 additions & 2 deletions examples/views/index.jst

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions lib/jst.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var fs = require('fs'),

exports.version = '0.0.11';

exports.detector = locales.detector;

var _cache = {},
_files = {},
_options = {
Expand Down

0 comments on commit 1e7ffa7

Please sign in to comment.