6 require_once( dirname(__FILE__
).'/LanguageConverter.php' );
7 require_once( dirname(__FILE__
).'/LanguageZh_cn.php' );
9 class ZhConverter
extends LanguageConverter
{
10 function loadDefaultTables() {
11 require( "includes/ZhConversion.php" );
12 $this->mTables
= array();
13 $this->mTables
['zh-cn'] = $zh2CN;
14 $this->mTables
['zh-tw'] = $zh2TW;
15 $this->mTables
['zh-sg'] = array_merge($zh2CN, $zh2SG);
16 $this->mTables
['zh-hk'] = array_merge($zh2TW, $zh2HK);
17 $this->mTables
['zh'] = array();
20 function postLoadTables() {
21 $this->mTables
['zh-sg'] = array_merge($this->mTables
['zh-cn'], $this->mTables
['zh-sg']);
22 $this->mTables
['zh-hk'] = array_merge($this->mTables
['zh-tw'], $this->mTables
['zh-hk']);
25 /* there shouldn't be any latin text in Chinese conversion, so no need
28 function markNoConversion($text) {
32 function convertCategoryKey( $key ) {
33 return $this->autoConvert( $key, 'zh-cn' );
38 /* class that handles both Traditional and Simplified Chinese
39 right now it only distinguish zh_cn, zh_tw, zh_sg and zh_hk.
41 class LanguageZh
extends LanguageZh_cn
{
43 function __construct() {
45 parent
::__construct();
46 $this->mConverter
= new ZhConverter($this, 'zh',
47 array('zh', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk'),
53 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
57 # this should give much better diff info
58 function segmentForDiff( $text ) {
60 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
61 "' ' .\"$1\"", $text);
64 function unsegmentForDiff( $text ) {
66 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
71 function stripForSearch( $string ) {
72 $fname="LanguageZh::stripForSearch";
73 wfProfileIn( $fname );
75 // eventually this should be a word segmentation
76 // for now just treat each character as a word
78 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
79 "' ' .\"$1\"", $string);
81 //always convert to zh-cn before indexing. it should be
82 //better to use zh-cn for search, since conversion from
83 //Traditional to Simplified is less ambiguous than the
86 $t = $this->mConverter
->autoConvert($t, 'zh-cn');
87 $t = parent
::stripForSearch( $t );
88 wfProfileOut( $fname );
93 function convertForSearchResult( $termsArray ) {
94 $terms = implode( '|', $termsArray );
95 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
96 $ret = array_unique( explode('|', $terms) );