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(),
15 $manualLevel = array() ) {
16 $this->mDescCodeSep
= ':';
17 $this->mDescVarSep
= ';';
18 parent
::__construct($langobj, $maincode,
34 $this->mVariantNames
= array_merge($this->mVariantNames
,$names);
35 $this->loadNamespaceTables();
38 function loadNamespaceTables() {
39 global $wgMetaNamespace;
40 $nsproject = $wgMetaNamespace;
41 $projecttable = array(
42 'Wikipedia' => '维基百科',
43 'Wikisource' => '维基文库',
45 'Wiktionary' => '维基词典',
46 'Wikibooks' => '维基教科书',
47 'Wikiquote' => '维基语录',
49 $this->mNamespaceTables
['zh-hans'] = array(
54 'User talk' => '用户讨论',
56 => isset($projecttable[$nsproject]) ?
57 $projecttable[$nsproject] : $nsproject,
59 => isset($projecttable[$nsproject]) ?
60 $projecttable[$nsproject] . '讨论' : $nsproject . '讨论',
62 'File talk' => '文件讨论',
63 'MediaWiki' => 'MediaWiki',
64 'MediaWiki talk' => 'MediaWiki讨论',
66 'Template talk' => '模板讨论',
68 'Help talk' => '帮助讨论',
70 'Category talk' => '分类讨论',
72 $this->mNamespaceTables
['zh-hant'] = array_merge($this->mNamespaceTables
['zh-hans']);
73 $this->mNamespaceTables
['zh-hant']['File'] = '檔案';
74 $this->mNamespaceTables
['zh-hant']['File talk'] = '檔案討論';
75 $this->mNamespaceTables
['zh'] = array_merge($this->mNamespaceTables
['zh-hans']);
76 $this->mNamespaceTables
['zh-cn'] = array_merge($this->mNamespaceTables
['zh-hans']);
77 $this->mNamespaceTables
['zh-hk'] = array_merge($this->mNamespaceTables
['zh-hant']);
78 $this->mNamespaceTables
['zh-mo'] = array_merge($this->mNamespaceTables
['zh-hant']);
79 $this->mNamespaceTables
['zh-my'] = array_merge($this->mNamespaceTables
['zh-hans']);
80 $this->mNamespaceTables
['zh-sg'] = array_merge($this->mNamespaceTables
['zh-hans']);
81 $this->mNamespaceTables
['zh-tw'] = array_merge($this->mNamespaceTables
['zh-hant']);
84 function loadDefaultTables() {
85 require( dirname(__FILE__
)."/../../includes/ZhConversion.php" );
86 $this->mTables
= array(
87 'zh-hans' => new ReplacementArray( $zh2Hans ),
88 'zh-hant' => new ReplacementArray( $zh2Hant ),
89 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
90 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
91 'zh-mo' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
92 'zh-my' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
93 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
94 'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
95 'zh' => new ReplacementArray
99 function postLoadTables() {
100 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
101 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
102 $this->mTables
['zh-mo']->merge( $this->mTables
['zh-hant'] );
103 $this->mTables
['zh-my']->merge( $this->mTables
['zh-hans'] );
104 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
105 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
108 /* there shouldn't be any latin text in Chinese conversion, so no need
110 $noParse is there for compatibility with LanguageConvert::markNoConversion
112 function markNoConversion($text, $noParse = false) {
116 function convertCategoryKey( $key ) {
117 return $this->autoConvert( $key, 'zh' );
122 * class that handles both Traditional and Simplified Chinese
123 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
127 class LanguageZh
extends LanguageZh_hans
{
129 function __construct() {
131 parent
::__construct();
133 $variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
135 $variantfallbacks = array(
136 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
137 'zh-hans' => array('zh-cn','zh-sg','zh-my'),
138 'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
139 'zh-cn' => array('zh-hans','zh-sg','zh-my'),
140 'zh-sg' => array('zh-hans','zh-cn','zh-my'),
141 'zh-my' => array('zh-hans','zh-sg','zh-cn'),
142 'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
143 'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
144 'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
148 'zh-hans' => 'unidirectional',
149 'zh-hant' => 'unidirectional',
152 $this->mConverter
= new ZhConverter( $this, 'zh',
153 $variants, $variantfallbacks,
157 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
160 # this should give much better diff info
161 function segmentForDiff( $text ) {
163 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
164 "' ' .\"$1\"", $text);
167 function unsegmentForDiff( $text ) {
169 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
174 * auto convert to zh-hans and normalize special characters.
176 * @param $string String
177 * @param $autoVariant String, default to 'zh-hans'
180 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
181 wfProfileIn( __METHOD__
);
183 // always convert to zh-hans before indexing. it should be
184 // better to use zh-hans for search, since conversion from
185 // Traditional to Simplified is less ambiguous than the
187 $s = $this->mConverter
->autoConvert( $string, $autoVariant );
188 // LanguageZh_hans::normalizeForSearch
189 $s = parent
::normalizeForSearch( $s );
190 wfProfileOut( __METHOD__
);
195 function convertForSearchResult( $termsArray ) {
196 $terms = implode( '|', $termsArray );
197 $terms = self
::convertDoubleWidth( $terms );
198 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
199 $ret = array_unique( explode('|', $terms) );