2004-02-18 02:15:00 +00:00
|
|
|
|
<?php
|
2012-06-10 17:40:03 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Chinese specific code.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
|
*
|
|
|
|
|
|
* @file
|
|
|
|
|
|
* @ingroup Language
|
|
|
|
|
|
*/
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @ingroup Language
|
|
|
|
|
|
*/
|
2005-04-15 14:12:39 +00:00
|
|
|
|
class ZhConverter extends LanguageConverter {
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
2014-04-17 13:31:28 +00:00
|
|
|
|
* @param Language $langobj
|
|
|
|
|
|
* @param string $maincode
|
|
|
|
|
|
* @param array $variants
|
|
|
|
|
|
* @param array $variantfallbacks
|
|
|
|
|
|
* @param array $flags
|
|
|
|
|
|
* @param array $manualLevel
|
2011-05-29 16:32:05 +00:00
|
|
|
|
*/
|
2017-10-04 19:02:29 +00:00
|
|
|
|
function __construct( Language $langobj, $maincode,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$variants = [],
|
|
|
|
|
|
$variantfallbacks = [],
|
|
|
|
|
|
$flags = [],
|
|
|
|
|
|
$manualLevel = [] ) {
|
2008-07-09 08:16:39 +00:00
|
|
|
|
$this->mDescCodeSep = ':';
|
|
|
|
|
|
$this->mDescVarSep = ';';
|
2010-07-29 09:43:18 +00:00
|
|
|
|
parent::__construct( $langobj, $maincode,
|
2008-06-26 03:00:34 +00:00
|
|
|
|
$variants,
|
|
|
|
|
|
$variantfallbacks,
|
|
|
|
|
|
$flags,
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$manualLevel );
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$names = [
|
2013-04-17 19:10:02 +00:00
|
|
|
|
'zh' => '原文',
|
2008-06-26 03:00:34 +00:00
|
|
|
|
'zh-hans' => '简体',
|
|
|
|
|
|
'zh-hant' => '繁體',
|
2013-04-17 19:10:02 +00:00
|
|
|
|
'zh-cn' => '大陆',
|
|
|
|
|
|
'zh-tw' => '台灣',
|
|
|
|
|
|
'zh-hk' => '香港',
|
|
|
|
|
|
'zh-mo' => '澳門',
|
|
|
|
|
|
'zh-sg' => '新加坡',
|
|
|
|
|
|
'zh-my' => '大马',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
];
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$this->mVariantNames = array_merge( $this->mVariantNames, $names );
|
2008-06-26 03:00:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-04-15 14:12:39 +00:00
|
|
|
|
function loadDefaultTables() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$this->mTables = [
|
2016-01-29 05:19:58 +00:00
|
|
|
|
'zh-hans' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2Hans ),
|
|
|
|
|
|
'zh-hant' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2Hant ),
|
|
|
|
|
|
'zh-cn' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
|
|
|
|
|
|
'zh-hk' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2HK ),
|
|
|
|
|
|
'zh-mo' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2HK ),
|
|
|
|
|
|
'zh-my' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
|
|
|
|
|
|
'zh-sg' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
|
|
|
|
|
|
'zh-tw' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2TW ),
|
2013-04-17 19:10:02 +00:00
|
|
|
|
'zh' => new ReplacementArray
|
2016-02-17 09:09:32 +00:00
|
|
|
|
];
|
2004-10-04 04:14:05 +00:00
|
|
|
|
}
|
2005-01-22 03:22:16 +00:00
|
|
|
|
|
2005-04-15 14:12:39 +00:00
|
|
|
|
function postLoadTables() {
|
2014-09-04 12:19:43 +00:00
|
|
|
|
$this->mTables['zh-cn']->setArray(
|
|
|
|
|
|
$this->mTables['zh-cn']->getArray() + $this->mTables['zh-hans']->getArray()
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->mTables['zh-hk']->setArray(
|
|
|
|
|
|
$this->mTables['zh-hk']->getArray() + $this->mTables['zh-hant']->getArray()
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->mTables['zh-mo']->setArray(
|
|
|
|
|
|
$this->mTables['zh-mo']->getArray() + $this->mTables['zh-hant']->getArray()
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->mTables['zh-my']->setArray(
|
|
|
|
|
|
$this->mTables['zh-my']->getArray() + $this->mTables['zh-hans']->getArray()
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->mTables['zh-sg']->setArray(
|
|
|
|
|
|
$this->mTables['zh-sg']->getArray() + $this->mTables['zh-hans']->getArray()
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->mTables['zh-tw']->setArray(
|
|
|
|
|
|
$this->mTables['zh-tw']->getArray() + $this->mTables['zh-hant']->getArray()
|
|
|
|
|
|
);
|
2007-12-02 09:02:09 +00:00
|
|
|
|
}
|
2005-04-28 03:27:07 +00:00
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
2014-04-17 13:31:28 +00:00
|
|
|
|
* @param string $key
|
|
|
|
|
|
* @return string
|
2011-05-29 16:32:05 +00:00
|
|
|
|
*/
|
2005-04-28 03:33:54 +00:00
|
|
|
|
function convertCategoryKey( $key ) {
|
2007-12-02 09:02:09 +00:00
|
|
|
|
return $this->autoConvert( $key, 'zh' );
|
2005-04-28 03:33:54 +00:00
|
|
|
|
}
|
2005-04-15 14:12:39 +00:00
|
|
|
|
}
|
2004-12-29 01:07:43 +00:00
|
|
|
|
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* class that handles both Traditional and Simplified Chinese
|
|
|
|
|
|
* right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @ingroup Language
|
|
|
|
|
|
*/
|
2007-09-27 15:40:35 +00:00
|
|
|
|
class LanguageZh extends LanguageZh_hans {
|
2006-06-24 18:48:58 +00:00
|
|
|
|
function __construct() {
|
2006-07-26 07:15:39 +00:00
|
|
|
|
parent::__construct();
|
2007-12-02 03:41:12 +00:00
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$variants = [
|
2014-04-21 18:43:15 +00:00
|
|
|
|
'zh',
|
|
|
|
|
|
'zh-hans',
|
|
|
|
|
|
'zh-hant',
|
|
|
|
|
|
'zh-cn',
|
|
|
|
|
|
'zh-hk',
|
|
|
|
|
|
'zh-mo',
|
|
|
|
|
|
'zh-my',
|
|
|
|
|
|
'zh-sg',
|
|
|
|
|
|
'zh-tw'
|
2016-02-17 09:09:32 +00:00
|
|
|
|
];
|
2010-07-29 09:43:18 +00:00
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$variantfallbacks = [
|
|
|
|
|
|
'zh' => [ 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ],
|
|
|
|
|
|
'zh-hans' => [ 'zh-cn', 'zh-sg', 'zh-my' ],
|
|
|
|
|
|
'zh-hant' => [ 'zh-tw', 'zh-hk', 'zh-mo' ],
|
|
|
|
|
|
'zh-cn' => [ 'zh-hans', 'zh-sg', 'zh-my' ],
|
|
|
|
|
|
'zh-sg' => [ 'zh-hans', 'zh-cn', 'zh-my' ],
|
|
|
|
|
|
'zh-my' => [ 'zh-hans', 'zh-sg', 'zh-cn' ],
|
|
|
|
|
|
'zh-tw' => [ 'zh-hant', 'zh-hk', 'zh-mo' ],
|
|
|
|
|
|
'zh-hk' => [ 'zh-hant', 'zh-mo', 'zh-tw' ],
|
|
|
|
|
|
'zh-mo' => [ 'zh-hant', 'zh-hk', 'zh-tw' ],
|
|
|
|
|
|
];
|
|
|
|
|
|
$ml = [
|
2013-04-17 19:10:02 +00:00
|
|
|
|
'zh' => 'disable',
|
2008-06-26 03:00:34 +00:00
|
|
|
|
'zh-hans' => 'unidirectional',
|
|
|
|
|
|
'zh-hant' => 'unidirectional',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
];
|
2007-12-02 03:41:12 +00:00
|
|
|
|
|
2008-06-26 03:00:34 +00:00
|
|
|
|
$this->mConverter = new ZhConverter( $this, 'zh',
|
|
|
|
|
|
$variants, $variantfallbacks,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$ml );
|
2004-12-29 01:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* this should give much better diff info
|
|
|
|
|
|
*
|
2014-04-17 13:31:28 +00:00
|
|
|
|
* @param string $text
|
2011-05-29 16:32:05 +00:00
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2004-12-05 02:17:21 +00:00
|
|
|
|
function segmentForDiff( $text ) {
|
2013-03-18 01:09:02 +00:00
|
|
|
|
return preg_replace( '/[\xc0-\xff][\x80-\xbf]*/', ' $0', $text );
|
2004-12-05 02:17:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
2014-04-17 13:31:28 +00:00
|
|
|
|
* @param string $text
|
2011-05-29 16:32:05 +00:00
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2004-12-05 02:17:21 +00:00
|
|
|
|
function unsegmentForDiff( $text ) {
|
2013-03-18 01:09:02 +00:00
|
|
|
|
return preg_replace( '/ ([\xc0-\xff][\x80-\xbf]*)/', '$1', $text );
|
2004-12-05 02:17:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-02-02 15:09:01 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* auto convert to zh-hans and normalize special characters.
|
|
|
|
|
|
*
|
2014-04-17 13:31:28 +00:00
|
|
|
|
* @param string $string
|
2014-07-24 12:55:43 +00:00
|
|
|
|
* @param string $autoVariant Defaults to 'zh-hans'
|
2014-04-17 13:31:28 +00:00
|
|
|
|
* @return string
|
2010-02-02 15:09:01 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
|
2010-01-06 19:51:29 +00:00
|
|
|
|
// always convert to zh-hans before indexing. it should be
|
|
|
|
|
|
// better to use zh-hans for search, since conversion from
|
|
|
|
|
|
// Traditional to Simplified is less ambiguous than the
|
|
|
|
|
|
// other way around
|
2010-01-07 04:50:32 +00:00
|
|
|
|
$s = $this->mConverter->autoConvert( $string, $autoVariant );
|
2010-02-02 15:09:01 +00:00
|
|
|
|
// LanguageZh_hans::normalizeForSearch
|
|
|
|
|
|
$s = parent::normalizeForSearch( $s );
|
2010-01-06 19:51:29 +00:00
|
|
|
|
return $s;
|
2004-11-09 21:41:30 +00:00
|
|
|
|
}
|
2004-11-29 01:22:44 +00:00
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
2014-04-17 13:31:28 +00:00
|
|
|
|
* @param array $termsArray
|
2011-05-29 16:32:05 +00:00
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
2004-11-29 01:22:44 +00:00
|
|
|
|
function convertForSearchResult( $termsArray ) {
|
|
|
|
|
|
$terms = implode( '|', $termsArray );
|
2010-01-07 04:50:32 +00:00
|
|
|
|
$terms = self::convertDoubleWidth( $terms );
|
2005-04-15 14:12:39 +00:00
|
|
|
|
$terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$ret = array_unique( explode( '|', $terms ) );
|
2004-11-29 01:22:44 +00:00
|
|
|
|
return $ret;
|
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
}
|