Last active
May 1, 2024 19:55
Revisions
-
mashpie revised this gist
Apr 28, 2013 . 1 changed file with 0 additions and 5 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 charactersOriginal file line number Diff line number Diff line change @@ -22,11 +22,6 @@ app.configure(function () { // init i18n module for this loop app.use(i18n.init); }); // register hbs helpers in res.locals' context which provides this.locale -
mashpie revised this gist
Mar 26, 2013 . 1 changed file with 1 addition and 14 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ // require modules var express = require('express'), i18n = require('i18n'), hbs = require('hbs'), app = module.exports = express(); @@ -38,22 +37,10 @@ hbs.registerHelper('__n', function () { return i18n.__n.apply(this, arguments); }); // serving homepage app.get('/', function (req, res) { res.render('index'); }); // startup app.listen(3000); -
mashpie revised this gist
Mar 26, 2013 . 1 changed file with 0 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,6 @@ app.configure(function () { res.locals.locale = req.locale; next(); }); }); // register hbs helpers in res.locals' context which provides this.locale -
mashpie revised this gist
Mar 26, 2013 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // require modules var express = require('express'), i18n = require('i18n'), url = require('url'), hbs = require('hbs'), app = module.exports = express(); -
mashpie created this gist
Mar 26, 2013 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ // require modules var express = require('express'), i18n = require('../../i18n'), url = require('url'), hbs = require('hbs'), app = module.exports = express(); i18n.configure({ locales: ['en', 'fr'], cookie: 'locale', directory: "" + __dirname + "/locales" }); app.configure(function () { // setup hbs app.set('views', "" + __dirname + "/views"); app.set('view engine', 'hbs'); app.engine('hbs', hbs.__express); // you'll need cookies app.use(express.cookieParser()); // init i18n module for this loop app.use(i18n.init); // register locale to res.locals so hbs helpers know this.locale app.use(function (req, res, next) { res.locals.locale = req.locale; next(); }); app.use(app.router); }); // register hbs helpers in res.locals' context which provides this.locale hbs.registerHelper('__', function () { return i18n.__.apply(this, arguments); }); hbs.registerHelper('__n', function () { return i18n.__n.apply(this, arguments); }); // delay a response to simulate a long running process, // while another request comes in with altered language settings app.get('/', function (req, res) { res.render('index'); }); // set a cookie to requested locale app.get('/:locale', function (req, res) { res.cookie('locale', req.params.locale); res.redirect("/?delay=" + app.getDelay(req, res)); }); // simple param parsing app.getDelay = function (req, res) { return url.parse(req.url, true).query.delay || 0; }; // startup app.listen(3000); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ <span id="text">{{{__ "text to test"}}}</span> <br> <span id="onecat">{{{__n "%d cat" "%d cats" 1}}}</span> <br> <span id="twocats">{{{__n "%d cat" "%d cats" 2}}}</span>