00001 <?php
00002
00003 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
00004 require_once( dirname(__FILE__).'/LanguageZh_hans.php' );
00005
00009 class ZhConverter extends LanguageConverter {
00010
00011 function __construct($langobj, $maincode,
00012 $variants=array(),
00013 $variantfallbacks=array(),
00014 $flags = array(),
00015 $manualLevel = array() ) {
00016 $this->mDescCodeSep = ':';
00017 $this->mDescVarSep = ';';
00018 parent::__construct($langobj, $maincode,
00019 $variants,
00020 $variantfallbacks,
00021 $flags,
00022 $manualLevel);
00023 $names = array(
00024 'zh' => '原文',
00025 'zh-hans' => '简体',
00026 'zh-hant' => '繁體',
00027 'zh-cn' => '大陆',
00028 'zh-tw' => '台灣',
00029 'zh-hk' => '香港',
00030 'zh-mo' => '澳門',
00031 'zh-sg' => '新加坡',
00032 'zh-my' => '大马',
00033 );
00034 $this->mVariantNames = array_merge($this->mVariantNames,$names);
00035 }
00036
00037 function loadDefaultTables() {
00038 require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
00039 $this->mTables = array(
00040 'zh-hans' => new ReplacementArray( $zh2Hans ),
00041 'zh-hant' => new ReplacementArray( $zh2Hant ),
00042 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
00043 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
00044 'zh-mo' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
00045 'zh-my' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
00046 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
00047 'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
00048 'zh' => new ReplacementArray
00049 );
00050 }
00051
00052 function postLoadTables() {
00053 $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
00054 $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
00055 $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
00056 $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
00057 $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
00058 $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
00059 }
00060
00061
00062
00063
00064
00065 function markNoConversion($text, $noParse = false) {
00066 return $text;
00067 }
00068
00069 function convertCategoryKey( $key ) {
00070 return $this->autoConvert( $key, 'zh' );
00071 }
00072 }
00073
00080 class LanguageZh extends LanguageZh_hans {
00081
00082 function __construct() {
00083 global $wgHooks;
00084 parent::__construct();
00085
00086 $variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
00087
00088 $variantfallbacks = array(
00089 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
00090 'zh-hans' => array('zh-cn','zh-sg','zh-my'),
00091 'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
00092 'zh-cn' => array('zh-hans','zh-sg','zh-my'),
00093 'zh-sg' => array('zh-hans','zh-cn','zh-my'),
00094 'zh-my' => array('zh-hans','zh-sg','zh-cn'),
00095 'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
00096 'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
00097 'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
00098 );
00099 $ml=array(
00100 'zh' => 'disable',
00101 'zh-hans' => 'unidirectional',
00102 'zh-hant' => 'unidirectional',
00103 );
00104
00105 $this->mConverter = new ZhConverter( $this, 'zh',
00106 $variants, $variantfallbacks,
00107 array(),
00108 $ml);
00109
00110 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
00111 }
00112
00113 # this should give much better diff info
00114 function segmentForDiff( $text ) {
00115 return preg_replace(
00116 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00117 "' ' .\"$1\"", $text);
00118 }
00119
00120 function unsegmentForDiff( $text ) {
00121 return preg_replace(
00122 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00123 "\"$1\"", $text);
00124 }
00125
00133 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
00134 wfProfileIn( __METHOD__ );
00135
00136
00137
00138
00139
00140 $s = $this->mConverter->autoConvert( $string, $autoVariant );
00141
00142 $s = parent::normalizeForSearch( $s );
00143 wfProfileOut( __METHOD__ );
00144 return $s;
00145
00146 }
00147
00148 function convertForSearchResult( $termsArray ) {
00149 $terms = implode( '|', $termsArray );
00150 $terms = self::convertDoubleWidth( $terms );
00151 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
00152 $ret = array_unique( explode('|', $terms) );
00153 return $ret;
00154 }
00155 }
00156