/** * @param Event $event * @return void|string */ public function detect(Event $event) { $request = $event->getRequest(); $cookieName = $this->getCookieName(); if (!$this->isHttpRequest($request) || !$event->hasLocales()) { return; } $cookie = $request->getCookie(); if (!$cookie || !$cookie->offsetExists($cookieName)) { return; } $locale = $cookie->offsetGet($cookieName); $locales = $event->getLocales(); if (!$event->hasLocale($locale)) { return; } return $locale; }
/** * {@inheritDoc} */ public function detect(Event $event) { if (!($authService = $this->getAuthenticationService())) { return; } if ($lookup = $event->hasLocales()) { $locales = $event->getLocales(); } if ($authService->hasIdentity()) { $identity = $authService->getIdentity(); if ($identity instanceof LocalizableInterface && $identity->getLocale()) { $locale = $identity->getLocale()->getCanonicalName(); if (!$lookup) { return $locale; } if (\Locale::lookup($locales, $locale)) { return $locale; } } } }
/** * {@inheritDoc} */ public function detect(Event $event) { $request = $event->getRequest(); if (!$this->isHttpRequest($request)) { return; } $lookup = $event->hasLocales(); if ($lookup) { $locales = $event->getLocales(); } $headers = $request->getHeaders(); if ($headers->has('Accept-Language')) { foreach ($headers->get('Accept-Language')->getPrioritized() as $locale) { $locale = $locale->getLanguage(); if (!$lookup) { return $locale; } if (\Locale::lookup($locales, $locale)) { return $locale; } } } }