var i18n = require('i18n');
var moment = require('moment');

var localization = function init(we) {
  i18n.configure (we.config.i18n);
  // set i18n middleware
  we.express.use(i18n.init);

  we.i18n = i18n;

  // set default moment locale
  moment.locale(we.config.i18n.defaultLocale);

  we.express.use(function setCurrentUserLocale(req, res, next) {
    if (req.user && req.user.language) {
      if (we.config.i18n.locales.indexOf(req.user.language) > -1) {
        req.setLocale(req.user.language);
      }
    }
    next();
  })

};

module.exports = localization;
@@ -365,16 +365,22 @@
 .user &&
+%0A     
  req.use
@@ -393,22 +393,18 @@
 uage
-) %7B
+ &&
 %0A      
-if (
 we.c
@@ -453,22 +453,46 @@
 ge) %3E -1
+%0A    
 ) %7B%0A  
+    // user locale%0A
       re
@@ -531,17 +531,160 @@
     
-  %7D%0A    %7D
+%7D else %7B%0A      // default%0A      req.setLocale(we.config.i18n.defaultLocale);%0A    %7D%0A    // set locale for views%0A    res.locals.locale = req.getLocale();%0A
 %0A   

update localization to set res.locals.locale