-
-
Save nyarla/2365434 to your computer and use it in GitHub Desktop.
(OBSOLETED) This code is no longer maintenance: Express.js + i18n-node + ejs
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
// load libraries | |
var express = require('express') | |
, i18n = require('i18n') | |
; | |
var app = module.exports = express.createServer(); | |
i18n.configure({ | |
locales: ['en', 'ja'] | |
}); | |
app.configure(function () { | |
app.set('views', __dirname + 'templates'); | |
app.set('view engine', 'ejs'); | |
app.set('view options', { layout: false }); | |
app.helpers({ | |
'l': i18n.__ | |
, 'ln': i18n.__n | |
}); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(i18n.init); | |
app.use(app.router); | |
}); | |
app.get('/', function ( req, res ) { | |
res.render('index'); | |
}); | |
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 characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>i18n sample</title> | |
</head> | |
<body> | |
<p><%= l('hello world!') %></p> | |
</body> | |
</html> |
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
{ | |
'hello world!': 'こんにちま! ザ・ワールド!' | |
} |
This was very helpful. My only change was using app.locals rather than app.helpers for my Express 3 app.
exactly what I am looking for! Thanks!
Thank you!
А сейчас как?
Thanks for giving great example,
But , the express which is used here is old version. In new version of express how can i access the variable "l" in ejs from the app.js.
Please help me as soon as possible.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!