no need to mark latin text in Chinese conversion
[lhc/web/wiklou.git] / languages / LanguageZh.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Language
5 */
6 require_once( "LanguageConverter.php" );
7 require_once( "LanguageZh_cn.php");
8 require_once( "LanguageZh_tw.php");
9 require_once( "LanguageZh_sg.php");
10 require_once( "LanguageZh_hk.php");
11
12 class ZhConverter extends LanguageConverter {
13 function loadDefaultTables() {
14 require( "includes/ZhConversion.php" );
15 $this->mTables = array();
16 $this->mTables['zh-cn'] = $zh2CN;
17 $this->mTables['zh-tw'] = $zh2TW;
18 $this->mTables['zh-sg'] = array_merge($zh2CN, $zh2SG);
19 $this->mTables['zh-hk'] = array_merge($zh2TW, $zh2HK);
20 $this->mTables['zh'] = array();
21 }
22
23 function postLoadTables() {
24 $this->mTables['zh-sg'] = array_merge($this->mTables['zh-cn'], $this->mTables['zh-sg']);
25 $this->mTables['zh-hk'] = array_merge($this->mTables['zh-tw'], $this->mTables['zh-hk']);
26 }
27
28 /* there shouldn't be any latin text in Chinese conversion, so no need
29 to mark anything
30 */
31 function markNoConversion($text) {
32 return $text;
33 }
34 }
35
36
37 /* class that handles both Traditional and Simplified Chinese
38 right now it only distinguish zh_cn, zh_tw, zh_sg and zh_hk.
39 */
40 class LanguageZh extends LanguageZh_cn {
41
42 function LanguageZh() {
43 global $wgHooks;
44 $this->mConverter = new ZhConverter($this, 'zh',
45 array('zh', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk'),
46 array('zh'=>'zh-cn',
47 'zh-cn'=>'zh-sg',
48 'zh-sg'=>'zh-cn',
49 'zh-tw'=>'zh-hk',
50 'zh-hk'=>'zh-tw'));
51 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
52 }
53
54
55 # this should give much better diff info
56 function segmentForDiff( $text ) {
57 return preg_replace(
58 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
59 "' ' .\"$1\"", $text);
60 }
61
62 function unsegmentForDiff( $text ) {
63 return preg_replace(
64 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
65 "\"$1\"", $text);
66 }
67
68 // word segmentation
69 function stripForSearch( $string ) {
70 $fname="LanguageZh::stripForSearch";
71 wfProfileIn( $fname );
72
73 // eventually this should be a word segmentation
74 // for now just treat each character as a word
75 $t = preg_replace(
76 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
77 "' ' .\"$1\"", $string);
78
79 //always convert to zh-cn before indexing. it should be
80 //better to use zh-cn for search, since conversion from
81 //Traditional to Simplified is less ambiguous than the
82 //other way around
83
84 $t = $this->mConverter->autoConvert($t, 'zh-cn');
85 $t = LanguageUtf8::stripForSearch( $t );
86 wfProfileOut( $fname );
87 return $t;
88
89 }
90
91 function convertForSearchResult( $termsArray ) {
92 $terms = implode( '|', $termsArray );
93 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
94 $ret = array_unique( explode('|', $terms) );
95 return $ret;
96 }
97
98 }
99 ?>