3 require_once( dirname(__FILE__
).'/../LanguageConverter.php' );
4 require_once( dirname(__FILE__
).'/LanguageZh_hans.php' );
9 class ZhConverter
extends LanguageConverter
{
10 function loadDefaultTables() {
11 require( dirname(__FILE__
)."/../../includes/ZhConversion.php" );
12 $this->mTables
= array(
13 'zh-hans' => new ReplacementArray( $zh2Hans ),
14 'zh-hant' => new ReplacementArray( $zh2Hant ),
15 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
16 'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
17 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
18 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
19 'zh' => new ReplacementArray
23 function postLoadTables() {
24 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
25 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
26 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
27 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
30 /* there shouldn't be any latin text in Chinese conversion, so no need
32 $noParse is there for compatibility with LanguageConvert::markNoConversion
34 function markNoConversion($text, $noParse = false) {
38 function convertCategoryKey( $key ) {
39 return $this->autoConvert( $key, 'zh' );
44 * class that handles both Traditional and Simplified Chinese
45 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
49 class LanguageZh
extends LanguageZh_hans
{
51 function __construct() {
53 parent
::__construct();
55 $variants = array('zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk');
56 $variantfallbacks = array(
66 $this->mConverter
= new ZhConverter( $this, 'zh', $variants, $variantfallbacks );
68 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
71 # this should give much better diff info
72 function segmentForDiff( $text ) {
74 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
75 "' ' .\"$1\"", $text);
78 function unsegmentForDiff( $text ) {
80 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
85 function stripForSearch( $string ) {
86 $fname="LanguageZh::stripForSearch";
87 wfProfileIn( $fname );
89 // eventually this should be a word segmentation
90 // for now just treat each character as a word
92 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
93 "' ' .\"$1\"", $string);
95 //always convert to zh-hans before indexing. it should be
96 //better to use zh-hans for search, since conversion from
97 //Traditional to Simplified is less ambiguous than the
100 $t = $this->mConverter
->autoConvert($t, 'zh-hans');
101 $t = parent
::stripForSearch( $t );
102 wfProfileOut( $fname );
107 function convertForSearchResult( $termsArray ) {
108 $terms = implode( '|', $termsArray );
109 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
110 $ret = array_unique( explode('|', $terms) );