Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple i18n with node.js and express.js
exports.I18n =
en:
title: "Free YouTube video download"
navi:
home: "Home"
howto: "Tutorial"
blog: "Blog"
termsofuse: "Terms of Use"
support: "Support"
imprint: "Imprint"
de:
title: "Kostenloser YouTube Video Download"
navi:
home: "Home"
howto: "Anleitung"
blog: "Blog"
termsofuse: "AGB"
support: "Support"
imprint: "Impressum"
express = require 'express'
app = express.createServer()
i18n = require('./i18n').I18n
# Configure App Server
app.configure ->
app.use express.cookieDecoder()
app.use express.session()
# Custom middleware
app.use (req, res, next) ->
req.lang = i18n[req.session.lang]
next()
# Other stuff
app.use express.methodOverride()
app.use express.bodyDecoder()
app.use app.router
app.use express.logger()
null
app.configure 'development', ->
app.use express.errorHandler {
dumpExceptions: true,
showStack: true
}
null
app.configure 'production', ->
app.use express.errorHandler()
null
# Routes
app.get "/", (req, res) ->
res.render 'index.jade', {
locals: { title: req.lang.title }
}
null
app.listen 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.