Permalink
Browse files

make i18n works with express

  • Loading branch information...
1 parent ba06237 commit 1e7ffa7b4c5e58b73298dda39d3a931e0a69a576 @shaunlee committed May 5, 2011
View
@@ -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'));
});
@@ -31,7 +37,7 @@ app.configure('production', function(){
// Routes
app.get('/', function(req, res){
- res.render('index', {
+ res.render('index.html', {
title: 'Express'
});
});
@@ -0,0 +1,5 @@
+{
+ "Hello {name}": "你好 {name}",
+ "There is a car": "有一辆车",
+ "There are {n} cars": "有{n}辆车"
+}
File renamed without changes.
@@ -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>
View
@@ -1,2 +0,0 @@
-<h1>{{ title }}</h1>
-<p>Welcome to {{ title }}</p>
File renamed without changes.
View
@@ -11,6 +11,8 @@ var fs = require('fs'),
exports.version = '0.0.11';
+exports.detector = locales.detector;
+
var _cache = {},
_files = {},
_options = {

0 comments on commit 1e7ffa7

Please sign in to comment.