Follow up on r49157. Fixed the header parsing code to conform to RFC 2616 section...
authorPhilip Tzou <philip@users.mediawiki.org>
Fri, 22 May 2009 17:40:00 +0000 (17:40 +0000)
committerPhilip Tzou <philip@users.mediawiki.org>
Fri, 22 May 2009 17:40:00 +0000 (17:40 +0000)
languages/LanguageConverter.php

index df5409b..746adb7 100644 (file)
@@ -184,8 +184,17 @@ class LanguageConverter {
                        // preference is loaded
                        if( array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) {
                                $acceptLanguage = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
-                               $languages = preg_split('/[,;]/', $acceptLanguage);
+                               
+                               // take the part of the string up to the first semicolon
+                               if($semiPos = strpos( $acceptLanguage, ';' ) !== false )
+                                       $acceptLanguage = substr( $acceptLanguage, 0, $semiPos );
+
+                               // explode by comma
+                               $languages = explode(',', $acceptLanguage);
+
                                foreach( $languages as $language ) {
+                                       // strip whitespace
+                                       $language = trim( $language );
                                        if( in_array( $language, $this->mVariants ) ) {
                                                return $language;
                                                break;