Get locale from http accepted languages server.

@return null|string
161761
private function getFromHttpAcceptedLanguagesServer()
    {
        $httpAcceptLanguage = $this->request->server('HTTP_ACCEPT_LANGUAGE');

        // @codeCoverageIgnoreStart
        if ( ! class_exists('Locale') || empty($httpAcceptLanguage))
            return null;
        // @codeCoverageIgnoreEnd

        $locale = Locale::acceptFromHttp($httpAcceptLanguage);

        if ($this->isSupported($locale)) return $locale;

        return null;
    }
1209695
private function getFromAcceptedLanguagesHeader()
    {
        $matches = $this->getMatchesFromAcceptedLanguages();

        if ($locale = $this->inSupportedLocales($matches)) {
            return $locale;
        }

        // If any (i.e. "*") is acceptable, return the first supported locale
        if (isset($matches['*'])) {
            return $this->supportedLocales->first()->key();
        }

        return null;
    }
534920
public function getLanguage()
    {
        if ($this->sessionManager) {
            $this->sessionManager->start();
        }
        if (!isset($_SESSION['_fine_I18n_language'])){
            return null;
        }
        return $_SESSION['_fine_I18n_language'];
    }
311939
public static function getLocale()
    {
        static::getDefaultLocale();
        $current = Locale::getDefault();
        if ($current === '') {
            $current = static::DEFAULT_LOCALE;
            Locale::setDefault($current);
        }

        return $current;
    }
22230
protected function _getCurrentLanguage() {
        if (!isset($_SERVER['REQUEST_URI'])) {
            // Probably CLI context. Return the default locale
            return Garp_I18n::getDefaultLocale();
        }
        $requestUri = $_SERVER['REQUEST_URI'];
        $bits = explode('/', $requestUri);
        // remove empty values
        $bits = array_filter($bits, 'strlen');
        // reindex the array
        $bits = array_values($bits);
        $bits = array_map('strtolower', $bits);
        $locales = $this->_getPossibleLocales();
        if (array_key_exists(0, $bits) && in_array($bits[0], $locales)) {
            return $bits[0];
        }
        return Garp_I18n::getDefaultLocale();
    }
887219
function httpLocaleCode()
    {
        $ini = eZINI::instance();
        $localeCode = '';
        if ( $ini->hasVariable( 'RegionalSettings', 'HTTPLocale' ) )
        {
            $localeCode = $ini->variable( 'RegionalSettings', 'HTTPLocale' );
        }
        if ( $localeCode == '' and
             $this->HTTPLocaleCode != '' )
            $localeCode = $this->HTTPLocaleCode;
        if ( $localeCode == '' )
            $localeCode = $this->localeCode();
        return $localeCode;
    }
866633
public function getCurrentLanguage()
    {
        if ($this->getStorageMethod() == 'session') {
            return Session::get($this->getLanguageKey(), Config::get('app.locale'));
        }
        return Request::cookie($this->getLanguageKey()) ?: Config::get('app.locale');
    }
476315
public static function setLocale($locale = null) {
        $app = app();
        $currentLocale = $app->config->get('app.locale');
        if (empty($locale) || !is_string($locale)) {
            // If the locale has not been passed through the function
            // it tries to get it from the first segment of the url
            $locale = $app->request->segment(1);
        }
        if (!in_array($locale, $app->config->get('sirgrimorum.crudgenerator.list_locales'))) {
            $locale = $currentLocale;
        }

        //if (!empty($this->supportedLocales[$locale])) {
        $currentLocale = $locale;
        //}

        $app->setLocale($currentLocale);

        return $currentLocale;
    }
493260
protected function getLocale()
    {
        if (!$this->hasArgument('forceLocale')) {
            return null;
        }
        $forceLocale = $this->arguments['forceLocale'];
        $useLocale = null;
        if ($forceLocale instanceof I18n\Locale) {
            $useLocale = $forceLocale;
        } elseif (is_string($forceLocale)) {
            try {
                $useLocale = new I18n\Locale($forceLocale);
            } catch (I18n\Exception $exception) {
                throw new InvalidVariableException('"' . $forceLocale . '" is not a valid locale identifier.', 1342610148, $exception);
            }
        } elseif ($forceLocale === true) {
            $useLocale = $this->localizationService->getConfiguration()->getCurrentLocale();
        }

        return $useLocale;
    }
1001427
public static function getLanguageForSession()
    {
        $cookieName = Config::getInstance()->General['language_cookie_name'];
        $cookie = new Cookie($cookieName);
        if ($cookie->isCookieFound()) {
            return $cookie->get('language');
        }
        return null;
    }
1029902
public function getSiblingLocales()
    {
        $domain = $this->getDomain();
        $locales = $domain
            ? $domain->getLocales()
            : Locale::getCached();
        return $locales;
    }
640019
public static function getLocale()
    {
        if (empty(self::$locale)) {
            self::$locale = new StringType(\locale_get_default());
        }

        return self::$locale;
    }
1348213
public function getClientPreferredLocale()
    {
        if (null !== $this->locale) {
            $locale = $this->locale;

        } else {
            // Get detector
            $detector = $this->getDetector();

            // Detect user's preferred locale
            $detector->detect();

            // get the locale from detector
            $locale = $detector->getLocale();
        }

        // return the active locale
        return $locale;
    }
457528
public function getLocale()
    {
        $language = $this->getLanguage();
        $country = $this->getCountry();

        if (empty($language) || empty($country)) {
            return null;
        }

        return
            strtolower($language->getIso6391())
            . '_' .
            strtoupper($country->getIso2());
    }
589725
public function getFromClient() {
		$returner = [];

		// Example string
		// en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2

		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
			$parts = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);

			foreach ($parts as $part) {
				preg_match("|^
					(.*?)		# the language part
					([-].*?)?	# the country part (optional)
					(;q=(.*))?	# the quality part (optional)
				$|x", $part, $matches);

				// set quality to 1.0 if not given
				$quality	= isset($matches[4]) ? $matches[4] : '1.0';

				$returner[$quality] = strtolower(trim($matches[1]));
			}
			krsort($returner);
		}
		return $returner;
	}
963561
public function clientLang()
	{
		if ( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ) {

			$language = explode(',', preg_replace('/(;\s?q=[0-9\.]+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))));
			return strtolower($language[0]);
		}

		return;
	}
671650
def browser_locale
      accept_lang = @env["HTTP_ACCEPT_LANGUAGE"]
      return if accept_lang.nil?

      langs = accept_lang.split(",").map do |l|
        l += ";q=1.0" unless l =~ /;q=\d+\.\d+$/
        l.split(";q=")
      end

      langs.sort! { |a, b| b[1] <=> a[1] }

      if check_accepted?
        langs.each do |lang|
          l = accepted_locale(split_lang(lang.first).to_sym)
          return l unless l.nil?
        end
      end

      split_lang(langs.first.first)
    end