242fea2f83e601cc9b0879649baab5d4927fd1d5
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($zh2Hant, $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' );
42 /* class that handles both Traditional and Simplified Chinese
43 right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
45 class LanguageZh
extends LanguageZh_hans
{
47 function __construct() {
49 parent
::__construct();
51 $variants = array('zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk');
52 $variantfallbacks = array(
62 $this->mConverter
= new ZhConverter( $this, 'zh', $variants, $variantfallbacks );
64 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
67 # this should give much better diff info
68 function segmentForDiff( $text ) {
70 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
71 "' ' .\"$1\"", $text);
74 function unsegmentForDiff( $text ) {
76 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
81 function stripForSearch( $string ) {
82 $fname="LanguageZh::stripForSearch";
83 wfProfileIn( $fname );
85 // eventually this should be a word segmentation
86 // for now just treat each character as a word
88 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
89 "' ' .\"$1\"", $string);
91 //always convert to zh-hans before indexing. it should be
92 //better to use zh-hans for search, since conversion from
93 //Traditional to Simplified is less ambiguous than the
96 $t = $this->mConverter
->autoConvert($t, 'zh-hans');
97 $t = parent
::stripForSearch( $t );
98 wfProfileOut( $fname );
103 function convertForSearchResult( $termsArray ) {
104 $terms = implode( '|', $termsArray );
105 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
106 $ret = array_unique( explode('|', $terms) );