code: function localeMiddleware(req, res, next) {
  
      // detect locale
      var locale = undefined, requested = undefined, accept = undefined;
      options.getLocaleFrom.some(function(name) {
        if (name === 'default') return false;
        var strategy = strategies[name];
        locale = strategy.getLocaleFrom(req, options.locales);
        if (!requested) {
          requested = (typeof locale === 'object') ? locale.requestedLocale : locale;
        }
        if (typeof locale === 'object') return true;
        if (options.locales) locale = matchLocale(locale);
        return !!locale;
      });
  
      // no locale detected to store, try with accept-language
      if (!locale) {
        if (strategies['accept-language']) {
          accept = strategies['accept-language'].getLocalesFrom(req);
          // the first one was already tested with getLocaleFrom
          accept.shift();
          accept.some(function(l) {
            locale = l;
            if (!requested) requested = l;
            if (options.locales) locale = matchLocale(l);
            return !!locale;
          });
        }
      }
  
      // no locale detected to store, take default locale when added as strategy
      if (!locale) {
        if (strategies.default) {
          locale = strategies.default.getLocaleFrom(req, options.locales);
          requested = null;
        }
      }
  
      // no locale at all
      if (!locale) return next();
  
      if (typeof locale === 'string') locale = locale.toLowerCase();
      if (typeof requested === 'string') requested = requested.toLowerCase();
  
      // store locale
      var localeObject = typeof locale === 'object' ? locale : createLocaleObject(locale, accept, requested);
  
      // ok finally, locale detected -> store locale
      options.storeLocaleTo.forEach(function(name) {
        var strategy = strategies[name];
        strategy.storeLocaleTo(req, res, localeObject);
      });
      return next();
  
    }
docs: connect/express middleware