src/Utility/Language.php
public static function parseLanguageList($languageList = null, $options = []) {
		$defaultOptions = [
			'forceLowerCase' => true,
		];
		if (!is_array($options)) {
			$options = ['forceLowerCase' => $options];
		}
		$options += $defaultOptions;

		if ($languageList === null) {
			if (!env('HTTP_ACCEPT_LANGUAGE')) {
				return [];
			}
			$languageList = env('HTTP_ACCEPT_LANGUAGE');
		}

		$languages = [];
		$languagesRanks = [];
		$languageRanges = explode(',', trim($languageList));

		foreach ($languageRanges as $languageRange) {
			$pattern = '/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/';
			if (preg_match($pattern, trim($languageRange), $match)) {
				if (!isset($match[2])) {
					$rank = '1.0';
				} else {
					$rank = (string)(float)($match[2]);
				}
				if (!isset($languages[$rank])) {
					if ($rank === '1') {
						$rank = '1.0';
					}
					$languages[$rank] = [];
				}

				$language = $match[1];
				if ($options['forceLowerCase']) {
					$language = strtolower($language);
				} else {
					$language = substr_replace($language, strtolower(substr($language, 0, 2)), 0, 2);
					if (strlen($language) === 5) {
						$language = substr_replace($language, strtoupper(substr($language, 3, 2)), 3, 2);
					}
				}

				if (array_key_exists($language, $languagesRanks) === false) {
					$languages[$rank][] = $language;
					$languagesRanks[$language] = $rank;
				} elseif ($rank > $languagesRanks[$language]) {
					foreach ($languages as $existRank => $existLangs) {
						$key = array_search($existLangs, $languages);
						if ($key !== false) {
							unset($languages[$existRank][$key]);
							if (empty($languages[$existRank])) {
								unset($languages[$existRank]);
							}
						}
					}
					$languages[$rank][] = $language;
					$languagesRanks[$language] = $rank;
				}
			}
		}
		krsort($languages);
		return $languages;
	}
public static function parseLanguageList($languageList = null, $options = []) {
		$defaultOptions = [
			'forceLowerCase' => true,
		];
		if (!is_array($options)) {
			$options = ['forceLowerCase' => $options];
		}
		$options += $defaultOptions;

		if ($languageList === null) {
			if (!env('HTTP_ACCEPT_LANGUAGE')) {
				return [];
			}
			$languageList = env('HTTP_ACCEPT_LANGUAGE');
		}

		$languages = [];
		$languagesRanks = [];
		$languageRanges = explode(',', trim($languageList));

		foreach ($languageRanges as $languageRange) {
			$pattern = '/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/';
			if (preg_match($pattern, trim($languageRange), $match)) {
				if (!isset($match[2])) {
					$rank = '1.0';
				} else {
					$rank = (string)(float)($match[2]);
				}
				if (!isset($languages[$rank])) {
					if ($rank === '1') {
						$rank = '1.0';
					}
					$languages[$rank] = [];
				}

				$language = $match[1];
				if ($options['forceLowerCase']) {
					$language = strtolower($language);
				} else {
					$language = substr_replace($language, strtolower(substr($language, 0, 2)), 0, 2);
					if (strlen($language) === 5) {
						$language = substr_replace($language, strtoupper(substr($language, 3, 2)), 3, 2);
					}
				}

				if (array_key_exists($language, $languagesRanks) === false) {
					$languages[$rank][] = $language;
					$languagesRanks[$language] = $rank;
				} elseif ($rank > $languagesRanks[$language]) {
					foreach ($languages as $existRank => $existLangs) {
						$key = array_search($existLangs, $languages);
						if ($key !== false) {
							unset($languages[$existRank][$key]);
							if (empty($languages[$existRank])) {
								unset($languages[$existRank]);
							}
						}
					}
					$languages[$rank][] = $language;
					$languagesRanks[$language] = $rank;
				}
			}
		}
		krsort($languages);
		return $languages;
	}
public static function parseLanguageList ( $ languageList = null , $ options = [ ] ) { $ defaultOptions = [ 'forceLowerCase' => true , ] ; if ( ! is_array ( $ options ) ) { $ options = [ 'forceLowerCase' => $ options ] ; } $ options += $ defaultOptions ; if ( $ languageList === null ) { if ( ! env ( 'HTTP_ACCEPT_LANGUAGE' ) ) { return [ ] ; } $ languageList = env ( 'HTTP_ACCEPT_LANGUAGE' ) ; } $ languages = [ ] ; $ languagesRanks = [ ] ; $ languageRanges = explode ( ',' , trim ( $ languageList ) ) ; foreach ( $ languageRanges as $ languageRange ) { $ pattern = '/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/' ; if ( preg_match ( $ pattern , trim ( $ languageRange ) , $ match ) ) { if ( ! isset ( $ match [ 2 ] ) ) { $ rank = '1.0' ; } else { $ rank = ( string ) ( float ) ( $ match [ 2 ] ) ; } if ( ! isset ( $ languages [ $ rank ] ) ) { if ( $ rank === '1' ) { $ rank = '1.0' ; } $ languages [ $ rank ] = [ ] ; } $ language = $ match [ 1 ] ; if ( $ options [ 'forceLowerCase' ] ) { $ language = strtolower ( $ language ) ; } else { $ language = substr_replace ( $ language , strtolower ( substr ( $ language , 0 , 2 ) ) , 0 , 2 ) ; if ( strlen ( $ language ) === 5 ) { $ language = substr_replace ( $ language , strtoupper ( substr ( $ language , 3 , 2 ) ) , 3 , 2 ) ; } } if ( array_key_exists ( $ language , $ languagesRanks ) === false ) { $ languages [ $ rank ] [ ] = $ language ; $ languagesRanks [ $ language ] = $ rank ; } elseif ( $ rank > $ languagesRanks [ $ language ] ) { foreach ( $ languages as $ existRank => $ existLangs ) { $ key = array_search ( $ existLangs , $ languages ) ; if ( $ key !== false ) { unset ( $ languages [ $ existRank ] [ $ key ] ) ; if ( empty ( $ languages [ $ existRank ] ) ) { unset ( $ languages [ $ existRank ] ) ; } } } $ languages [ $ rank ] [ ] = $ language ; $ languagesRanks [ $ language ] = $ rank ; } } } krsort ( $ languages ) ; return $ languages ; }
Parse languages from a browser language list.

Options
- forceLowerCase: defaults to true

@param string|null $languageList List of locales/language codes.
@param array|bool|null $options Flags to forceLowerCase or removeDuplicates locales/language codes
deprecated: Set to true/false to toggle lowercase

@return array
Parse languages from a browser language list .