3 require_once( dirname( __FILE__
) . '/../LanguageConverter.php' );
4 require_once( dirname( __FILE__
) . '/LanguageZh_hans.php' );
9 class ZhConverter
extends LanguageConverter
{
12 * @param $langobj Language
13 * @param $maincode string
14 * @param $variants array
15 * @param $variantfallbacks array
17 * @param $manualLevel array
19 function __construct( $langobj, $maincode,
21 $variantfallbacks = array(),
23 $manualLevel = array() ) {
24 $this->mDescCodeSep
= ':';
25 $this->mDescVarSep
= ';';
26 parent
::__construct( $langobj, $maincode,
42 $this->mVariantNames
= array_merge( $this->mVariantNames
, $names );
45 function loadDefaultTables() {
46 require( dirname( __FILE__
) . "/../../includes/ZhConversion.php" );
47 $this->mTables
= array(
48 'zh-hans' => new ReplacementArray( $zh2Hans ),
49 'zh-hant' => new ReplacementArray( $zh2Hant ),
50 'zh-cn' => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
51 'zh-hk' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
52 'zh-mo' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
53 'zh-my' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
54 'zh-sg' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
55 'zh-tw' => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
56 'zh' => new ReplacementArray
60 function postLoadTables() {
61 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
62 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
63 $this->mTables
['zh-mo']->merge( $this->mTables
['zh-hant'] );
64 $this->mTables
['zh-my']->merge( $this->mTables
['zh-hans'] );
65 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
66 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
70 * there shouldn't be any latin text in Chinese conversion, so no need
72 * $noParse is there for compatibility with LanguageConvert::markNoConversion
75 * @param $noParse bool
79 function markNoConversion( $text, $noParse = false ) {
87 function convertCategoryKey( $key ) {
88 return $this->autoConvert( $key, 'zh' );
93 * class that handles both Traditional and Simplified Chinese
94 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
98 class LanguageZh
extends LanguageZh_hans
{
100 function __construct() {
102 parent
::__construct();
104 $variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
106 $variantfallbacks = array(
107 'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
108 'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
109 'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
110 'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ),
111 'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ),
112 'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
113 'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
114 'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
115 'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
119 'zh-hans' => 'unidirectional',
120 'zh-hant' => 'unidirectional',
123 $this->mConverter
= new ZhConverter( $this, 'zh',
124 $variants, $variantfallbacks,
128 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
132 * this should give much better diff info
134 * @param $text string
137 function segmentForDiff( $text ) {
139 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
140 "' ' .\"$1\"", $text );
144 * @param $text string
147 function unsegmentForDiff( $text ) {
149 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
154 * auto convert to zh-hans and normalize special characters.
156 * @param $string String
157 * @param $autoVariant String, default to 'zh-hans'
160 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
161 wfProfileIn( __METHOD__
);
163 // always convert to zh-hans before indexing. it should be
164 // better to use zh-hans for search, since conversion from
165 // Traditional to Simplified is less ambiguous than the
167 $s = $this->mConverter
->autoConvert( $string, $autoVariant );
168 // LanguageZh_hans::normalizeForSearch
169 $s = parent
::normalizeForSearch( $s );
170 wfProfileOut( __METHOD__
);
176 * @param $termsArray array
179 function convertForSearchResult( $termsArray ) {
180 $terms = implode( '|', $termsArray );
181 $terms = self
::convertDoubleWidth( $terms );
182 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
183 $ret = array_unique( explode( '|', $terms ) );