From b49c2f051a0d95ac280af0250e69215faee6018b Mon Sep 17 00:00:00 2001 From: CiaranG Date: Thu, 2 Oct 2008 14:13:38 -0400 Subject: Combined language patches that got missed due to repo dependencies darcs-hash:20081002181338-f6e2c-cf9cf3791680634fa457cb83dc2e4f933073a9b1.gz --- lib/util.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'lib/util.php') diff --git a/lib/util.php b/lib/util.php index 87c7f8fb0..cf514564e 100644 --- a/lib/util.php +++ b/lib/util.php @@ -146,6 +146,7 @@ function common_init_language() { bind_textdomain_codeset("laconica", "UTF-8"); textdomain("laconica"); setlocale(LC_CTYPE, 'C'); + common_log(LOG_INFO,'Language requested:'.$language.' Locale set:'.$locale_set,__FILE__); } define('PAGE_TYPE_PREFS', 'text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2'); @@ -483,25 +484,27 @@ function common_timezone() { } function common_language() { - $httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : NULL; - $language = array(); - $user_language = FALSE; + // If there is a user logged in and they've set a language preference + // then return that one... if (common_logged_in()) { $user = common_current_user(); $user_language = $user->language; + if ($user_language) + return $user_language; } - if ($user_language) { - return $user_language; - } else if (!empty($httplang)) { - $language = client_prefered_language($httplang); - if ($language) { - return $language; - } - } else { - return common_config('site', 'language'); - } + // Otherwise, find the best match for the languages requested by the + // user's browser... + $httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : NULL; + if (!empty($httplang)) { + $language = client_prefered_language($httplang); + if ($language) + return $language; + } + + // Finally, if none of the above worked, use the site's default... + return common_config('site', 'language'); } # salted, hashed passwords are stored in the DB -- cgit v1.2.3-54-g00ecf