Merge pull request #3144 from Icinga/bugfix/http_accept_language-header-missing-2885

Handle missing Accept-Language header
This commit is contained in:
Johannes Meyer 2018-01-16 13:40:41 +01:00 committed by GitHub
commit 0ce4ccfda9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -190,7 +190,12 @@ class PreferenceForm extends Form
} }
$languages = array(); $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) { foreach (Translator::getAvailableLocaleCodes() as $language) {
$languages[$language] = $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 the preferred locale based on the given HTTP header and the available translations
* *
* @return string * @return string|null
*/ */
protected function getLocale() protected function getLocale()
{ {
$locale = Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']); return isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])
return $locale; ? Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE'])
: null;
} }
/** /**