From 56abc53a2be12bf92e4e709c56e5b460e1169f9b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 3 Feb 2014 12:22:13 +0100 Subject: [PATCH] Properly fix the default locale issue --- .../Icinga/Application/ApplicationBootstrap.php | 6 +++++- library/Icinga/Application/Web.php | 2 +- library/Icinga/Util/Translator.php | 15 ++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index 67eb61630..c69c9f2f7 100755 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -435,7 +435,11 @@ abstract class ApplicationBootstrap */ protected function setupInternationalization() { - Translator::setupLocale($this->config->global->get('language', Translator::DEFAULT_LOCALE)); + try { + Translator::setupLocale($this->config->global->get('language', Translator::DEFAULT_LOCALE)); + } catch (Exception $error) { + Logger::info($error->getMessage()); + } $localeDir = $this->getApplicationDir('locale'); if (file_exists($localeDir) && is_dir($localeDir)) { diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 0714fee64..fa12b9b7b 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -448,7 +448,7 @@ class Web extends ApplicationBootstrap try { Translator::setupLocale($userLocale); } catch (Exception $error) { - Logger::error( + Logger::info( 'Cannot set locale "' . $userLocale . '" configured in ' . 'preferences of user "' . $this->user->getUsername() . '"' ); diff --git a/library/Icinga/Util/Translator.php b/library/Icinga/Util/Translator.php index 0e0936f8d..76089908a 100644 --- a/library/Icinga/Util/Translator.php +++ b/library/Icinga/Util/Translator.php @@ -43,11 +43,8 @@ class Translator /** * The locale code that is used in the project - * - * We are actually using en_US. "C" refers to "whatever is hardcoded" - * and is used because en_US might not be available though. */ - const DEFAULT_LOCALE = 'C'; + const DEFAULT_LOCALE = 'en_US'; /** * Known gettext domains and directories @@ -108,10 +105,14 @@ class Translator public static function setupLocale($localeName) { if (setlocale(LC_ALL, $localeName . '.UTF-8') === false) { - throw new Exception("Cannot set locale '$localeName.UTF-8' for category 'LC_ALL'"); + setlocale(LC_ALL, 'C'); // C == "use whatever is hardcoded" + if ($localeName !== self::DEFAULT_LOCALE) { + throw new Exception("Cannot set locale '$localeName.UTF-8' for category 'LC_ALL'"); + } + } else { + putenv('LC_ALL=' . $localeName . '.UTF-8'); // Failsafe, Win and Unix + putenv('LANG=' . $localeName . '.UTF-8'); // Windows fix, untested } - putenv('LC_ALL=' . $localeName . '.UTF-8'); // Failsafe, Win and Unix - putenv('LANG=' . $localeName . '.UTF-8'); // Windows fix, untested } /**