3 * Chinese specific code.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 require_once __DIR__
. '/../LanguageConverter.php';
25 require_once __DIR__
. '/LanguageZh_hans.php';
30 class ZhConverter
extends LanguageConverter
{
32 * @param Language $langobj
33 * @param string $maincode
34 * @param array $variants
35 * @param array $variantfallbacks
37 * @param array $manualLevel
39 function __construct( $langobj, $maincode,
41 $variantfallbacks = array(),
43 $manualLevel = array() ) {
44 $this->mDescCodeSep
= ':';
45 $this->mDescVarSep
= ';';
46 parent
::__construct( $langobj, $maincode,
62 $this->mVariantNames
= array_merge( $this->mVariantNames
, $names );
65 function loadDefaultTables() {
66 require __DIR__
. "/../../includes/ZhConversion.php";
67 $this->mTables
= array(
68 'zh-hans' => new ReplacementArray( $zh2Hans ),
69 'zh-hant' => new ReplacementArray( $zh2Hant ),
70 'zh-cn' => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
71 'zh-hk' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
72 'zh-mo' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
73 'zh-my' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
74 'zh-sg' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
75 'zh-tw' => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
76 'zh' => new ReplacementArray
80 function postLoadTables() {
81 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
82 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
83 $this->mTables
['zh-mo']->merge( $this->mTables
['zh-hant'] );
84 $this->mTables
['zh-my']->merge( $this->mTables
['zh-hans'] );
85 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
86 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
93 function convertCategoryKey( $key ) {
94 return $this->autoConvert( $key, 'zh' );
99 * class that handles both Traditional and Simplified Chinese
100 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
104 class LanguageZh
extends LanguageZh_hans
{
105 function __construct() {
108 parent
::__construct();
122 $variantfallbacks = array(
123 'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
124 'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
125 'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
126 'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ),
127 'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ),
128 'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
129 'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
130 'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
131 'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
135 'zh-hans' => 'unidirectional',
136 'zh-hant' => 'unidirectional',
139 $this->mConverter
= new ZhConverter( $this, 'zh',
140 $variants, $variantfallbacks,
144 $wgHooks['PageContentSaveComplete'][] = $this->mConverter
;
148 * this should give much better diff info
150 * @param string $text
153 function segmentForDiff( $text ) {
154 return preg_replace( '/[\xc0-\xff][\x80-\xbf]*/', ' $0', $text );
158 * @param string $text
161 function unsegmentForDiff( $text ) {
162 return preg_replace( '/ ([\xc0-\xff][\x80-\xbf]*)/', '$1', $text );
166 * auto convert to zh-hans and normalize special characters.
168 * @param string $string
169 * @param string $autoVariant default to 'zh-hans'
172 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
173 wfProfileIn( __METHOD__
);
175 // always convert to zh-hans before indexing. it should be
176 // better to use zh-hans for search, since conversion from
177 // Traditional to Simplified is less ambiguous than the
179 $s = $this->mConverter
->autoConvert( $string, $autoVariant );
180 // LanguageZh_hans::normalizeForSearch
181 $s = parent
::normalizeForSearch( $s );
182 wfProfileOut( __METHOD__
);
188 * @param array $termsArray
191 function convertForSearchResult( $termsArray ) {
192 $terms = implode( '|', $termsArray );
193 $terms = self
::convertDoubleWidth( $terms );
194 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
195 $ret = array_unique( explode( '|', $terms ) );