public function detect()
	{
		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
		{
			$browserLangs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
			$systemLangs  = $this->available();
			foreach ($browserLangs as $browserLang)
			{
				// Slice out the part before ; on first step, the part before - on second, place into array
				$browserLang = substr($browserLang, 0, strcspn($browserLang, ';'));
				$primary_browserLang = substr($browserLang, 0, 2);
				foreach ($systemLangs as $systemLang)
				{
					// Take off 3 letters iso code languages as they can't match browsers' languages and default them to en
					$Jinstall_lang = $systemLang->lang_code;

					if (strlen($Jinstall_lang) < 6)
					{
						if (strtolower($browserLang) == strtolower(substr($systemLang->lang_code, 0, strlen($browserLang))))
						{
							return $systemLang->lang_code;
						}
						elseif ($primary_browserLang == substr($systemLang->lang_code, 0, 2))
						{
							$primaryDetectedLang = $systemLang->lang_code;
						}
					}
				}

				if (isset($primaryDetectedLang))
				{
					return $primaryDetectedLang;
				}
			}
		}

		return null;
	}
public function detect()
	{
		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
		{
			$browserLangs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
			$systemLangs  = $this->available();
			foreach ($browserLangs as $browserLang)
			{
				// Slice out the part before ; on first step, the part before - on second, place into array
				$browserLang = substr($browserLang, 0, strcspn($browserLang, ';'));
				$primary_browserLang = substr($browserLang, 0, 2);
				foreach ($systemLangs as $systemLang)
				{
					// Take off 3 letters iso code languages as they can't match browsers' languages and default them to en
					$Jinstall_lang = $systemLang->lang_code;

					if (strlen($Jinstall_lang) < 6)
					{
						if (strtolower($browserLang) == strtolower(substr($systemLang->lang_code, 0, strlen($browserLang))))
						{
							return $systemLang->lang_code;
						}
						elseif ($primary_browserLang == substr($systemLang->lang_code, 0, 2))
						{
							$primaryDetectedLang = $systemLang->lang_code;
						}
					}
				}

				if (isset($primaryDetectedLang))
				{
					return $primaryDetectedLang;
				}
			}
		}

		return null;
	}
public function detect ( ) { if ( isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ) { $ browserLangs = explode ( ',' , $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ; $ systemLangs = $ this -> available ( ) ; foreach ( $ browserLangs as $ browserLang ) { // Slice out the part before ; on first step, the part before - on second, place into array $ browserLang = substr ( $ browserLang , 0 , strcspn ( $ browserLang , ';' ) ) ; $ primary_browserLang = substr ( $ browserLang , 0 , 2 ) ; foreach ( $ systemLangs as $ systemLang ) { // Take off 3 letters iso code languages as they can't match browsers' languages and default them to en $ Jinstall_lang = $ systemLang -> lang_code ; if ( strlen ( $ Jinstall_lang ) < 6 ) { if ( strtolower ( $ browserLang ) == strtolower ( substr ( $ systemLang -> lang_code , 0 , strlen ( $ browserLang ) ) ) ) { return $ systemLang -> lang_code ; } elseif ( $ primary_browserLang == substr ( $ systemLang -> lang_code , 0 , 2 ) ) { $ primaryDetectedLang = $ systemLang -> lang_code ; } } } if ( isset ( $ primaryDetectedLang ) ) { return $ primaryDetectedLang ; } } } return null ; }
Tries to detect the language.

@return  string  locale or null if not found
Tries to detect the language .