Handle missing Accept-Language header

refs #2885
This commit is contained in:
Alexander A. Klimov 2017-11-24 16:11:06 +01:00 committed by Johannes Meyer
parent 00b411ad32
commit 4b715e0176
1 changed files with 10 additions and 4 deletions

View File

@ -190,7 +190,12 @@ class PreferenceForm extends Form
}
$languages = array();
$languages['autodetect'] = sprintf($this->translate('Browser (%s)', 'preferences.form'), $this->getLocale());
$locale = $this->getLocale();
if ($locale !== null) {
$languages['autodetect'] = sprintf($this->translate('Browser (%s)', 'preferences.form'), $locale);
}
foreach (Translator::getAvailableLocaleCodes() as $language) {
$languages[$language] = $language;
}
@ -337,12 +342,13 @@ class PreferenceForm extends Form
/**
* Return the preferred locale based on the given HTTP header and the available translations
*
* @return string
* @return string|null
*/
protected function getLocale()
{
$locale = Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']);
return $locale;
return isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])
? Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE'])
: null;
}
/**