MDL-44843 try to hack around strict locale names in OSX

This commit is contained in:
Petr Škoda 2014-03-25 10:36:55 +08:00
parent ad32dda90c
commit 25ab60ba8e

View file

@ -7665,7 +7665,18 @@ function moodle_setlocale($locale='') {
$messages= setlocale (LC_MESSAGES, 0);
}
// Set locale to all.
setlocale (LC_ALL, $currentlocale);
$result = setlocale (LC_ALL, $currentlocale);
// If setting of locale fails try the other utf8 or utf-8 variant,
// some operating systems support both (Debian), others just one (OSX).
if ($result === false) {
if (stripos($currentlocale, '.UTF-8') !== false) {
$newlocale = str_ireplace('.UTF-8', '.UTF8', $currentlocale);
setlocale (LC_ALL, $newlocale);
} else if (stripos($currentlocale, '.UTF8') !== false) {
$newlocale = str_ireplace('.UTF8', '.UTF-8', $currentlocale);
setlocale (LC_ALL, $newlocale);
}
}
// Set old values.
setlocale (LC_MONETARY, $monetary);
setlocale (LC_NUMERIC, $numeric);