2009-03-23 19:10:28 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2010-07-29 09:43:18 +00:00
|
|
|
|
require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
|
|
|
|
|
|
require_once( dirname( __FILE__ ) . '/LanguageZh.php' );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @ingroup Language
|
|
|
|
|
|
*/
|
|
|
|
|
|
class GanConverter extends LanguageConverter {
|
|
|
|
|
|
|
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(),
|
2009-03-23 19:10:28 +00:00
|
|
|
|
$flags = array(),
|
|
|
|
|
|
$manualLevel = array() ) {
|
|
|
|
|
|
$this->mDescCodeSep = ':';
|
|
|
|
|
|
$this->mDescVarSep = ';';
|
2010-07-29 09:43:18 +00:00
|
|
|
|
parent::__construct( $langobj, $maincode,
|
2009-03-23 19:10:28 +00:00
|
|
|
|
$variants,
|
|
|
|
|
|
$variantfallbacks,
|
|
|
|
|
|
$flags,
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$manualLevel );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
$names = array(
|
|
|
|
|
|
'gan' => '原文',
|
|
|
|
|
|
'gan-hans' => '简体',
|
|
|
|
|
|
'gan-hant' => '繁體',
|
|
|
|
|
|
);
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$this->mVariantNames = array_merge( $this->mVariantNames, $names );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function loadDefaultTables() {
|
2010-07-29 09:43:18 +00:00
|
|
|
|
require( dirname( __FILE__ ) . "/../../includes/ZhConversion.php" );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
$this->mTables = array(
|
|
|
|
|
|
'gan-hans' => new ReplacementArray( $zh2Hans ),
|
|
|
|
|
|
'gan-hant' => new ReplacementArray( $zh2Hant ),
|
|
|
|
|
|
'gan' => new ReplacementArray
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
2009-03-23 19:10:28 +00:00
|
|
|
|
*/
|
2010-07-29 09:43:18 +00:00
|
|
|
|
function markNoConversion( $text, $noParse = false ) {
|
2009-03-23 19:10:28 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $key string
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
*/
|
2009-03-23 19:10:28 +00:00
|
|
|
|
function convertCategoryKey( $key ) {
|
|
|
|
|
|
return $this->autoConvert( $key, 'gan' );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* class that handles both Traditional and Simplified Chinese
|
|
|
|
|
|
* right now it only distinguish gan_hans, gan_hant.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @ingroup Language
|
|
|
|
|
|
*/
|
|
|
|
|
|
class LanguageGan extends LanguageZh {
|
|
|
|
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
|
|
global $wgHooks;
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$variants = array( 'gan', 'gan-hans', 'gan-hant' );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
$variantfallbacks = array(
|
2010-07-29 09:43:18 +00:00
|
|
|
|
'gan' => array( 'gan-hans', 'gan-hant' ),
|
|
|
|
|
|
'gan-hans' => array( 'gan' ),
|
|
|
|
|
|
'gan-hant' => array( 'gan' ),
|
2009-03-23 19:10:28 +00:00
|
|
|
|
);
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$ml = array(
|
2009-03-23 19:10:28 +00:00
|
|
|
|
'gan' => 'disable',
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$this->mConverter = new GanConverter( $this, 'gan',
|
|
|
|
|
|
$variants, $variantfallbacks,
|
2010-01-19 02:36:33 +00:00
|
|
|
|
array(),
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$ml );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
|
|
|
|
|
|
$wgHooks['ArticleSaveComplete'][] = $this->mConverter;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* this should give much better diff info
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $text string
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2009-03-23 19:10:28 +00:00
|
|
|
|
function segmentForDiff( $text ) {
|
|
|
|
|
|
return preg_replace(
|
|
|
|
|
|
"/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
|
2010-07-29 09:43:18 +00:00
|
|
|
|
"' ' .\"$1\"", $text );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $text string
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2009-03-23 19:10:28 +00:00
|
|
|
|
function unsegmentForDiff( $text ) {
|
|
|
|
|
|
return preg_replace(
|
|
|
|
|
|
"/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
|
2010-07-29 09:43:18 +00:00
|
|
|
|
"\"$1\"", $text );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* word segmentation
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $string string
|
|
|
|
|
|
* @param $autoVariant string
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
*/
|
2010-02-02 15:09:01 +00:00
|
|
|
|
function normalizeForSearch( $string, $autoVariant = 'gan-hans' ) {
|
|
|
|
|
|
// LanguageZh::normalizeForSearch
|
|
|
|
|
|
return parent::normalizeForSearch( $string, $autoVariant );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-29 16:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $termsArray array
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
2009-03-23 19:10:28 +00:00
|
|
|
|
function convertForSearchResult( $termsArray ) {
|
|
|
|
|
|
$terms = implode( '|', $termsArray );
|
2010-01-07 04:50:32 +00:00
|
|
|
|
$terms = self::convertDoubleWidth( $terms );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
$terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
|
2010-07-29 09:43:18 +00:00
|
|
|
|
$ret = array_unique( explode( '|', $terms ) );
|
2009-03-23 19:10:28 +00:00
|
|
|
|
return $ret;
|
|
|
|
|
|
}
|
2010-01-19 02:36:33 +00:00
|
|
|
|
}
|