mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
Add UA::getLocale()
This commit is contained in:
parent
154bddfd18
commit
dfc1082c85
3 changed files with 33 additions and 10 deletions
|
|
@ -177,6 +177,21 @@ class UA
|
|||
return self::$_robot_cache[$ua] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method parses the Accept-Language header to guess the browser's default locale.
|
||||
*
|
||||
* @param string $header (optional)
|
||||
* @return string
|
||||
*/
|
||||
public static function getLocale($header = null)
|
||||
{
|
||||
// Get the Accept-Language header if the caller did not specify $header.
|
||||
$header = $header ?: (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : 'en-US');
|
||||
|
||||
// Return the first locale name found.
|
||||
return preg_match('/^([a-z0-9_-]+)/i', $header, $matches) ? $matches[1] : 'en-US';
|
||||
}
|
||||
|
||||
/**
|
||||
* This method parses the User-Agent string to guess what kind of browser it is.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue