Detects current locale

@param Request $request
@param Response | null $response

@throws Exception if locale was not detected
503151
public function detect(Request $request, Response $response = null)
	{
		$localeId = null;

		/* @var $detector Detector\DetectorInterface */
		foreach ($this->detectors as $detector) {
			
			$localeId = $detector->detect($request);
			
			if ( ! empty($localeId)) {
				
				if ($this->hasLocale($localeId) && ($this->processInactive || $this->isActive($localeId))) {
					$this->setCurrent($localeId);
					break;
				}
			}
		}

		if (empty($localeId)) {
			throw new Exception\RuntimeException("Could not detect locale for request '{$request->getBaseUrl()}'");
		}

		/* @var $storage Storage\StorageInterface */

		// @FIXME: there is no response object here.
		foreach ($this->storages as $storage) {
			$storage->store($request, $response, $localeId);
		}
	}
1217995
public void setLocale(Locale locale)
  {
    if(locale != null && report != null && report instanceof LocalizableReport) 
    {
      ((LocalizableReport) report).setLocale(locale); 
    }
  }
396922
public function putLanguageAction(Request $request)
    {
        $user = $this->tokenStorage->getToken()->getUser();
        $user->setLocale($request->get('locale'));

        $this->objectManager->flush();

        return $this->viewHandler->handle(View::create(['locale' => $user->getLocale()]));
    }
1238646
protected function configureIO(Request $request, Response $response)
	{
	    if (true === $request->hasParameterOption(['--ansi'])) {
	        $response->setDecorated(true);
	    } elseif (true === $request->hasParameterOption(['--no-ansi'])) {
	        $response->setDecorated(false);
	    }
	    
	    if (true === $request->hasParameterOption(['--no-interaction', '-n'])) {
	        $request->setInteractive(false);
	    }
	    
	    if (true === $request->hasParameterOption(['--quiet', '-q'])) {
	        $response->setVerbosity(Response::VERBOSITY_QUIET);
	    } else {
	        if ($request->hasParameterOption('-vvv') || $request->hasParameterOption('--verbose=3') || $request->getParameterOption('--verbose') === 3) {
	            $response->setVerbosity(Response::VERBOSITY_DEBUG);
	        } elseif ($request->hasParameterOption('-vv') || $request->hasParameterOption('--verbose=2') || $request->getParameterOption('--verbose') === 2) {
	            $response->setVerbosity(Response::VERBOSITY_VERY_VERBOSE);
	        } elseif ($request->hasParameterOption('-v') || $request->hasParameterOption('--verbose=1') || $request->hasParameterOption('--verbose') || $request->getParameterOption('--verbose')) {
	            $response->setVerbosity(Response::VERBOSITY_VERBOSE);
	        }
	    }
	}
64393
private function initLocale()
    {
        $this->locale = $this->detectLocale();

        // datetime format
        if (!setlocale(LC_TIME, $this->locales[$this->locale])) {
            throw new \Exception(sprintf("Unable to set locale to '%s'", $this->locales[$this->locale]));
        }

        // punic default value
        Data::setDefaultLocale($this->getIETF());

        if ('cli' !== PHP_SAPI) {
            if (!self::request()->getCookie(self::COOKIE_LANGUAGE)) {
                self::response()->addCookie(new Cookie(self::COOKIE_LANGUAGE, $this->locale, 60 * 60 * 24 * 365));
            }
        }
    }
1061115
public function changeLanguageAction(Request $request, $oldLocale, $locale)
    {
        $params = [];

        $translationRoute = $this->getTranslationRoute($request->headers->get('referer'), $oldLocale, $locale);

        $request->setLocale($locale);

        if (!is_array($translationRoute)) {
            $routeName = $translationRoute;
        } else {
            $routeName = $translationRoute['_route'];
            unset($translationRoute['_route']);
            foreach ($translationRoute as $key => $var) {
                $params[$key] = $var;
            }
        }

        $params['_locale'] = $locale;

        $parts = parse_url($request->headers->get('referer'));

        if (array_key_exists('query', $parts) && $parts['query']) {
            parse_str($parts['query'], $query);

            $params = array_merge($query, $params);
        }

        $newURL = $this->get('router')->generate($routeName, $params);

        $response = new RedirectResponse($newURL);

        if ($this->getPageHelper()->isAllowLocaleCookie()) {
            $response->headers->setCookie(new Cookie('_locale', $locale));
        }

        return $response;
    }
447962
public function changeAction(Request $request, $locale)
    {
        if (($token = $this->tokenStorage->getToken()) && 'anon.' !== $token->getUser()) {
            $this->localeManager->setUserLocale($locale);
        }

        $request->setLocale($locale);
        $request->getSession()->set('_locale', $locale);

        return new RedirectResponse(
            $request->headers->get('referer')
        );
    }
878321
public function handleResponse(Request $request, Response $response)
    {
        if ($response->getStatusCode() == 422) {
            $errors = $response->getOriginalContent()['validation_errors'];

            throw new HttpResponseException(
                redirect()->back()->withInput($request->input())->withErrors($errors)
            );
        }

        if ($response->getStatusCode() == 403) {
            abort(403);
        }

        return $response->isNotFound() ? abort(404) : $response->getOriginalContent();
    }
365390
public function collect(Request $request, Response $response, \Exception $exception = null)
    {
        $startTime = $request->server->get('REQUEST_TIME_FLOAT', $request->server->get('REQUEST_TIME'));

        $time = \microtime(true) - $startTime;
        $time = \round($time * 1000);

        $statData = $this->getStatsdDataFactory()->timing($this->getStatsDataKey(), $time);
        $this->addStatsData($statData);

        return true;
    }
67719
protected function getDetectedLocale(HTTPRequest $request)
    {
        // Only detect on home page (landing page)
        if ($request->getURL() !== '') {
            return null;
        }
        // Respect config disable
        if (!FluentDirectorExtension::config()->get('detect_locale')) {
            return null;
        }

        /** @var LocaleDetector $detector */
        $detector = Injector::inst()->get(LocaleDetector::class);
        $localeObj = $detector->detectLocale($request);
        if ($localeObj) {
            return $localeObj->getLocale();
        }
        return null;
    }
1224378
private function setLocale($locale, $request)
    {
        $allowedLangs = array_keys(Localizer::allowedLanguages());
        if (config('localizer.block_unallowed_langs') && !in_array($locale, $allowedLangs)) {
            abort(404, 'Unallowed language');
        }

        if (Auth::check()) {
            $user = Auth::User();
            $user->locale = $locale;
            $user->save();
        } else {
            $request->session()->put('locale', $locale);
        }
    }
56782
protected Locale getLocale( HttpServletRequest request )
    {

        HttpSession session = request.getSession();
        Locale locale = ( Locale ) session.getAttribute( Globals.LOCALE_KEY );
        return locale != null ? locale : DEFAULT_LOCALE;
    }
1135138
public function afterSend($request, $response)
    {
        $event = new RequestEvent();
        $event->request = $request;
        $event->response = $response;
        $this->trigger(self::EVENT_AFTER_SEND, $event);
    }
771730
function (request, response) {
      var locale = request.params.locale;
      var sendFile = response.sendFile || response.sendfile;
      sendFile.apply(response, [path.join(configuration.directory, locale + configuration.extension)]);
    }
724184
public function collect(Request $request, Response $response, \Exception $exception = null)
    {
        $this->startProfile = new CacheProfile($this->statsListener->getInitialStats() ?: []);
        $this->endProfile = new CacheProfile($this->statsListener->getCurrentStats() ?: []);

        $this->timeSpent = $this->statsListener->getTimeSpent();
        $this->calls = $this->statsListener->getCalls();
        $this->callSummary = $this->statsListener->getCallSummary();

        $this->summary = new CacheProfileSummary(
            $this->statsListener->getCacheType(),
            $this->statsListener->getCacheNamespace(),
            $this->startProfile,
            $this->endProfile,
            $this->callSummary
        );
    }
1370721
public function viewLiveAction(Request $request, $locale, $path = null)
    {
        $request->setLocale($locale);

        return $this->changeViewMode($request, PageInterface::STATUS_PUBLISHED, $path);
    }
716594
public function collect(Request $request, Response $response, \Exception $exception = null)
    {
        $statData = $this->getStatsdDataFactory()->gauge($this->getStatsDataKey(), $this->getMemoryUsage());
        $this->addStatsData($statData);

        return true;
    }