Networking\InitCmsBundle\EventListener\LocaleListener::getBrowserAcceptLanguages PHP Method

getBrowserAcceptLanguages() public method

get browser accept languages
public getBrowserAcceptLanguages ( Request $request ) : array
$request Symfony\Component\HttpFoundation\Request
return array
    public function getBrowserAcceptLanguages(Request $request)
    {
        $browserLanguages = array();
        if (strlen($request->server->get('HTTP_ACCEPT_LANGUAGE')) == 0) {
            return array();
        }
        $languages = $this->splitHttpAcceptHeader($request->server->get('HTTP_ACCEPT_LANGUAGE'));
        foreach ($languages as $lang) {
            if (strstr($lang, '-')) {
                $codes = explode('-', $lang);
                if ($codes[0] == 'i') {
                    // Language not listed in ISO 639 that are not variants
                    // of any listed language, which can be registered with the
                    // i-prefix, such as i-cherokee
                    if (count($codes) > 1) {
                        $lang = $codes[1];
                    }
                } else {
                    for ($i = 0, $max = count($codes); $i < $max; $i++) {
                        if ($i == 0) {
                            $lang = strtolower($codes[0]);
                        } else {
                            $lang .= '_' . strtoupper($codes[$i]);
                        }
                    }
                }
            }
            $browserLanguages[] = $lang;
        }
        return $browserLanguages;
    }