// Set a default country/timezone in installer, checking HTTP_ACCEPT_LANGUAGE #PSTEST-890
This commit is contained in:
@@ -178,4 +178,28 @@ class InstallLanguages
|
||||
|
||||
return $countries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse HTTP_ACCEPT_LANGUAGE and get first data matching list of available languages
|
||||
*
|
||||
* @return bool|array
|
||||
*/
|
||||
public function detectLanguage()
|
||||
{
|
||||
// This code is from a php.net comment : http://www.php.net/manual/fr/reserved.variables.server.php#94237
|
||||
$split_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
if (!is_array($split_languages))
|
||||
return false;
|
||||
|
||||
foreach ($split_languages as $lang)
|
||||
{
|
||||
$pattern = '/^(?P<primarytag>[a-zA-Z]{2,8})'.
|
||||
'(?:-(?P<subtag>[a-zA-Z]{2,8}))?(?:(?:;q=)'.
|
||||
'(?P<quantifier>\d\.\d))?$/';
|
||||
if (preg_match($pattern, $lang, $m))
|
||||
if (in_array($m['primarytag'], $this->getIsoList()))
|
||||
return $m;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user