MediaWiki  REL1_21
LanguageZh.php
Go to the documentation of this file.
00001 <?php
00024 require_once( __DIR__ . '/../LanguageConverter.php' );
00025 require_once( __DIR__ . '/LanguageZh_hans.php' );
00026 
00030 class ZhConverter extends LanguageConverter {
00031 
00040         function __construct( $langobj, $maincode,
00041                                                                 $variants = array(),
00042                                                                 $variantfallbacks = array(),
00043                                                                 $flags = array(),
00044                                                                 $manualLevel = array() ) {
00045                 $this->mDescCodeSep = ':';
00046                 $this->mDescVarSep = ';';
00047                 parent::__construct( $langobj, $maincode,
00048                                                                         $variants,
00049                                                                         $variantfallbacks,
00050                                                                         $flags,
00051                                                                         $manualLevel );
00052                 $names = array(
00053                         'zh'      => '原文',
00054                         'zh-hans' => '简体',
00055                         'zh-hant' => '繁體',
00056                         'zh-cn'   => '大陆',
00057                         'zh-tw'   => '台灣',
00058                         'zh-hk'   => '香港',
00059                         'zh-mo'   => '澳門',
00060                         'zh-sg'   => '新加坡',
00061                         'zh-my'   => '大马',
00062                 );
00063                 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
00064         }
00065 
00066         function loadDefaultTables() {
00067                 require( __DIR__ . "/../../includes/ZhConversion.php" );
00068                 $this->mTables = array(
00069                         'zh-hans' => new ReplacementArray( $zh2Hans ),
00070                         'zh-hant' => new ReplacementArray( $zh2Hant ),
00071                         'zh-cn'   => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
00072                         'zh-hk'   => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
00073                         'zh-mo'   => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
00074                         'zh-my'   => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
00075                         'zh-sg'   => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
00076                         'zh-tw'   => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
00077                         'zh'      => new ReplacementArray
00078                 );
00079         }
00080 
00081         function postLoadTables() {
00082                 $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
00083                 $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
00084                 $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
00085                 $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
00086                 $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
00087                 $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
00088         }
00089 
00094         function convertCategoryKey( $key ) {
00095                 return $this->autoConvert( $key, 'zh' );
00096         }
00097 }
00098 
00105 class LanguageZh extends LanguageZh_hans {
00106 
00107         function __construct() {
00108                 global $wgHooks;
00109                 parent::__construct();
00110 
00111                 $variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
00112 
00113                 $variantfallbacks = array(
00114                         'zh'      => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
00115                         'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
00116                         'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
00117                         'zh-cn'   => array( 'zh-hans', 'zh-sg', 'zh-my' ),
00118                         'zh-sg'   => array( 'zh-hans', 'zh-cn', 'zh-my' ),
00119                         'zh-my'   => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
00120                         'zh-tw'   => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
00121                         'zh-hk'   => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
00122                         'zh-mo'   => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
00123                 );
00124                 $ml = array(
00125                         'zh'      => 'disable',
00126                         'zh-hans' => 'unidirectional',
00127                         'zh-hant' => 'unidirectional',
00128                 );
00129 
00130                 $this->mConverter = new ZhConverter( $this, 'zh',
00131                                                                 $variants, $variantfallbacks,
00132                                                                 array(),
00133                                                                 $ml );
00134 
00135                 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
00136         }
00137 
00144         function segmentForDiff( $text ) {
00145                 return preg_replace(
00146                         "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00147                         "' ' .\"$1\"", $text );
00148         }
00149 
00154         function unsegmentForDiff( $text ) {
00155                 return preg_replace(
00156                         "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00157                         "\"$1\"", $text );
00158         }
00159 
00167         function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
00168                 wfProfileIn( __METHOD__ );
00169 
00170                 // always convert to zh-hans before indexing. it should be
00171                 // better to use zh-hans for search, since conversion from
00172                 // Traditional to Simplified is less ambiguous than the
00173                 // other way around
00174                 $s = $this->mConverter->autoConvert( $string, $autoVariant );
00175                 // LanguageZh_hans::normalizeForSearch
00176                 $s = parent::normalizeForSearch( $s );
00177                 wfProfileOut( __METHOD__ );
00178                 return $s;
00179 
00180         }
00181 
00186         function convertForSearchResult( $termsArray ) {
00187                 $terms = implode( '|', $termsArray );
00188                 $terms = self::convertDoubleWidth( $terms );
00189                 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
00190                 $ret = array_unique( explode( '|', $terms ) );
00191                 return $ret;
00192         }
00193 }
00194