fixing zh-TW array to merging with zh-Hant instead of zh-Hans
[lhc/web/wiklou.git] / languages / classes / LanguageZh.php
1 <?php
2 /**
3 * @addtogroup Language
4 */
5 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
6 require_once( dirname(__FILE__).'/LanguageZh_hans.php' );
7
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
19 );
20 }
21
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'] );
27 }
28
29 /* there shouldn't be any latin text in Chinese conversion, so no need
30 to mark anything.
31 $noParse is there for compatibility with LanguageConvert::markNoConversion
32 */
33 function markNoConversion($text, $noParse = false) {
34 return $text;
35 }
36
37 function convertCategoryKey( $key ) {
38 return $this->autoConvert( $key, 'zh' );
39 }
40 }
41
42
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.
45 */
46 class LanguageZh extends LanguageZh_hans {
47
48 function __construct() {
49 global $wgHooks;
50 parent::__construct();
51
52 $variants = array('zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk');
53 $variantfallbacks = array(
54 'zh' => 'zh-hans',
55 'zh-hans' => 'zh-cn',
56 'zh-hant' => 'zh-tw',
57 'zh-cn' => 'zh-hans',
58 'zh-sg' => 'zh-hans',
59 'zh-tw' => 'zh-hant',
60 'zh-hk' => 'zh-hant'
61 );
62
63 $this->mConverter = new ZhConverter( $this, 'zh', $variants, $variantfallbacks );
64
65 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
66 }
67
68
69 # this should give much better diff info
70 function segmentForDiff( $text ) {
71 return preg_replace(
72 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
73 "' ' .\"$1\"", $text);
74 }
75
76 function unsegmentForDiff( $text ) {
77 return preg_replace(
78 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
79 "\"$1\"", $text);
80 }
81
82 // word segmentation
83 function stripForSearch( $string ) {
84 $fname="LanguageZh::stripForSearch";
85 wfProfileIn( $fname );
86
87 // eventually this should be a word segmentation
88 // for now just treat each character as a word
89 $t = preg_replace(
90 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
91 "' ' .\"$1\"", $string);
92
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
96 //other way around
97
98 $t = $this->mConverter->autoConvert($t, 'zh-hans');
99 $t = parent::stripForSearch( $t );
100 wfProfileOut( $fname );
101 return $t;
102
103 }
104
105 function convertForSearchResult( $termsArray ) {
106 $terms = implode( '|', $termsArray );
107 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
108 $ret = array_unique( explode('|', $terms) );
109 return $ret;
110 }
111
112 }