From 531c0738daab2d5f9b8324b85b45af7131aec0da Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 16 Oct 2009 17:42:27 +0000 Subject: [PATCH] Workaround for not fully natively set up locales with native gettext... Set "en_US" locale first, then the locale we want for our user. This seems to initialize gettext properly somehow, which I could see when the languages would come up briefly on settings save when changing from a supported language. Definitely works for ga_ES on my Ubuntu system (8.10 intrepid), hopefully reasonably consistent. --- lib/util.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/util.php b/lib/util.php index 9b299cb14f..38147e998b 100644 --- a/lib/util.php +++ b/lib/util.php @@ -51,13 +51,24 @@ function common_init_locale($language=null) 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"); + $language = common_language(); - // So we don't have to make people install the gettext locales $locale_set = common_init_locale($language); - bindtextdomain("statusnet", common_config('site','locale_path')); + setlocale(LC_CTYPE, 'C'); + + // So we don't have to make people install the gettext locales + $path = common_config('site','locale_path'); + common_log(LOG_INFO, "binding text domain: $path"); + bindtextdomain("statusnet", $path); bind_textdomain_codeset("statusnet", "UTF-8"); textdomain("statusnet"); - setlocale(LC_CTYPE, 'C'); + if(!$locale_set) { common_log(LOG_INFO, 'Language requested:' . $language . ' - locale could not be set. Perhaps that system locale is not installed.', __FILE__); } -- 2.39.5