protected function detectByRequestHeader()
    {
        // Direct stop of processing if needed header not set
        if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
            return false;
        }

        // Process header accept-language (except-language should be like 'de-de,de;q=0.8,en;q=0.3,en-us;q=0.5')
        $acceptedLanguages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);

        // Valid result?
        if (count($acceptedLanguages) < 1) {
            return false;
        }

        // iterate over raw header-entries and extract
        foreach ($acceptedLanguages as $acceptedLanguage) {
            // prepare by splitting
            $parts = explode(';', $acceptedLanguage);

            // locale preset
            $locale = strtolower(trim($parts[0]));
            $weight = 1;

            // check if q is set
            if (count($parts) > 1) {
                $weight = trim(str_replace('q=', '', $parts[1]));
            }

            // if locale is valid add it
            if ($this->isValidLocaleCode($locale) && $weight >= 0) {
                $this->addLocale($locale, $weight);
            }
        }

        // Now sort by it's weight!
        $this->detectedLocales = $this->sortByWeight($this->detectedLocales);

        // iterate over sorted result and retrieve language and country in correct order
        foreach ($this->detectedLocales as $localeSet) {
            $parts    = explode('-', $localeSet['locale']);
            $parts[1] = (isset($parts[1])) ? $parts[1] : $parts[0];

            // get language and country validated
            $language = ($this->isValidLocaleCode($parts[0])) ? $parts[0] : null;
            $country  = ($this->isValidLocaleCode($parts[1])) ? $parts[1] : null;

            // store
            $this->detectedLanguages[] = $language;
            $this->detectedCountries[] = $country;
        }

        // Success - return the preferred locale-set
        return [
            'locale'   => $this->detectedLocales[0]['locale'],
            'weight'   => $this->detectedLocales[0]['weight'],
            'language' => $this->detectedLanguages[0],
            'country'  => $this->detectedCountries[0],
        ];
    }
protected function detectByRequestHeader()
    {
        // Direct stop of processing if needed header not set
        if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
            return false;
        }

        // Process header accept-language (except-language should be like 'de-de,de;q=0.8,en;q=0.3,en-us;q=0.5')
        $acceptedLanguages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);

        // Valid result?
        if (count($acceptedLanguages) < 1) {
            return false;
        }

        // iterate over raw header-entries and extract
        foreach ($acceptedLanguages as $acceptedLanguage) {
            // prepare by splitting
            $parts = explode(';', $acceptedLanguage);

            // locale preset
            $locale = strtolower(trim($parts[0]));
            $weight = 1;

            // check if q is set
            if (count($parts) > 1) {
                $weight = trim(str_replace('q=', '', $parts[1]));
            }

            // if locale is valid add it
            if ($this->isValidLocaleCode($locale) && $weight >= 0) {
                $this->addLocale($locale, $weight);
            }
        }

        // Now sort by it's weight!
        $this->detectedLocales = $this->sortByWeight($this->detectedLocales);

        // iterate over sorted result and retrieve language and country in correct order
        foreach ($this->detectedLocales as $localeSet) {
            $parts    = explode('-', $localeSet['locale']);
            $parts[1] = (isset($parts[1])) ? $parts[1] : $parts[0];

            // get language and country validated
            $language = ($this->isValidLocaleCode($parts[0])) ? $parts[0] : null;
            $country  = ($this->isValidLocaleCode($parts[1])) ? $parts[1] : null;

            // store
            $this->detectedLanguages[] = $language;
            $this->detectedCountries[] = $country;
        }

        // Success - return the preferred locale-set
        return [
            'locale'   => $this->detectedLocales[0]['locale'],
            'weight'   => $this->detectedLocales[0]['weight'],
            'language' => $this->detectedLanguages[0],
            'country'  => $this->detectedCountries[0],
        ];
    }
protected function detectByRequestHeader ( ) { // Direct stop of processing if needed header not set if ( ! isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ) { return false ; } // Process header accept-language (except-language should be like 'de-de,de;q=0.8,en;q=0.3,en-us;q=0.5') $ acceptedLanguages = explode ( ',' , $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ; // Valid result? if ( count ( $ acceptedLanguages ) < 1 ) { return false ; } // iterate over raw header-entries and extract foreach ( $ acceptedLanguages as $ acceptedLanguage ) { // prepare by splitting $ parts = explode ( ';' , $ acceptedLanguage ) ; // locale preset $ locale = strtolower ( trim ( $ parts [ 0 ] ) ) ; $ weight = 1 ; // check if q is set if ( count ( $ parts ) > 1 ) { $ weight = trim ( str_replace ( 'q=' , '' , $ parts [ 1 ] ) ) ; } // if locale is valid add it if ( $ this -> isValidLocaleCode ( $ locale ) && $ weight >= 0 ) { $ this -> addLocale ( $ locale , $ weight ) ; } } // Now sort by it's weight! $ this -> detectedLocales = $ this -> sortByWeight ( $ this -> detectedLocales ) ; // iterate over sorted result and retrieve language and country in correct order foreach ( $ this -> detectedLocales as $ localeSet ) { $ parts = explode ( '-' , $ localeSet [ 'locale' ] ) ; $ parts [ 1 ] = ( isset ( $ parts [ 1 ] ) ) ? $ parts [ 1 ] : $ parts [ 0 ] ; // get language and country validated $ language = ( $ this -> isValidLocaleCode ( $ parts [ 0 ] ) ) ? $ parts [ 0 ] : null ; $ country = ( $ this -> isValidLocaleCode ( $ parts [ 1 ] ) ) ? $ parts [ 1 ] : null ; // store $ this -> detectedLanguages [ ] = $ language ; $ this -> detectedCountries [ ] = $ country ; } // Success - return the preferred locale-set return [ 'locale' => $ this -> detectedLocales [ 0 ] [ 'locale' ] , 'weight' => $ this -> detectedLocales [ 0 ] [ 'weight' ] , 'language' => $ this -> detectedLanguages [ 0 ] , 'country' => $ this -> detectedCountries [ 0 ] , ] ; }
This method is intend to detect the available locales by request-header.

@author Benjamin Carl <opensource@clickalicious.de>

@return bool|array FALSE on error, otherwise ARRAY containing the preferred locale(s)
This method is intend to detect the available locales by request - header .