fix install/update problem for languages without language files
authorZheng Zhu <zhengzhu@users.mediawiki.org>
Mon, 6 Dec 2004 04:36:12 +0000 (04:36 +0000)
committerZheng Zhu <zhengzhu@users.mediawiki.org>
Mon, 6 Dec 2004 04:36:12 +0000 (04:36 +0000)
languages/Language.php
maintenance/InitialiseMessages.inc

index 6e086b3..0a754f4 100644 (file)
@@ -2169,20 +2169,35 @@ class Language {
 
        function getPreferredVariant() {
                global $wgUser;
-               
+
+               $lang ='';              
+
                // if user logged in, get in from user's preference
-               if( $wgUser->getID() != 0 )
-                       return $wgUser->getOption( 'variant' );
-               
+               if( $wgUser->getID() != 0 ) {
+                       $lang = $wgUser->getOption( 'variant' );
+               }
+               if($lang != '')
+                       return $lang;
+
                // if we have multiple variants for this langauge, 
-               // pick the first one as default
+               // pick the first one that's not utf8 (it could be
+               // utf8 if the language does not have a language file)
                $v = $this->getVariants();
-               if( !empty( $v ) )
-                       return $v{0};
-               
-               // otherwise there should really be just one variant, 
+               if( !empty( $v ) ) {
+                       foreach ($v as $v2) {
+                               if($v2 != 'utf8') {
+                                       $lang = $v2;
+                                       break;
+                               }
+                       }
+               }
+               if($lang != '')
+                       return $lang;
+
                // get it from the class name
                $lang = strtolower( substr( get_class( $this ), 8 ) );
+               if($lang == 'utf8')
+                       $lang = 'en';
                return $lang;
        }
 
index b270824..9a9ea04 100755 (executable)
@@ -19,16 +19,9 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) {
        global $IP;
 
        # overwrite language conversion option so that all variants 
-       # of the messages are initialised
+       # of the selected language are initialised
        $wgDisableLangConversion = false;
 
-       $langclass = 'Language'. str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
-       require_once("$IP/languages/$langclass.php");
-
-       $variants = $wgContLang->getVariants();
-       if(!in_array($wgContLanguageCode, $variants))
-               $variants[]=$wgContLanguageCode;
-
        if ( $messageArray ) {
                $sortedArray = $messageArray;
        } else {
@@ -36,20 +29,35 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) {
        }
        
        ksort( $sortedArray );
-       
        $messages=array();
-       foreach ($variants as $v) {
-               $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
-               $lang = new $langclass;
-               if(!is_object($lang)) {
-                       die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
-               }
-               if($v==$wgContLanguageCode)
-                       $suffix='';
-               else
-                       $suffix="/$v";
+
+       /* check special case where the language does 
+          not have a language file 
+       */
+       if( get_class($wgContLang) != 'language'.strtolower($wgContLanguageCode) ) {
                foreach ($sortedArray as $key => $msg) {
-                       $messages[$key.$suffix] = $lang->getMessage($key);
+                       $messages[$key] = $wgContLang->getMessage($key);
+               }
+       }
+       else {
+               $variants = $wgContLang->getVariants();
+               if(!in_array($wgContLanguageCode, $variants))
+                       $variants[]=$wgContLanguageCode;
+
+               foreach ($variants as $v) {
+                       $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
+                       if( !class_exists($langclass) ) {
+                               die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
+                       }
+                       $lang = new $langclass;
+
+                       if($v==$wgContLanguageCode)
+                               $suffix='';
+                       else
+                               $suffix="/$v";
+                       foreach ($sortedArray as $key => $msg) {
+                               $messages[$key.$suffix] = $lang->getMessage($key);
+                       }
                }
        }