mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
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 {
|
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() . '"'
|
||||||
);
|
);
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user