* (bug 5432) Fix inconsistencies in cookie names when using table prefixes
[mediawiki.git] / languages / LanguageZh.php
blobf2052eef6c18704be856e879d7cc7e78092a6962
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");
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();
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']);
28 /* there shouldn't be any latin text in Chinese conversion, so no need
29 to mark anything
31 function markNoConversion($text) {
32 return $text;
35 function convertCategoryKey( $key ) {
36 return $this->autoConvert( $key, 'zh-cn' );
41 /* class that handles both Traditional and Simplified Chinese
42 right now it only distinguish zh_cn, zh_tw, zh_sg and zh_hk.
44 class LanguageZh extends LanguageZh_cn {
46 function LanguageZh() {
47 global $wgHooks;
48 $this->mConverter = new ZhConverter($this, 'zh',
49 array('zh', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk'),
50 array('zh'=>'zh-cn',
51 'zh-cn'=>'zh-sg',
52 'zh-sg'=>'zh-cn',
53 'zh-tw'=>'zh-hk',
54 'zh-hk'=>'zh-tw'));
55 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
59 # this should give much better diff info
60 function segmentForDiff( $text ) {
61 return preg_replace(
62 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
63 "' ' .\"$1\"", $text);
66 function unsegmentForDiff( $text ) {
67 return preg_replace(
68 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
69 "\"$1\"", $text);
72 // word segmentation
73 function stripForSearch( $string ) {
74 $fname="LanguageZh::stripForSearch";
75 wfProfileIn( $fname );
77 // eventually this should be a word segmentation
78 // for now just treat each character as a word
79 $t = preg_replace(
80 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
81 "' ' .\"$1\"", $string);
83 //always convert to zh-cn before indexing. it should be
84 //better to use zh-cn for search, since conversion from
85 //Traditional to Simplified is less ambiguous than the
86 //other way around
88 $t = $this->mConverter->autoConvert($t, 'zh-cn');
89 $t = LanguageUtf8::stripForSearch( $t );
90 wfProfileOut( $fname );
91 return $t;
95 function convertForSearchResult( $termsArray ) {
96 $terms = implode( '|', $termsArray );
97 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
98 $ret = array_unique( explode('|', $terms) );
99 return $ret;