// Set a default country/timezone in installer, checking HTTP_ACCEPT_LANGUAGE #PSTEST-890

This commit is contained in:
rMalie
2012-02-29 09:02:36 +00:00
parent 320e44d464
commit c402fbc7e2
3 changed files with 45 additions and 35 deletions
+24
View File
@@ -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;
}
}