6 require_once( "LanguageConverter.php" );
7 require_once( "LanguageZh_cn.php");
8 require_once( "LanguageZh_tw.php");
9 require_once( "LanguageZh_sg.php");
10 require_once( "LanguageZh_hk.php");
12 class ZhConverter
extends LanguageConverter
{
13 function loadDefaultTables() {
14 require( "includes/ZhConversion.php" );
15 $this->mTables
= array();
16 $this->mTables
['zh-cn'] = $zh2CN;
17 $this->mTables
['zh-tw'] = $zh2TW;
18 $this->mTables
['zh-sg'] = array_merge($zh2CN, $zh2SG);
19 $this->mTables
['zh-hk'] = array_merge($zh2TW, $zh2HK);
20 $this->mTables
['zh'] = array();
23 function postLoadTables() {
24 $this->mTables
['zh-sg'] = array_merge($this->mTables
['zh-cn'], $this->mTables
['zh-sg']);
25 $this->mTables
['zh-hk'] = array_merge($this->mTables
['zh-tw'], $this->mTables
['zh-hk']);
30 /* class that handles both Traditional and Simplified Chinese
31 right now it only distinguish zh_cn, zh_tw, zh_sg and zh_hk.
33 class LanguageZh
extends LanguageZh_cn
{
35 function LanguageZh() {
37 $this->mConverter
= new ZhConverter($this, 'zh',
38 array('zh', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk'),
44 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
48 # this should give much better diff info
49 function segmentForDiff( $text ) {
51 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
52 "' ' .\"$1\"", $text);
55 function unsegmentForDiff( $text ) {
57 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
62 function stripForSearch( $string ) {
63 $fname="LanguageZh::stripForSearch";
64 wfProfileIn( $fname );
66 // eventually this should be a word segmentation
67 // for now just treat each character as a word
69 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
70 "' ' .\"$1\"", $string);
72 //always convert to zh-cn before indexing. it should be
73 //better to use zh-cn for search, since conversion from
74 //Traditional to Simplified is less ambiguous than the
77 $t = $this->mConverter
->autoConvert($t, 'zh-cn');
78 $t = LanguageUtf8
::stripForSearch( $t );
79 wfProfileOut( $fname );
84 function convertForSearchResult( $termsArray ) {
85 $terms = implode( '|', $termsArray );
86 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
87 $ret = array_unique( explode('|', $terms) );