From ae05da2ba1ea4675283c2cceed4dd7956f63fd65 Mon Sep 17 00:00:00 2001 From: Gabor Hojtsy Date: Sat, 1 Mar 2003 13:52:46 +0000 Subject: [PATCH] Applying KISS, taking account the user's Accept Language browser setting (without bothering with the priority values provided by the UA, as those are not applicable for us). --- include/langchooser.inc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/langchooser.inc b/include/langchooser.inc index f9be22e12..d07bbff70 100644 --- a/include/langchooser.inc +++ b/include/langchooser.inc @@ -30,9 +30,19 @@ if (preg_match("!^/(\\w{2}(_\\w{2})?)/!", $_SERVER['REQUEST_URI'], $flang)) { if (preg_match("!^/manual/(\\w{2}(_\\w{2})?)(/|$)!", $_SERVER['REQUEST_URI'], $flang)) { language_add($flang[1]); } +unset($flang); // USER PREFERENCE HANDLING SHOULD BE ADDED HERE IN THE FUTURE +// Specified by the user via the browser's Accept Language setting +// Samples: "hu, en-us;q=0.66, en;q=0.33", "hu,en-us;q=0.5" +$browser_accept = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); +foreach ($browser_accept as $idx => $langcode) { + list($langcode) = @explode(";", trim($langcode)); + language_add($langcode); +} +unset($browser_accept); unset($idx); unset($langcode); + // Language preferred by this mirror site language_add(default_language()); @@ -64,9 +74,9 @@ function language_add($langcode) // The Brazilian Portuguese code needs special attention if ($langcode == 'pt_br') { $langcode = 'pt_BR'; } - // Append language code in priority order - // if it is not there already [try to lower number - // of file_exists() calls to minumum] + // Append language code in priority order if it is not + // there already and supported by the PHP site. Try to + // lower number of file_exists() calls to the minumum... if (!in_array($langcode, $LANGS) && isset($LANGUAGES[$langcode])) { $LANGS[] = $langcode; } }