-
-
Save umaar/1154088 to your computer and use it in GitHub Desktop.
Simple i18n with node.js and express.js
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
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" |
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
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