Skip to content

Instantly share code, notes, and snippets.

@umaar
Forked from saschagehlich/i18n.coffee
Created August 18, 2011 13:48
Show Gist options
  • Save umaar/1154088 to your computer and use it in GitHub Desktop.
Save umaar/1154088 to your computer and use it in GitHub Desktop.
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