// 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

View File

@@ -175,7 +175,12 @@ abstract class InstallControllerHttp
// Set current language
$this->language = InstallLanguages::getInstance();
$lang = (isset($this->session->lang)) ? $this->session->lang : $this->detectLanguage();
$detect_language = $this->language->detectLanguage();
if (isset($this->session->lang))
$lang = $this->session->lang;
else
$lang = (isset($detect_language['primarytag'])) ? $detect_language['primarytag'] : false;
if (!in_array($lang, $this->language->getIsoList()))
$lang = 'en';
$this->language->setLanguage($lang);
@@ -391,25 +396,6 @@ abstract class InstallControllerHttp
}
}
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->language->getIsoList()))
return $m['primarytag'];
}
return false;
}
public function &__get($varname)
{
if (isset($this->__vars[$varname]))