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 = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
137 $variantfallbacks = array(
138 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
139 'zh-hans' => array('zh-cn','zh-sg','zh-my'),
140 'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
141 'zh-cn' => array('zh-hans','zh-sg','zh-my'),
142 'zh-sg' => array('zh-hans','zh-cn','zh-my'),
143 'zh-my' => array('zh-hans','zh-sg','zh-cn'),
144 'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
145 'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
146 'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
150 'zh-hans' => 'unidirectional',
151 'zh-hant' => 'unidirectional',
154 $this->mConverter
= new ZhConverter( $this, 'zh',
155 $variants, $variantfallbacks,
159 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
162 # this should give much better diff info
163 function segmentForDiff( $text ) {
165 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
166 "' ' .\"$1\"", $text);
169 function unsegmentForDiff( $text ) {
171 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
176 function stripForSearch( $string ) {
177 wfProfileIn( __METHOD__
);
179 //always convert to zh-hans before indexing. it should be
180 //better to use zh-hans for search, since conversion from
181 //Traditional to Simplified is less ambiguous than the
184 $t = $this->mConverter
->autoConvert( $string, 'zh-hans' );
185 $t = parent
::stripForSearch( $t );
186 wfProfileOut( __METHOD__
);
191 function convertForSearchResult( $termsArray ) {
192 $terms = implode( '|', $termsArray );
193 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
194 $ret = array_unique( explode('|', $terms) );