From 4b715e017679abdd25a822abf410ddd1df54d9eb Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 24 Nov 2017 16:11:06 +0100 Subject: [PATCH] Handle missing Accept-Language header refs #2885 --- application/forms/PreferenceForm.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/application/forms/PreferenceForm.php b/application/forms/PreferenceForm.php index 5ec8bfa17..80108516a 100644 --- a/application/forms/PreferenceForm.php +++ b/application/forms/PreferenceForm.php @@ -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; } /**