Improve failure handling when setting the locale

This commit is contained in:
Johannes Meyer 2014-04-04 15:34:46 +02:00
parent 8be3ccc527
commit ea44ae3693
2 changed files with 5 additions and 5 deletions

View File

@ -363,7 +363,7 @@ class Web extends ApplicationBootstrap
try { try {
Translator::setupLocale($locale); Translator::setupLocale($locale);
} catch (Exception $error) { } catch (Exception $error) {
Logger::info( Logger::warning(
'Cannot set locale "' . $locale . '" configured in ' . 'Cannot set locale "' . $locale . '" configured in ' .
'preferences of user "' . $this->user->getUsername() . '"' 'preferences of user "' . $this->user->getUsername() . '"'
); );

View File

@ -104,14 +104,14 @@ class Translator
*/ */
public static function setupLocale($localeName) public static function setupLocale($localeName)
{ {
if (setlocale(LC_ALL, $localeName . '.UTF-8') === false) { if (setlocale(LC_ALL, $localeName . '.UTF-8') === false && setlocale(LC_ALL, $localeName) === false) {
setlocale(LC_ALL, 'C'); // C == "use whatever is hardcoded" setlocale(LC_ALL, 'C'); // C == "use whatever is hardcoded"
if ($localeName !== self::DEFAULT_LOCALE) { if ($localeName !== self::DEFAULT_LOCALE) {
throw new Exception("Cannot set locale '$localeName.UTF-8' for category 'LC_ALL'"); throw new Exception("Cannot set locale '$localeName' for category 'LC_ALL'");
} }
} else { } else {
putenv('LC_ALL=' . $localeName . '.UTF-8'); // Failsafe, Win and Unix putenv('LC_ALL=' . setlocale(LC_ALL, 0)); // Failsafe, Win and Unix
putenv('LANG=' . $localeName . '.UTF-8'); // Windows fix, untested putenv('LANG=' . setlocale(LC_ALL, 0)); // Windows fix, untested
} }
} }