Follwup r75575, honour table prefixes. Bad Roan ;)
[mediawiki.git] / languages / classes / LanguageZh.php
blob0055a33b064a968b052064970701aa0e7e743c12
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 {
11 function __construct( $langobj, $maincode,
12 $variants = array(),
13 $variantfallbacks = array(),
14 $flags = array(),
15 $manualLevel = array() ) {
16 $this->mDescCodeSep = ':';
17 $this->mDescVarSep = ';';
18 parent::__construct( $langobj, $maincode,
19 $variants,
20 $variantfallbacks,
21 $flags,
22 $manualLevel );
23 $names = array(
24 'zh' => '原文',
25 'zh-hans' => '简体',
26 'zh-hant' => '繁體',
27 'zh-cn' => '大陆',
28 'zh-tw' => '台灣',
29 'zh-hk' => '香港',
30 'zh-mo' => '澳門',
31 'zh-sg' => '新加坡',
32 'zh-my' => '大马',
34 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
37 function loadDefaultTables() {
38 require( dirname( __FILE__ ) . "/../../includes/ZhConversion.php" );
39 $this->mTables = array(
40 'zh-hans' => new ReplacementArray( $zh2Hans ),
41 'zh-hant' => new ReplacementArray( $zh2Hant ),
42 'zh-cn' => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
43 'zh-hk' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
44 'zh-mo' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
45 'zh-my' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
46 'zh-sg' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
47 'zh-tw' => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
48 'zh' => new ReplacementArray
52 function postLoadTables() {
53 $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
54 $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
55 $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
56 $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
57 $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
58 $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
61 /* there shouldn't be any latin text in Chinese conversion, so no need
62 to mark anything.
63 $noParse is there for compatibility with LanguageConvert::markNoConversion
65 function markNoConversion( $text, $noParse = false ) {
66 return $text;
69 function convertCategoryKey( $key ) {
70 return $this->autoConvert( $key, 'zh' );
74 /**
75 * class that handles both Traditional and Simplified Chinese
76 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
78 * @ingroup Language
80 class LanguageZh extends LanguageZh_hans {
82 function __construct() {
83 global $wgHooks;
84 parent::__construct();
86 $variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
88 $variantfallbacks = array(
89 'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
90 'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
91 'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
92 'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ),
93 'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ),
94 'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
95 'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
96 'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
97 'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
99 $ml = array(
100 'zh' => 'disable',
101 'zh-hans' => 'unidirectional',
102 'zh-hant' => 'unidirectional',
105 $this->mConverter = new ZhConverter( $this, 'zh',
106 $variants, $variantfallbacks,
107 array(),
108 $ml );
110 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
113 # this should give much better diff info
114 function segmentForDiff( $text ) {
115 return preg_replace(
116 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
117 "' ' .\"$1\"", $text );
120 function unsegmentForDiff( $text ) {
121 return preg_replace(
122 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
123 "\"$1\"", $text );
127 * auto convert to zh-hans and normalize special characters.
129 * @param $string String
130 * @param $autoVariant String, default to 'zh-hans'
131 * @return String
133 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
134 wfProfileIn( __METHOD__ );
136 // always convert to zh-hans before indexing. it should be
137 // better to use zh-hans for search, since conversion from
138 // Traditional to Simplified is less ambiguous than the
139 // other way around
140 $s = $this->mConverter->autoConvert( $string, $autoVariant );
141 // LanguageZh_hans::normalizeForSearch
142 $s = parent::normalizeForSearch( $s );
143 wfProfileOut( __METHOD__ );
144 return $s;
148 function convertForSearchResult( $termsArray ) {
149 $terms = implode( '|', $termsArray );
150 $terms = self::convertDoubleWidth( $terms );
151 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
152 $ret = array_unique( explode( '|', $terms ) );
153 return $ret;