0ba1ad91345aba7757789897c0be3c13cb807c40
3 $dir = dirname(__FILE__
) . '/';
4 require_once( $dir . '../LanguageConverter.php' );
5 require_once( $dir . 'LanguageZh_hans.php' );
10 class ZhConverter
extends LanguageConverter
{
12 function __construct($langobj, $maincode,
14 $variantfallbacks=array(),
17 $manualLevel = array() ) {
18 $this->mDescCodeSep
= ':';
19 $this->mDescVarSep
= ';';
20 parent
::__construct($langobj, $maincode,
37 $this->mVariantNames
= array_merge($this->mVariantNames
,$names);
40 function loadDefaultTables() {
41 require( dirname(__FILE__
)."/../../includes/ZhConversion.php" );
42 $this->mTables
= array(
43 'zh-hans' => new ReplacementArray( $zh2Hans ),
44 'zh-hant' => new ReplacementArray( $zh2Hant ),
45 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
46 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
47 'zh-mo' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
48 'zh-my' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
49 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
50 'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
51 'zh' => new ReplacementArray
55 function postLoadTables() {
56 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
57 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
58 $this->mTables
['zh-mo']->merge( $this->mTables
['zh-hant'] );
59 $this->mTables
['zh-my']->merge( $this->mTables
['zh-hans'] );
60 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
61 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
64 /* there shouldn't be any latin text in Chinese conversion, so no need
66 $noParse is there for compatibility with LanguageConvert::markNoConversion
68 function markNoConversion($text, $noParse = false) {
72 function convertCategoryKey( $key ) {
73 return $this->autoConvert( $key, 'zh' );
78 * class that handles both Traditional and Simplified Chinese
79 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
83 class LanguageZh
extends LanguageZh_hans
{
85 function __construct() {
87 parent
::__construct();
89 $variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
90 $variantfallbacks = array(
91 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
92 'zh-hans' => array('zh-cn','zh-sg','zh-my'),
93 'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
94 'zh-cn' => array('zh-hans','zh-sg','zh-my'),
95 'zh-sg' => array('zh-hans','zh-cn','zh-my'),
96 'zh-my' => array('zh-hans','zh-sg','zh-cn'),
97 'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
98 'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
99 'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
103 'zh-hans' => 'unidirectional',
104 'zh-hant' => 'unidirectional',
107 $this->mConverter
= new ZhConverter( $this, 'zh',
108 $variants, $variantfallbacks,
112 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
115 # this should give much better diff info
116 function segmentForDiff( $text ) {
118 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
119 "' ' .\"$1\"", $text);
122 function unsegmentForDiff( $text ) {
124 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
129 function stripForSearch( $string ) {
130 wfProfileIn( __METHOD__
);
132 // eventually this should be a word segmentation
133 // for now just treat each character as a word
134 // @fixme only do this for Han characters...
136 "/([\\xc0-\\xff][\\x80-\\xbf]*)/",
139 //always convert to zh-hans before indexing. it should be
140 //better to use zh-hans for search, since conversion from
141 //Traditional to Simplified is less ambiguous than the
144 $t = $this->mConverter
->autoConvert($t, 'zh-hans');
145 $t = parent
::stripForSearch( $t );
146 wfProfileOut( __METHOD__
);
151 function convertForSearchResult( $termsArray ) {
152 $terms = implode( '|', $termsArray );
153 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
154 $ret = array_unique( explode('|', $terms) );