3 require_once( dirname(__FILE__
).'/../LanguageConverter.php' );
4 require_once( dirname(__FILE__
).'/LanguageZh_hans.php' );
9 class ZhConverter
extends LanguageConverter
{
11 function __construct($langobj, $maincode,
13 $variantfallbacks=array(),
16 $manualLevel = array() ) {
17 $this->mDescCodeSep
= ':';
18 $this->mDescVarSep
= ';';
19 parent
::__construct($langobj, $maincode,
36 $this->mVariantNames
= array_merge($this->mVariantNames
,$names);
37 $this->loadNamespaceTables();
40 function loadNamespaceTables() {
41 global $wgMetaNamespace;
42 $nsproject = $wgMetaNamespace;
43 $projecttable = array(
44 'Wikipedia' => '维基百科',
45 'Wikisource' => '维基文库',
47 'Wiktionary' => '维基词典',
48 'Wikibooks' => '维基教科书',
49 'Wikiquote' => '维基语录',
51 $this->mNamespaceTables
['zh-hans'] = array(
56 'User talk' => '用户讨论',
58 => isset($projecttable[$nsproject]) ?
59 $projecttable[$nsproject] : $nsproject,
61 => isset($projecttable[$nsproject]) ?
62 $projecttable[$nsproject] . '讨论' : $nsproject . '讨论',
64 'File talk' => '文件讨论',
65 'MediaWiki' => 'MediaWiki',
66 'MediaWiki talk' => 'MediaWiki讨论',
68 'Template talk' => '模板讨论',
70 'Help talk' => '帮助讨论',
72 'Category talk' => '分类讨论',
74 $this->mNamespaceTables
['zh-hant'] = array_merge($this->mNamespaceTables
['zh-hans']);
75 $this->mNamespaceTables
['zh-hant']['File'] = '檔案';
76 $this->mNamespaceTables
['zh-hant']['File talk'] = '檔案討論';
77 $this->mNamespaceTables
['zh'] = array_merge($this->mNamespaceTables
['zh-hans']);
78 $this->mNamespaceTables
['zh-cn'] = array_merge($this->mNamespaceTables
['zh-hans']);
79 $this->mNamespaceTables
['zh-hk'] = array_merge($this->mNamespaceTables
['zh-hant']);
80 $this->mNamespaceTables
['zh-mo'] = array_merge($this->mNamespaceTables
['zh-hant']);
81 $this->mNamespaceTables
['zh-my'] = array_merge($this->mNamespaceTables
['zh-hans']);
82 $this->mNamespaceTables
['zh-sg'] = array_merge($this->mNamespaceTables
['zh-hans']);
83 $this->mNamespaceTables
['zh-tw'] = array_merge($this->mNamespaceTables
['zh-hant']);
86 function loadDefaultTables() {
87 require( dirname(__FILE__
)."/../../includes/ZhConversion.php" );
88 $this->mTables
= array(
89 'zh-hans' => new ReplacementArray( $zh2Hans ),
90 'zh-hant' => new ReplacementArray( $zh2Hant ),
91 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
92 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
93 'zh-mo' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
94 'zh-my' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
95 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
96 'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
97 'zh' => new ReplacementArray
101 function postLoadTables() {
102 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
103 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
104 $this->mTables
['zh-mo']->merge( $this->mTables
['zh-hant'] );
105 $this->mTables
['zh-my']->merge( $this->mTables
['zh-hans'] );
106 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
107 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
110 /* there shouldn't be any latin text in Chinese conversion, so no need
112 $noParse is there for compatibility with LanguageConvert::markNoConversion
114 function markNoConversion($text, $noParse = false) {
118 function convertCategoryKey( $key ) {
119 return $this->autoConvert( $key, 'zh' );
124 * class that handles both Traditional and Simplified Chinese
125 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
129 class LanguageZh
extends LanguageZh_hans
{
131 function __construct() {
133 parent
::__construct();
135 $variants_all = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
138 // If a wiki disabled some variants,
139 // LanguageConverter shouldn't process them
140 foreach( $variants_all as $variant ) {
141 $status = wfMsgExt( "variantname-$variant", array( 'parsemag', 'language' => $this ) );
142 if( trim($status) != 'disable' )
143 $variants[] = $variant;
146 $variantfallbacks = array(
147 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
148 'zh-hans' => array('zh-cn','zh-sg','zh-my'),
149 'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
150 'zh-cn' => array('zh-hans','zh-sg','zh-my'),
151 'zh-sg' => array('zh-hans','zh-cn','zh-my'),
152 'zh-my' => array('zh-hans','zh-sg','zh-cn'),
153 'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
154 'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
155 'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
159 'zh-hans' => 'unidirectional',
160 'zh-hant' => 'unidirectional',
163 $this->mConverter
= new ZhConverter( $this, 'zh',
164 $variants, $variantfallbacks,
168 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
171 # this should give much better diff info
172 function segmentForDiff( $text ) {
174 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
175 "' ' .\"$1\"", $text);
178 function unsegmentForDiff( $text ) {
180 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
185 function stripForSearch( $string ) {
186 wfProfileIn( __METHOD__
);
188 //always convert to zh-hans before indexing. it should be
189 //better to use zh-hans for search, since conversion from
190 //Traditional to Simplified is less ambiguous than the
193 $t = $this->mConverter
->autoConvert( $string, 'zh-hans' );
194 $t = parent
::stripForSearch( $t );
195 wfProfileOut( __METHOD__
);
200 function convertForSearchResult( $termsArray ) {
201 $terms = implode( '|', $termsArray );
202 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
203 $ret = array_unique( explode('|', $terms) );