* updating the manual tables, fixing some conversion errors, and regenerate the ZhCon...
[mediawiki.git] / languages / classes / LanguageZh.php
blobdb913b50e6c4dce67c269c7e94fc53611cfa2d93
1 <?php
2 /**
3 * @addtogroup Language
4 */
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-cn' => new ReplacementArray( $zh2CN ),
13 'zh-tw' => new ReplacementArray( $zh2TW ),
14 'zh-sg' => new ReplacementArray( array_merge($zh2CN, $zh2SG) ),
15 'zh-hk' => new ReplacementArray( array_merge($zh2TW, $zh2HK) ),
16 'zh' => new ReplacementArray
20 function postLoadTables() {
21 $this->mTables['zh-sg']->merge( $this->mTables['zh-cn'] );
22 $this->mTables['zh-hk']->merge( $this->mTables['zh-tw'] );
25 /* there shouldn't be any latin text in Chinese conversion, so no need
26 to mark anything.
27 $noParse is there for compatibility with LanguageConvert::markNoConversion
29 function markNoConversion($text, $noParse = false) {
30 return $text;
33 function convertCategoryKey( $key ) {
34 return $this->autoConvert( $key, 'zh-cn' );
39 /* class that handles both Traditional and Simplified Chinese
40 right now it only distinguish zh_cn, zh_tw, zh_sg and zh_hk.
42 class LanguageZh extends LanguageZh_hans {
44 function __construct() {
45 global $wgHooks;
46 parent::__construct();
48 $variants = array('zh', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk');
49 $variantfallbacks = array(
50 'zh' => 'zh-cn',
51 'zh-cn' => 'zh-sg',
52 'zh-sg' => 'zh-cn',
53 'zh-tw' => 'zh-hk',
54 'zh-hk' => 'zh-tw'
57 $this->mConverter = new ZhConverter( $this, 'zh', $variants, $variantfallbacks );
59 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
63 # this should give much better diff info
64 function segmentForDiff( $text ) {
65 return preg_replace(
66 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
67 "' ' .\"$1\"", $text);
70 function unsegmentForDiff( $text ) {
71 return preg_replace(
72 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
73 "\"$1\"", $text);
76 // word segmentation
77 function stripForSearch( $string ) {
78 $fname="LanguageZh::stripForSearch";
79 wfProfileIn( $fname );
81 // eventually this should be a word segmentation
82 // for now just treat each character as a word
83 $t = preg_replace(
84 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
85 "' ' .\"$1\"", $string);
87 //always convert to zh-cn before indexing. it should be
88 //better to use zh-cn for search, since conversion from
89 //Traditional to Simplified is less ambiguous than the
90 //other way around
92 $t = $this->mConverter->autoConvert($t, 'zh-cn');
93 $t = parent::stripForSearch( $t );
94 wfProfileOut( $fname );
95 return $t;
99 function convertForSearchResult( $termsArray ) {
100 $terms = implode( '|', $termsArray );
101 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
102 $ret = array_unique( explode('|', $terms) );
103 return $ret;