From 063a583ad37c78db2d93f7dec0f53dd8163ae5dc Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 24 Mar 2014 17:18:58 +0000 Subject: [PATCH] got basic i18n working in express --- services/web/app.coffee | 1 + services/web/app/coffee/infrastructure/ExpressLocals.coffee | 4 ++++ services/web/app/coffee/infrastructure/Server.coffee | 3 +++ services/web/package.json | 5 +++-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/services/web/app.coffee b/services/web/app.coffee index 74605fc27e..600d65c186 100644 --- a/services/web/app.coffee +++ b/services/web/app.coffee @@ -7,6 +7,7 @@ Server = require("./app/js/infrastructure/Server") BackgroundTasks = require("./app/js/infrastructure/BackgroundTasks") Errors = require "./app/js/errors" + argv = require("optimist") .options("user", {alias : "u", description : "Run the server with permissions of the specified user"}) .options("group", {alias : "g", description : "Run the server with permissions of the specified group"}) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 053a6f0dac..1e8476f363 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -48,6 +48,10 @@ module.exports = (app)-> res.locals.settings = Settings next() + app.use (req, res, next)-> + res.locals.translate = req.i18n.translate + next() + app.use (req, res, next)-> res.locals.getSiteHost = -> Settings.siteUrl.substring(Settings.siteUrl.indexOf("//")+2) diff --git a/services/web/app/coffee/infrastructure/Server.coffee b/services/web/app/coffee/infrastructure/Server.coffee index 2c0866c051..52bd179945 100644 --- a/services/web/app/coffee/infrastructure/Server.coffee +++ b/services/web/app/coffee/infrastructure/Server.coffee @@ -15,6 +15,8 @@ sessionStore = new RedisStore(host:Settings.redis.web.host, port:Settings.redis. cookieParser = express.cookieParser(Settings.security.sessionSecret) oneDayInMilliseconds = 86400000 ReferalConnect = require('../Features/Referal/ReferalConnect') +i18n = require("i18next") +i18n.init(resGetPath: 'locales/__lng__/__ns__.json') Monitor = require "./Monitor" @@ -40,6 +42,7 @@ app.configure ()-> app.set 'views', __dirname + '/../../views' app.set 'view engine', 'jade' app.use express.bodyParser(uploadDir: __dirname + "/../../../data/uploads") + app.use i18n.handle app.use cookieParser app.use express.session proxy: true diff --git a/services/web/package.json b/services/web/package.json index 4d08ecc1f2..872b17952b 100644 --- a/services/web/package.json +++ b/services/web/package.json @@ -32,12 +32,13 @@ "fairy": "0.0.2", "node-uuid": "1.4.0", "mongojs": "0.9.8", - "nodemailer": "0.6.1", + "nodemailer": "0.6.1", "bcrypt": "0.7.5", "archiver": "0.5.1", "nodetime": "0.8.15", "mocha": "1.17.1", - "redback": "0.3.7" + "redback": "0.3.7", + "i18next": "~1.7.1" }, "devDependencies": { "chai": "",