We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 60e0f042 authored by Brion Vibber's avatar Brion Vibber

Ticket #2210: adjust locale setup fallback to try more locales on the system...

Ticket #2210: adjust locale setup fallback to try more locales on the system if en_US isn't available. We just need *something* other than C or POSIX to let gettext initialize itself, apparently...
Gets Spanish, French, Russian etc UI localization working on Debian Lenny fresh installation set up in Spanish (so es_ES.UTF-8 is available but en_US.UTF-8 isn't).
parent b98f956c
......@@ -52,17 +52,43 @@ function common_init_language()
{
mb_internal_encoding('UTF-8');
// gettext seems very picky... We first need to setlocale()
// to a locale which _does_ exist on the system, and _then_
// we can set in another locale that may not be set up
// (say, ga_ES for Galego/Galician) it seems to take it.
common_init_locale("en_US");
// Note that this setlocale() call may "fail" but this is harmless;
// gettext will still select the right language.
$language = common_language();
$locale_set = common_init_locale($language);
if (!$locale_set) {
// The requested locale doesn't exist on the system.
//
// gettext seems very picky... We first need to setlocale()
// to a locale which _does_ exist on the system, and _then_
// we can set in another locale that may not be set up
// (say, ga_ES for Galego/Galician) it seems to take it.
//
// For some reason C and POSIX which are guaranteed to work
// don't do the job. en_US.UTF-8 should be there most of the
// time, but not guaranteed.
$ok = common_init_locale("en_US");
if (!$ok) {
// Try to find a complete, working locale...
// @fixme shelling out feels awfully inefficient
// but I don't think there's a more standard way.
$all = `locale -a`;
foreach (explode("\n", $all) as $locale) {
if (preg_match('/\.utf[-_]?8$/i', $locale)) {
$ok = setlocale(LC_ALL, $locale);
if ($ok) {
break;
}
}
}
if (!$ok) {
common_log(LOG_ERR, "Unable to find a UTF-8 locale on this system; UI translations may not work.");
}
}
$locale_set = common_init_locale($language);
}
setlocale(LC_CTYPE, 'C');
// So we do not have to make people install the gettext locales
$path = common_config('site','locale_path');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment