2004-02-18 02:15:00 +00:00
|
|
|
|
<?php
|
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
|
|
|
|
|
2010-07-29 09:43:18 +00:00
|
|
|
|
require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
|
|
|
|
|
|
require_once( dirname( __FILE__ ) . '/LanguageZh_hans.php' );
|
2004-09-16 20:18:49 +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
|
|
|
|
/**
|
|
|
|
|
|
* @ingroup Language
|
|
|
|
|
|
*/
|
2005-04-15 14:12:39 +00:00
|
|
|
|
class ZhConverter extends LanguageConverter {
|
2008-06-26 03:00:34 +00:00
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $langobj Language
|
|
|
|
|
|
* @param $maincode string
|
|
|
|
|
|
* @param $variants array
|
|
|
|
|
|
* @param $variantfallbacks array
|
|
|
|
|
|
* @param $flags array
|
|
|
|
|
|
* @param $manualLevel array
|
|
|
|
|
|
*/
|
2010-07-29 09:43:18 +00:00
|
|
|
|
function __construct( $langobj, $maincode,
|
|
|
|
|
|
$variants = array(),
|
|
|
|
|
|
$variantfallbacks = array(),
|
2008-06-26 03:00:34 +00:00
|
|
|
|
$flags = array(),
|
|
|
|
|
|
$manualLevel = array() ) {
|
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 );
|
2008-06-26 03:00:34 +00:00
|
|
|
|
$names = array(
|
|
|
|
|
|
'zh' => '原文',
|
|
|
|
|
|
'zh-hans' => '简体',
|
|
|
|
|
|
'zh-hant' => '繁體',
|
|
|
|
|
|
'zh-cn' => '大陆',
|
|
|
|
|
|
'zh-tw' => '台灣',
|
|
|
|
|
|
'zh-hk' => '香港',
|
|
|
|
|
|
'zh-mo' => '澳門',
|
|
|
|
|
|
'zh-sg' => '新加坡',
|
2008-06-27 15:08:07 +00:00
|
|
|
|
'zh-my' => '大马',
|
2008-06-26 03:00:34 +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() {
|
2010-07-29 09:43:18 +00:00
|
|
|
|
require( dirname( __FILE__ ) . "/../../includes/ZhConversion.php" );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$this->mTables = array(
|
2007-12-02 09:02:09 +00:00
|
|
|
|
'zh-hans' => new ReplacementArray( $zh2Hans ),
|
|
|
|
|
|
'zh-hant' => new ReplacementArray( $zh2Hant ),
|
2010-07-29 09:43:18 +00:00
|
|
|
|
'zh-cn' => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
|
|
|
|
|
|
'zh-hk' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
|
|
|
|
|
|
'zh-mo' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
|
|
|
|
|
|
'zh-my' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
|
|
|
|
|
|
'zh-sg' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
|
|
|
|
|
|
'zh-tw' => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
|
2007-12-02 09:02:09 +00:00
|
|
|
|
'zh' => new ReplacementArray
|
2006-11-21 09:53:45 +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() {
|
2007-12-02 09:02:09 +00:00
|
|
|
|
$this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
|
|
|
|
|
|
$this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
|
2008-06-26 03:00:34 +00:00
|
|
|
|
$this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
|
|
|
|
|
|
$this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
|
|
|
|
|
|
$this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
|
|
|
|
|
|
$this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
|
2007-12-02 09:02:09 +00:00
|
|
|
|
}
|
2005-04-28 03:27:07 +00:00
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* there shouldn't be any latin text in Chinese conversion, so no need
|
|
|
|
|
|
* to mark anything.
|
|
|
|
|
|
* $noParse is there for compatibility with LanguageConvert::markNoConversion
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $text string
|
|
|
|
|
|
* @param $noParse bool
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return string
|
2008-06-26 03:00:34 +00:00
|
|
|
|
*/
|
2010-07-29 09:43:18 +00:00
|
|
|
|
function markNoConversion( $text, $noParse = false ) {
|
2005-04-28 03:27:07 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2005-04-28 03:33:54 +00:00
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $key string
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
*/
|
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 {
|
2005-08-15 19:27:58 +00:00
|
|
|
|
|
2006-06-24 18:48:58 +00:00
|
|
|
|
function __construct() {
|
2005-04-15 14:12:39 +00:00
|
|
|
|
global $wgHooks;
|
2006-07-26 07:15:39 +00:00
|
|
|
|
parent::__construct();
|
2007-12-02 03:41:12 +00:00
|
|
|
|
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
|
|
|
|
|
|
|
2007-12-02 03:41:12 +00:00
|
|
|
|
$variantfallbacks = array(
|
2010-07-29 09:43:18 +00:00
|
|
|
|
'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
|
|
|
|
|
|
'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
|
|
|
|
|
|
'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
|
|
|
|
|
|
'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ),
|
|
|
|
|
|
'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ),
|
|
|
|
|
|
'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
|
|
|
|
|
|
'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
|
|
|
|
|
|
'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
|
|
|
|
|
|
'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
|
2008-06-26 03:00:34 +00:00
|
|
|
|
);
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$ml = array(
|
2008-06-26 03:00:34 +00:00
|
|
|
|
'zh' => 'disable',
|
|
|
|
|
|
'zh-hans' => 'unidirectional',
|
|
|
|
|
|
'zh-hant' => 'unidirectional',
|
2007-12-02 03:41:12 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
2008-06-26 03:00:34 +00:00
|
|
|
|
$this->mConverter = new ZhConverter( $this, 'zh',
|
|
|
|
|
|
$variants, $variantfallbacks,
|
2010-01-19 02:36:33 +00:00
|
|
|
|
array(),
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$ml );
|
2007-12-02 03:41:12 +00:00
|
|
|
|
|
2005-04-15 14:12:39 +00:00
|
|
|
|
$wgHooks['ArticleSaveComplete'][] = $this->mConverter;
|
2004-12-29 01:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* this should give much better diff info
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $text string
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2004-12-05 02:17:21 +00:00
|
|
|
|
function segmentForDiff( $text ) {
|
|
|
|
|
|
return preg_replace(
|
|
|
|
|
|
"/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
|
2010-07-29 09:43:18 +00:00
|
|
|
|
"' ' .\"$1\"", $text );
|
2004-12-05 02:17:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $text string
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2004-12-05 02:17:21 +00:00
|
|
|
|
function unsegmentForDiff( $text ) {
|
|
|
|
|
|
return preg_replace(
|
|
|
|
|
|
"/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
|
2010-07-29 09:43:18 +00:00
|
|
|
|
"\"$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.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $string String
|
|
|
|
|
|
* @param $autoVariant String, default to 'zh-hans'
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
*/
|
|
|
|
|
|
function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
|
2008-11-25 02:39:06 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-12-29 01:07:43 +00:00
|
|
|
|
|
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 );
|
2008-11-25 02:39:06 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
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
|
|
|
|
/**
|
|
|
|
|
|
* @param $termsArray array
|
|
|
|
|
|
* @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
|
|
|
|
}
|
2008-06-26 03:00:34 +00:00
|
|
|
|
|