[JSTesting] fix case typo in file path
[lhc/web/wiklou.git] / languages / classes / LanguageZh.php
1 <?php
2
3 require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
4 require_once( dirname( __FILE__ ) . '/LanguageZh_hans.php' );
5
6 /**
7 * @ingroup Language
8 */
9 class ZhConverter extends LanguageConverter {
10
11 /**
12 * @param $langobj Language
13 * @param $maincode string
14 * @param $variants array
15 * @param $variantfallbacks array
16 * @param $flags array
17 * @param $manualLevel array
18 */
19 function __construct( $langobj, $maincode,
20 $variants = array(),
21 $variantfallbacks = array(),
22 $flags = array(),
23 $manualLevel = array() ) {
24 $this->mDescCodeSep = ':';
25 $this->mDescVarSep = ';';
26 parent::__construct( $langobj, $maincode,
27 $variants,
28 $variantfallbacks,
29 $flags,
30 $manualLevel );
31 $names = array(
32 'zh' => '原文',
33 'zh-hans' => '简体',
34 'zh-hant' => '繁體',
35 'zh-cn' => '大陆',
36 'zh-tw' => '台灣',
37 'zh-hk' => '香港',
38 'zh-mo' => '澳門',
39 'zh-sg' => '新加坡',
40 'zh-my' => '大马',
41 );
42 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
43 }
44
45 function loadDefaultTables() {
46 require( dirname( __FILE__ ) . "/../../includes/ZhConversion.php" );
47 $this->mTables = array(
48 'zh-hans' => new ReplacementArray( $zh2Hans ),
49 'zh-hant' => new ReplacementArray( $zh2Hant ),
50 'zh-cn' => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
51 'zh-hk' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
52 'zh-mo' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
53 'zh-my' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
54 'zh-sg' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
55 'zh-tw' => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
56 'zh' => new ReplacementArray
57 );
58 }
59
60 function postLoadTables() {
61 $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
62 $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
63 $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
64 $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
65 $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
66 $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
67 }
68
69 /**
70 * there shouldn't be any latin text in Chinese conversion, so no need
71 * to mark anything.
72 * $noParse is there for compatibility with LanguageConvert::markNoConversion
73 *
74 * @param $text string
75 * @param $noParse bool
76 *
77 * @return string
78 */
79 function markNoConversion( $text, $noParse = false ) {
80 return $text;
81 }
82
83 /**
84 * @param $key string
85 * @return String
86 */
87 function convertCategoryKey( $key ) {
88 return $this->autoConvert( $key, 'zh' );
89 }
90 }
91
92 /**
93 * class that handles both Traditional and Simplified Chinese
94 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
95 *
96 * @ingroup Language
97 */
98 class LanguageZh extends LanguageZh_hans {
99
100 function __construct() {
101 global $wgHooks;
102 parent::__construct();
103
104 $variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
105
106 $variantfallbacks = array(
107 'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
108 'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
109 'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
110 'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ),
111 'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ),
112 'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
113 'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
114 'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
115 'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
116 );
117 $ml = array(
118 'zh' => 'disable',
119 'zh-hans' => 'unidirectional',
120 'zh-hant' => 'unidirectional',
121 );
122
123 $this->mConverter = new ZhConverter( $this, 'zh',
124 $variants, $variantfallbacks,
125 array(),
126 $ml );
127
128 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
129 }
130
131 /**
132 * this should give much better diff info
133 *
134 * @param $text string
135 * @return string
136 */
137 function segmentForDiff( $text ) {
138 return preg_replace(
139 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
140 "' ' .\"$1\"", $text );
141 }
142
143 /**
144 * @param $text string
145 * @return string
146 */
147 function unsegmentForDiff( $text ) {
148 return preg_replace(
149 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
150 "\"$1\"", $text );
151 }
152
153 /**
154 * auto convert to zh-hans and normalize special characters.
155 *
156 * @param $string String
157 * @param $autoVariant String, default to 'zh-hans'
158 * @return String
159 */
160 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
161 wfProfileIn( __METHOD__ );
162
163 // always convert to zh-hans before indexing. it should be
164 // better to use zh-hans for search, since conversion from
165 // Traditional to Simplified is less ambiguous than the
166 // other way around
167 $s = $this->mConverter->autoConvert( $string, $autoVariant );
168 // LanguageZh_hans::normalizeForSearch
169 $s = parent::normalizeForSearch( $s );
170 wfProfileOut( __METHOD__ );
171 return $s;
172
173 }
174
175 /**
176 * @param $termsArray array
177 * @return array
178 */
179 function convertForSearchResult( $termsArray ) {
180 $terms = implode( '|', $termsArray );
181 $terms = self::convertDoubleWidth( $terms );
182 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
183 $ret = array_unique( explode( '|', $terms ) );
184 return $ret;
185 }
186 }
187