Improve failure handling when setting the locale
This commit is contained in:
parent
8be3ccc527
commit
ea44ae3693
|
@ -363,7 +363,7 @@ class Web extends ApplicationBootstrap
|
|||
try {
|
||||
Translator::setupLocale($locale);
|
||||
} catch (Exception $error) {
|
||||
Logger::info(
|
||||
Logger::warning(
|
||||
'Cannot set locale "' . $locale . '" configured in ' .
|
||||
'preferences of user "' . $this->user->getUsername() . '"'
|
||||
);
|
||||
|
|
|
@ -104,14 +104,14 @@ class Translator
|
|||
*/
|
||||
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"
|
||||
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 {
|
||||
putenv('LC_ALL=' . $localeName . '.UTF-8'); // Failsafe, Win and Unix
|
||||
putenv('LANG=' . $localeName . '.UTF-8'); // Windows fix, untested
|
||||
putenv('LC_ALL=' . setlocale(LC_ALL, 0)); // Failsafe, Win and Unix
|
||||
putenv('LANG=' . setlocale(LC_ALL, 0)); // Windows fix, untested
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue