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 parent
::__construct($langobj, $maincode,
34 $this->mVariantNames
= array_merge($this->mVariantNames
,$names);
37 function loadDefaultTables() {
38 require( dirname(__FILE__
)."/../../includes/ZhConversion.php" );
39 $this->mTables
= array(
40 'zh-hans' => new ReplacementArray( $zh2Hans ),
41 'zh-hant' => new ReplacementArray( $zh2Hant ),
42 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
43 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
44 'zh-mo' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
45 'zh-my' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
46 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
47 'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
48 'zh' => new ReplacementArray
52 function postLoadTables() {
53 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
54 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
55 $this->mTables
['zh-mo']->merge( $this->mTables
['zh-hant'] );
56 $this->mTables
['zh-my']->merge( $this->mTables
['zh-hans'] );
57 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
58 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
61 /* there shouldn't be any latin text in Chinese conversion, so no need
63 $noParse is there for compatibility with LanguageConvert::markNoConversion
65 function markNoConversion($text, $noParse = false) {
69 /* description of convert code in chinese language*/
70 function getRulesDesc($bidtable,$unidtable){
71 $text=parent
::getRulesDesc($bidtable,$unidtable);
72 $text=str_replace(':','\81F',$text);
73 $text=str_replace(';','\81G',$text);
77 function convertCategoryKey( $key ) {
78 return $this->autoConvert( $key, 'zh' );
83 * class that handles both Traditional and Simplified Chinese
84 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
88 class LanguageZh
extends LanguageZh_hans
{
90 function __construct() {
92 parent
::__construct();
94 $variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
95 $variantfallbacks = array(
96 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
97 'zh-hans' => array('zh-cn','zh-sg','zh-my'),
98 'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
99 'zh-cn' => array('zh-hans','zh-sg','zh-my'),
100 'zh-sg' => array('zh-hans','zh-cn','zh-my'),
101 'zh-my' => array('zh-hant','zh-sg','zh-cn'),
102 'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
103 'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
104 'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
108 'zh-hans' => 'unidirectional',
109 'zh-hant' => 'unidirectional',
112 $this->mConverter
= new ZhConverter( $this, 'zh',
113 $variants, $variantfallbacks,
117 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
120 # this should give much better diff info
121 function segmentForDiff( $text ) {
123 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
124 "' ' .\"$1\"", $text);
127 function unsegmentForDiff( $text ) {
129 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
134 function stripForSearch( $string ) {
135 $fname="LanguageZh::stripForSearch";
136 wfProfileIn( $fname );
138 // eventually this should be a word segmentation
139 // for now just treat each character as a word
141 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
142 "' ' .\"$1\"", $string);
144 //always convert to zh-hans before indexing. it should be
145 //better to use zh-hans for search, since conversion from
146 //Traditional to Simplified is less ambiguous than the
149 $t = $this->mConverter
->autoConvert($t, 'zh-hans');
150 $t = parent
::stripForSearch( $t );
151 wfProfileOut( $fname );
156 function convertForSearchResult( $termsArray ) {
157 $terms = implode( '|', $termsArray );
158 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
159 $ret = array_unique( explode('|', $terms) );