Skip to content

Instantly share code, notes, and snippets.

@nyarla

nyarla/app.js Secret

Last active March 28, 2018 10:51
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nyarla/2365434 to your computer and use it in GitHub Desktop.
Save nyarla/2365434 to your computer and use it in GitHub Desktop.
(OBSOLETED) This code is no longer maintenance: Express.js + i18n-node + ejs
// 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);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>i18n sample</title>
</head>
<body>
<p><%= l('hello world!') %></p>
</body>
</html>
{
'hello world!': 'こんにちま! ザ・ワールド!'
}
@dmshvetsov
Copy link

nice!

@JiveManlyBen
Copy link

This was very helpful. My only change was using app.locals rather than app.helpers for my Express 3 app.

@1ambda
Copy link

1ambda commented Jun 19, 2014

exactly what I am looking for! Thanks!

@AbijeetP
Copy link

Thank you!

@highfeed
Copy link

А сейчас как?

@ThiyagarajanJ
Copy link

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