From: Zheng Zhu Date: Tue, 7 Dec 2004 20:22:22 +0000 (+0000) Subject: more fixes for languages with no language files; allow UI customization for all langu... X-Git-Tag: 1.5.0alpha1~1132 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=7bee69578ce10fd49e56c37b5c1d0a51195a584d;p=lhc%2Fweb%2Fwiklou.git more fixes for languages with no language files; allow UI customization for all languages. --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 943fe152ab..188e2c40eb 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -378,46 +378,16 @@ function wfMsgReal( $key, $args, $useDB, $forContent=false ) { $fname = 'wfMsgReal'; wfProfileIn( $fname ); - if( $forContent ) { - /** - * Message is needed for page content, and needs - * to be consistent with the site's configured - * language. It might be part of a page title, - * or a link, or text that will go into the - * parser cache and be served back to other - * visitors. - */ - $cache = &$wgMessageCache; - $lang = &$wgContLang; - } else { - /** - * Message is for display purposes only. - * The user may have selected a conversion-based - * language variant or a separate user interface - * language; if so use that. - */ - if ( is_object( $wgContLang ) ) { - if( in_array( $wgLanguageCode, $wgContLang->getVariants() ) ) { - $cache = &$wgMessageCache; - $lang = &$wgLang; - } else { - $cache = false; - $lang = &$wgLang; - } + if( is_object( $wgMessageCache ) ) { + $message = $wgMessageCache->get( $key, $useDB, $forContent ); + } + else { + if( $forContent ) { + $lang = &$wgContLang; } else { - $cache = false; - $lang = false; + $lang = &$wgLang; } - } - - if( is_object( $cache ) ) { - $message = $cache->get( $key, $useDB, $forContent ); - } else { - if ( !is_object( $lang ) ) { - $lang = new Language; - } - wfSuppressWarnings(); $message = $lang->getMessage( $key ); wfRestoreWarnings(); diff --git a/includes/Setup.php b/includes/Setup.php index 1f351c316a..d609498d03 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -239,28 +239,29 @@ if( $wgCommandLineMode ) { wfProfileOut( $fname.'-User' ); wfProfileIn( $fname.'-language2' ); -function setupLangObj(&$langclass, $langcode) { +function setupLangObj(&$langclass) { global $wgUseLatin1, $IP; - if( ! class_exists( $langclass ) ) { - # Default to English/UTF-8 - require_once( "$IP/languages/LanguageUtf8.php" ); - $langclass = 'LanguageUtf8'; + # Default to English/UTF-8, or for non-UTF-8, to latin-1 + $baseclass = 'LanguageUtf8'; + if( $wgUseLatin1 ) + $baseclass = 'LanguageLatin1'; + require_once( "$IP/languages/$baseclass.php" ); + $lc = strtolower(substr($langclass, 8)); + $snip = " + class $langclass extends $baseclass { + function getVariants() { + return array(\"$lc\"); + } + + }"; + + eval($snip); } $lang = new $langclass(); - if ( !is_object($lang) ) { - print "No language class ($wgLang)\N"; - } - if( $wgUseLatin1 ) { - # For non-UTF-8 latin-1 downconversion - require_once( "$IP/languages/LanguageLatin1.php" ); - $xxx = new LanguageLatin1( $lang ); - unset( $lang ); - $lang = $xxx; - } return $lang; } @@ -270,8 +271,7 @@ function setupLangObj(&$langclass, $langcode) { $wgContLanguageCode = $wgLanguageCode; $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) ); -$wgContLang = setupLangObj( $wgContLangClass, $wgContLangClass ); -$n = get_class($wgContLang); +$wgContLang = setupLangObj( $wgContLangClass ); // set default user option from content language if( !$wgUser->mDataLoaded ) { @@ -286,10 +286,12 @@ $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) ); if( $wgLangClass == $wgContLangClass ) { $wgLang = &$wgContLang; } else { - require_once("$IP/languages/$wgLangClass.php"); - $wgLang = setupLangObj( $wgLangClass, $wgLanguageCode ); -} + wfSuppressWarnings(); + include_once("$IP/languages/$wgLangClass.php"); + wfRestoreWarnings(); + $wgLang = setupLangObj( $wgLangClass ); +} wfProfileOut( $fname.'-language' ); wfProfileIn( $fname.'-MessageCache' ); diff --git a/includes/SpecialAllmessages.php b/includes/SpecialAllmessages.php index 1fe5408d3f..a58f9f0d4d 100644 --- a/includes/SpecialAllmessages.php +++ b/includes/SpecialAllmessages.php @@ -13,12 +13,6 @@ function wfSpecialAllmessages() { global $wgLanguageCode, $wgContLanguageCode, $wgContLang; global $wgUseDatabaseMessages; - if($wgLanguageCode != $wgContLanguageCode && - !in_array($wgLanguageCode, $wgContLang->getVariants())) { - $err = wfMsg('allmessagesnotsupportedUI', $wgLanguageCode); - $wgOut->addHTML( $err ); - return; - } if(!$wgUseDatabaseMessages) { $wgOut->addHTML(wfMsg('allmessagesnotsupportedDB')); return; @@ -94,7 +88,7 @@ function makePhp($messages) { * */ function makeHTMLText( $messages ) { - global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode; + global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode, $wgContLang; $fname = "makeHTMLText"; wfProfileIn( $fname ); @@ -128,11 +122,13 @@ function makeHTMLText( $messages ) { wfProfileOut( "$fname-check" ); wfProfileIn( "$fname-output" ); + foreach( $messages as $key => $m ) { $title = $wgLang->ucfirst( $key ); if($wgLanguageCode != $wgContLanguageCode) $title.="/$wgLanguageCode"; + $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title ); $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title ); diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index dbb452d356..962cc33e88 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -323,7 +323,7 @@ class PreferencesForm { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgUseDynamicDates, $wgValidSkinNames; global $wgAllowRealName, $wgImageLimits; global $wgLanguageNames, $wgDisableLangConversion; - + global $wgContLanguageCode; $wgOut->setPageTitle( wfMsg( 'preferences' ) ); $wgOut->setArticleRelated( false ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); @@ -417,7 +417,7 @@ class PreferencesForm { global $IP; /* only add languages that have a file */ $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php"; - if(file_exists($langfile)) { + if(file_exists($langfile) || $code == $wgContLanguageCode) { $sel = ($code == $this->mUserLanguage)? 'selected="selected"' : ''; $wgOut->addHtml("\t\n"); } diff --git a/languages/Language.php b/languages/Language.php index 329a4d12f9..1b95b97da0 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2184,20 +2184,14 @@ class Language { // utf8 if the language does not have a language file) $v = $this->getVariants(); if( !empty( $v ) ) { - foreach ($v as $v2) { - if($v2 != 'utf8') { - $lang = $v2; - break; - } - } + return $v[0]; } if($lang != '') return $lang; // get it from the class name $lang = strtolower( substr( get_class( $this ), 8 ) ); - if($lang == 'utf8') - $lang = 'en'; + return $lang; } diff --git a/maintenance/InitialiseMessages.inc b/maintenance/InitialiseMessages.inc index 9a9ea04c39..1866e71546 100755 --- a/maintenance/InitialiseMessages.inc +++ b/maintenance/InitialiseMessages.inc @@ -19,7 +19,7 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) { global $IP; # overwrite language conversion option so that all variants - # of the selected language are initialised + # of the messages are initialised $wgDisableLangConversion = false; if ( $messageArray ) { @@ -31,35 +31,25 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) { ksort( $sortedArray ); $messages=array(); - /* check special case where the language does - not have a language file - */ - if( get_class($wgContLang) != 'language'.strtolower($wgContLanguageCode) ) { + $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] = $wgContLang->getMessage($key); + $messages[$key.$suffix] = $lang->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); - } - } - } initialiseMessagesReal( $overwrite, $messages ); }