9209db8e80d4a4cacae48af1544df427d4dd3d17
5 require_once( dirname(__FILE__
).'/../LanguageConverter.php' );
6 require_once( dirname(__FILE__
).'/LanguageZh_hans.php' );
8 class ZhConverter
extends LanguageConverter
{
9 function loadDefaultTables() {
10 require( dirname(__FILE__
)."/../../includes/ZhConversion.php" );
11 $this->mTables
= array(
12 'zh-hans' => new ReplacementArray( $zh2Hans ),
13 'zh-hant' => new ReplacementArray( $zh2Hant ),
14 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
15 'zh-tw' => new ReplacementArray( array_merge($zh2Hans, $zh2TW) ),
16 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
17 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
18 'zh' => new ReplacementArray
22 function postLoadTables() {
23 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
24 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
25 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
26 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
29 /* there shouldn't be any latin text in Chinese conversion, so no need
31 $noParse is there for compatibility with LanguageConvert::markNoConversion
33 function markNoConversion($text, $noParse = false) {
37 function convertCategoryKey( $key ) {
38 return $this->autoConvert( $key, 'zh' );
43 /* class that handles both Traditional and Simplified Chinese
44 right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
46 class LanguageZh
extends LanguageZh_hans
{
48 function __construct() {
50 parent
::__construct();
52 $variants = array('zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk');
53 $variantfallbacks = array(
63 $this->mConverter
= new ZhConverter( $this, 'zh', $variants, $variantfallbacks );
65 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
69 # this should give much better diff info
70 function segmentForDiff( $text ) {
72 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
73 "' ' .\"$1\"", $text);
76 function unsegmentForDiff( $text ) {
78 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
83 function stripForSearch( $string ) {
84 $fname="LanguageZh::stripForSearch";
85 wfProfileIn( $fname );
87 // eventually this should be a word segmentation
88 // for now just treat each character as a word
90 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
91 "' ' .\"$1\"", $string);
93 //always convert to zh-hans before indexing. it should be
94 //better to use zh-hans for search, since conversion from
95 //Traditional to Simplified is less ambiguous than the
98 $t = $this->mConverter
->autoConvert($t, 'zh-hans');
99 $t = parent
::stripForSearch( $t );
100 wfProfileOut( $fname );
105 function convertForSearchResult( $termsArray ) {
106 $terms = implode( '|', $termsArray );
107 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
108 $ret = array_unique( explode('|', $terms) );