Adding 'wantedpages-summary' it to $wgOptionalMessages as well.
[mediawiki.git] / languages / classes / LanguageZh.php
blobff3679885086315af46517b5c98059a36671fff4
1 <?php
3 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
4 require_once( dirname(__FILE__).'/LanguageZh_hans.php' );
6 /**
7 * @ingroup Language
8 */
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
31 to mark anything.
32 $noParse is there for compatibility with LanguageConvert::markNoConversion
34 function markNoConversion($text, $noParse = false) {
35 return $text;
38 function convertCategoryKey( $key ) {
39 return $this->autoConvert( $key, 'zh' );
43 /**
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.
47 * @ingroup Language
49 class LanguageZh extends LanguageZh_hans {
51 function __construct() {
52 global $wgHooks;
53 parent::__construct();
55 $variants = array('zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk');
56 $variantfallbacks = array(
57 'zh' => 'zh-hans',
58 'zh-hans' => 'zh',
59 'zh-hant' => 'zh',
60 'zh-cn' => 'zh-hans',
61 'zh-sg' => 'zh-hans',
62 'zh-tw' => 'zh-hant',
63 'zh-hk' => 'zh-hant',
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 ) {
73 return preg_replace(
74 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
75 "' ' .\"$1\"", $text);
78 function unsegmentForDiff( $text ) {
79 return preg_replace(
80 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
81 "\"$1\"", $text);
84 // word segmentation
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
91 $t = preg_replace(
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
98 //other way around
100 $t = $this->mConverter->autoConvert($t, 'zh-hans');
101 $t = parent::stripForSearch( $t );
102 wfProfileOut( $fname );
103 return $t;
107 function convertForSearchResult( $termsArray ) {
108 $terms = implode( '|', $termsArray );
109 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
110 $ret = array_unique( explode('|', $terms) );
111 return $ret;