Properly fix the default locale issue

This commit is contained in:
Johannes Meyer 2014-02-03 12:22:13 +01:00
parent 2ecf1a99a6
commit 56abc53a2b
3 changed files with 14 additions and 9 deletions

View File

@ -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)) {

View File

@ -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() . '"'
);

View File

@ -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
}
/**