3 require_once( dirname( __FILE__
) . '/../LanguageConverter.php' );
4 require_once( dirname( __FILE__
) . '/LanguageZh_hans.php' );
9 class ZhConverter
extends LanguageConverter
{
11 function __construct( $langobj, $maincode,
13 $variantfallbacks = array(),
15 $manualLevel = array() ) {
16 $this->mDescCodeSep
= ':';
17 $this->mDescVarSep
= ';';
18 parent
::__construct( $langobj, $maincode,
34 $this->mVariantNames
= array_merge( $this->mVariantNames
, $names );
37 function loadDefaultTables() {
38 require( dirname( __FILE__
) . "/../../includes/ZhConversion.php" );
39 $this->mTables
= array(
40 'zh-hans' => new ReplacementArray( $zh2Hans ),
41 'zh-hant' => new ReplacementArray( $zh2Hant ),
42 'zh-cn' => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
43 'zh-hk' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
44 'zh-mo' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
45 'zh-my' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
46 'zh-sg' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
47 'zh-tw' => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
48 'zh' => new ReplacementArray
52 function postLoadTables() {
53 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
54 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
55 $this->mTables
['zh-mo']->merge( $this->mTables
['zh-hant'] );
56 $this->mTables
['zh-my']->merge( $this->mTables
['zh-hans'] );
57 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
58 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
61 /* there shouldn't be any latin text in Chinese conversion, so no need
63 $noParse is there for compatibility with LanguageConvert::markNoConversion
65 function markNoConversion( $text, $noParse = false ) {
69 function convertCategoryKey( $key ) {
70 return $this->autoConvert( $key, 'zh' );
75 * class that handles both Traditional and Simplified Chinese
76 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
80 class LanguageZh
extends LanguageZh_hans
{
82 function __construct() {
84 parent
::__construct();
86 $variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
88 $variantfallbacks = array(
89 'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
90 'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
91 'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
92 'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ),
93 'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ),
94 'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
95 'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
96 'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
97 'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
101 'zh-hans' => 'unidirectional',
102 'zh-hant' => 'unidirectional',
105 $this->mConverter
= new ZhConverter( $this, 'zh',
106 $variants, $variantfallbacks,
110 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
113 # this should give much better diff info
114 function segmentForDiff( $text ) {
116 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
117 "' ' .\"$1\"", $text );
120 function unsegmentForDiff( $text ) {
122 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
127 * auto convert to zh-hans and normalize special characters.
129 * @param $string String
130 * @param $autoVariant String, default to 'zh-hans'
133 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
134 wfProfileIn( __METHOD__
);
136 // always convert to zh-hans before indexing. it should be
137 // better to use zh-hans for search, since conversion from
138 // Traditional to Simplified is less ambiguous than the
140 $s = $this->mConverter
->autoConvert( $string, $autoVariant );
141 // LanguageZh_hans::normalizeForSearch
142 $s = parent
::normalizeForSearch( $s );
143 wfProfileOut( __METHOD__
);
148 function convertForSearchResult( $termsArray ) {
149 $terms = implode( '|', $termsArray );
150 $terms = self
::convertDoubleWidth( $terms );
151 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
152 $ret = array_unique( explode( '|', $terms ) );