Ejemplo n.º 1
0
Archivo: app.js Proyecto: llabball/ifs
function localeMiddleware(req, res, next) {
  res.locals.currentUri = req._parsedUrl.pathname;
  res.locals.defaultLang = i18n.getLocale();
  res.locals.availableLangs = config.locales;
  var preferredLang = req.query['lang'];
  if(preferredLang !== undefined){
    req.session.preferredLang = preferredLang === 'default' && null || preferredLang;
  }
  if(req.session && req.session.preferredLang){
    i18n.setLocale(req.session.preferredLang);
  }
  res.locals.preferredLang = i18n.getLocale();
  next();
}
Ejemplo n.º 2
0
 hbs.registerHelper('__n', function() {
     var args = Array.prototype.slice.call(arguments, 0, -1),
         result = i18n.__n.apply(this, args);
     debug('i18n - ' + i18n.getLocale() + ':\r\n' +
         args, i18n.__n.apply(this, args));
     return result;
 });
Ejemplo n.º 3
0
module.exports = function(req, res, next) {

  i18n.init(req, res);

  var current_locale = i18n.getLocale();

  return next();
};
Ejemplo n.º 4
0
module.exports = (req, res, next) => {

    i18n.init(req, res);
    //res.local('__', res.__);

    const current_locale = i18n.getLocale();

    return next();
};
Ejemplo n.º 5
0
process.on('uncaughtException', function (err) {
    try {
        if (err.message.indexOf('[sprintf]') !== -1) {
            var currentLocale = App.Localization.langcodes[i18n.getLocale()].nativeName;
            AdvSettings.set('language', 'en');
            i18n.setLocale('en');
            App.vent.trigger('movies:list');
            $('.notification_alert').show().html('An error occured with the localization in ' + currentLocale).delay(4000).fadeOut(400);
        }
    } catch (e) {}
    win.error(err, err.stack);
});
Ejemplo n.º 6
0
 AppUser.afterRemoteError('create', function(ctx, next) {
   const req = loopback.getCurrentContext().get('http').req
   const t = req ? req.__ : __
   const locale = getLocale(req)
   const e = ctx.error
   if (e) switch (e.statusCode) {
     case 422:
       log.warn(e)
       if (e.details && e.details.codes && e.details.codes.length > 0) {
         e.message = t(errors.REGISTRATION_FAILED_USER_EXISTS.message, Object.keys(e.details.codes).join(', '))
       }
       break
     default:
       log.error(e)
   }
   next()
 })
Ejemplo n.º 7
0
function refreshData(plot) {
	var track = trackList[currentTrack];
	var interval = (track.duration*60) / (track.cardiac.length-1);
	var txt_duration = track.duration*60 >= 60 ? Math.floor(track.duration) + " min " + ((track.duration*60%60) <10 ? "" : (track.duration*60%60)) : track.duration*60 + " s";
	
	console.log("Interval : " + interval);
	
	console.log("Currently drawing new stuff.");
	console.log("Currently displayed data is from :" + track.getString());
		
	// Set page title
	$("#page-title").html(track.date.toLocaleString(i18n.getLocale(), { weekday: "long", year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric" }));

	// Update table
	$("#weight").html(track.weight + " kg");
	$("#level").html(track.level);
	$("#calories").html(track.calories + " cal");
	$("#duration").html(txt_duration);
	
	if (plot) {
		refreshPlot(track, interval);
	}
}
Ejemplo n.º 8
0
    app.use(function(req, res, next) {      
      // Current hostname
      res.locals.host = req.host; 
      // The current request
      res.locals.req  = req;
      // Current user
      res.locals.user = req.isAuthenticated() && req.user.is_active ? req.user : false;
      // Current language
      res.locals.lang = i18n.getLocale(req) || config.locale.default; 
      // Add url prefix
      res.locals.url = function(u, oauthCallback) { 
        var instance = res.locals.instance;
        
        if(oauthCallback && instance) {
          return "//" + config.oauth["callback-host"] + "/" + res.locals.lang + u + "/" + instance.id; 
        } else {
          return "/" + res.locals.lang + u; 
        }
      };                           

      // Checks the language at every request
      require("./core/controllers/url").checkLanguage(req, res, function() {
        // Check the current domain to dertermine the current instance
        require("./core/controllers/url").checkInstance(req, res, function(err, instance) {
          if( !err && instance.objects.length > 0) {
            // Records the instance
            res.locals.instance = instance.objects[0]
          } else {
            // Disables instance mode
            res.locals.instance = false;
          }
          // Set up basic authentication strategy
          checkBasicAuth(req, res, next);
        }); 
      })     

    });
Ejemplo n.º 9
0
app.use(express.session({
    store: new mongoStore({ 
        host: config.mongohost,
        db: config.database,
    }),
}));

app.use(passport.initialize());
app.use(passport.session());
app.use(i18n.init);
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

app.enable('trust proxy');

console.log('app.js locale: ' + i18n.getLocale());

app.all('*', function(req, res, next) {
    
    if (req.isAuthenticated()) {
        if (req.user.hasOwnProperty('period')) {
            
            var now = moment();
            var exp = moment(req.user.period.end);
            
            if (now <= exp) {
                req.user.expired = false;
            } else {
                req.user.expired = true;
                if (req.user.status == 'trial') {
                    req.user.expiredmessage = 'Your free trial period is over.';
	, 'locale': function (req, res) {
		return i18n.getLocale();
	}