Ver Fonte

got basic i18n working in express

Henry Oswald há 12 anos atrás
pai
commit
063a583ad3

+ 1 - 0
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"})

+ 4 - 0
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)

+ 3 - 0
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

+ 3 - 2
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": "",