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 $markup=array(),
00015 $flags = array(),
00016 $manualLevel = array() ) {
00017 $this->mDescCodeSep = ':';
00018 $this->mDescVarSep = ';';
00019 parent::__construct($langobj, $maincode,
00020 $variants,
00021 $variantfallbacks,
00022 $markup,
00023 $flags,
00024 $manualLevel);
00025 $names = array(
00026 'zh' => '原文',
00027 'zh-hans' => '简体',
00028 'zh-hant' => '繁體',
00029 'zh-cn' => '大陆',
00030 'zh-tw' => '台灣',
00031 'zh-hk' => '香港',
00032 'zh-mo' => '澳門',
00033 'zh-sg' => '新加坡',
00034 'zh-my' => '大马',
00035 );
00036 $this->mVariantNames = array_merge($this->mVariantNames,$names);
00037 $this->loadNamespaceTables();
00038 }
00039
00040 function loadNamespaceTables() {
00041 global $wgMetaNamespace;
00042 $nsproject = $wgMetaNamespace;
00043 $projecttable = array(
00044 'Wikipedia' => '维基百科',
00045 'Wikisource' => '维基文库',
00046 'Wikinews' => '维基新闻',
00047 'Wiktionary' => '维基词典',
00048 'Wikibooks' => '维基教科书',
00049 'Wikiquote' => '维基语录',
00050 );
00051 $this->mNamespaceTables['zh-hans'] = array(
00052 'Media' => '媒体',
00053 'Special' => '特殊',
00054 'Talk' => '讨论',
00055 'User' => '用户',
00056 'User talk' => '用户讨论',
00057 $nsproject
00058 => isset($projecttable[$nsproject]) ?
00059 $projecttable[$nsproject] : $nsproject,
00060 $nsproject . ' talk'
00061 => isset($projecttable[$nsproject]) ?
00062 $projecttable[$nsproject] . '讨论' : $nsproject . '讨论',
00063 'File' => '文件',
00064 'File talk' => '文件讨论',
00065 'MediaWiki' => 'MediaWiki',
00066 'MediaWiki talk' => 'MediaWiki讨论',
00067 'Template' => '模板',
00068 'Template talk' => '模板讨论',
00069 'Help' => '帮助',
00070 'Help talk' => '帮助讨论',
00071 'Category' => '分类',
00072 'Category talk' => '分类讨论',
00073 );
00074 $this->mNamespaceTables['zh-hant'] = array_merge($this->mNamespaceTables['zh-hans']);
00075 $this->mNamespaceTables['zh-hant']['File'] = '檔案';
00076 $this->mNamespaceTables['zh-hant']['File talk'] = '檔案討論';
00077 $this->mNamespaceTables['zh'] = array_merge($this->mNamespaceTables['zh-hans']);
00078 $this->mNamespaceTables['zh-cn'] = array_merge($this->mNamespaceTables['zh-hans']);
00079 $this->mNamespaceTables['zh-hk'] = array_merge($this->mNamespaceTables['zh-hant']);
00080 $this->mNamespaceTables['zh-mo'] = array_merge($this->mNamespaceTables['zh-hant']);
00081 $this->mNamespaceTables['zh-my'] = array_merge($this->mNamespaceTables['zh-hans']);
00082 $this->mNamespaceTables['zh-sg'] = array_merge($this->mNamespaceTables['zh-hans']);
00083 $this->mNamespaceTables['zh-tw'] = array_merge($this->mNamespaceTables['zh-hant']);
00084 }
00085
00086 function loadDefaultTables() {
00087 require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
00088 $this->mTables = array(
00089 'zh-hans' => new ReplacementArray( $zh2Hans ),
00090 'zh-hant' => new ReplacementArray( $zh2Hant ),
00091 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
00092 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
00093 'zh-mo' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
00094 'zh-my' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
00095 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
00096 'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
00097 'zh' => new ReplacementArray
00098 );
00099 }
00100
00101 function postLoadTables() {
00102 $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
00103 $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
00104 $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
00105 $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
00106 $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
00107 $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
00108 }
00109
00110
00111
00112
00113
00114 function markNoConversion($text, $noParse = false) {
00115 return $text;
00116 }
00117
00118 function convertCategoryKey( $key ) {
00119 return $this->autoConvert( $key, 'zh' );
00120 }
00121 }
00122
00129 class LanguageZh extends LanguageZh_hans {
00130
00131 function __construct() {
00132 global $wgHooks;
00133 parent::__construct();
00134
00135 $variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
00136 $variantfallbacks = array(
00137 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
00138 'zh-hans' => array('zh-cn','zh-sg','zh-my'),
00139 'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
00140 'zh-cn' => array('zh-hans','zh-sg','zh-my'),
00141 'zh-sg' => array('zh-hans','zh-cn','zh-my'),
00142 'zh-my' => array('zh-hans','zh-sg','zh-cn'),
00143 'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
00144 'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
00145 'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
00146 );
00147 $ml=array(
00148 'zh' => 'disable',
00149 'zh-hans' => 'unidirectional',
00150 'zh-hant' => 'unidirectional',
00151 );
00152
00153 $this->mConverter = new ZhConverter( $this, 'zh',
00154 $variants, $variantfallbacks,
00155 array(),array(),
00156 $ml);
00157
00158 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
00159 }
00160
00161 # this should give much better diff info
00162 function segmentForDiff( $text ) {
00163 return preg_replace(
00164 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00165 "' ' .\"$1\"", $text);
00166 }
00167
00168 function unsegmentForDiff( $text ) {
00169 return preg_replace(
00170 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00171 "\"$1\"", $text);
00172 }
00173
00174
00175 function stripForSearch( $string ) {
00176 wfProfileIn( __METHOD__ );
00177
00178
00179
00180
00181 $t = preg_replace(
00182 "/([\\xc0-\\xff][\\x80-\\xbf]*)/",
00183 " $1", $string);
00184
00185
00186
00187
00188
00189
00190 $t = $this->mConverter->autoConvert($t, 'zh-hans');
00191 $t = parent::stripForSearch( $t );
00192 wfProfileOut( __METHOD__ );
00193 return $t;
00194
00195 }
00196
00197 function convertForSearchResult( $termsArray ) {
00198 $terms = implode( '|', $termsArray );
00199 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
00200 $ret = array_unique( explode('|', $terms) );
00201 return $ret;
00202 }
00203 }
00204