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( $zh2CN ),
71 'zh-hk' => new ReplacementArray( $zh2HK ),
72 'zh-mo' => new ReplacementArray( $zh2HK ),
73 'zh-my' => new ReplacementArray( $zh2CN ),
74 'zh-sg' => new ReplacementArray( $zh2CN ),
75 'zh-tw' => new ReplacementArray( $zh2TW ),
76 'zh' => new ReplacementArray
80 function postLoadTables() {
81 $this->mTables
['zh-cn']->setArray(
82 $this->mTables
['zh-cn']->getArray() +
$this->mTables
['zh-hans']->getArray()
84 $this->mTables
['zh-hk']->setArray(
85 $this->mTables
['zh-hk']->getArray() +
$this->mTables
['zh-hant']->getArray()
87 $this->mTables
['zh-mo']->setArray(
88 $this->mTables
['zh-mo']->getArray() +
$this->mTables
['zh-hant']->getArray()
90 $this->mTables
['zh-my']->setArray(
91 $this->mTables
['zh-my']->getArray() +
$this->mTables
['zh-hans']->getArray()
93 $this->mTables
['zh-sg']->setArray(
94 $this->mTables
['zh-sg']->getArray() +
$this->mTables
['zh-hans']->getArray()
96 $this->mTables
['zh-tw']->setArray(
97 $this->mTables
['zh-tw']->getArray() +
$this->mTables
['zh-hant']->getArray()
105 function convertCategoryKey( $key ) {
106 return $this->autoConvert( $key, 'zh' );
111 * class that handles both Traditional and Simplified Chinese
112 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
116 class LanguageZh
extends LanguageZh_hans
{
117 function __construct() {
120 parent
::__construct();
134 $variantfallbacks = array(
135 'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
136 'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
137 'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
138 'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ),
139 'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ),
140 'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
141 'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
142 'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
143 'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
147 'zh-hans' => 'unidirectional',
148 'zh-hant' => 'unidirectional',
151 $this->mConverter
= new ZhConverter( $this, 'zh',
152 $variants, $variantfallbacks,
156 $wgHooks['PageContentSaveComplete'][] = $this->mConverter
;
160 * this should give much better diff info
162 * @param string $text
165 function segmentForDiff( $text ) {
166 return preg_replace( '/[\xc0-\xff][\x80-\xbf]*/', ' $0', $text );
170 * @param string $text
173 function unsegmentForDiff( $text ) {
174 return preg_replace( '/ ([\xc0-\xff][\x80-\xbf]*)/', '$1', $text );
178 * auto convert to zh-hans and normalize special characters.
180 * @param string $string
181 * @param string $autoVariant Defaults to 'zh-hans'
184 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
186 // always convert to zh-hans before indexing. it should be
187 // better to use zh-hans for search, since conversion from
188 // Traditional to Simplified is less ambiguous than the
190 $s = $this->mConverter
->autoConvert( $string, $autoVariant );
191 // LanguageZh_hans::normalizeForSearch
192 $s = parent
::normalizeForSearch( $s );
198 * @param array $termsArray
201 function convertForSearchResult( $termsArray ) {
202 $terms = implode( '|', $termsArray );
203 $terms = self
::convertDoubleWidth( $terms );
204 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
205 $ret = array_unique( explode( '|', $terms ) );