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(),
16 $manualLevel = array() ) {
17 $this->mDescCodeSep
= ':';
18 $this->mDescVarSep
= ';';
19 parent
::__construct($langobj, $maincode,
36 $this->mVariantNames
= array_merge($this->mVariantNames
,$names);
39 function loadDefaultTables() {
40 require( dirname(__FILE__
)."/../../includes/ZhConversion.php" );
41 $this->mTables
= array(
42 'zh-hans' => new ReplacementArray( $zh2Hans ),
43 'zh-hant' => new ReplacementArray( $zh2Hant ),
44 'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
45 'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
46 'zh-mo' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
47 'zh-my' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
48 'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
49 'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
50 'zh' => new ReplacementArray
54 function postLoadTables() {
55 $this->mTables
['zh-cn']->merge( $this->mTables
['zh-hans'] );
56 $this->mTables
['zh-hk']->merge( $this->mTables
['zh-hant'] );
57 $this->mTables
['zh-mo']->merge( $this->mTables
['zh-hant'] );
58 $this->mTables
['zh-my']->merge( $this->mTables
['zh-hans'] );
59 $this->mTables
['zh-sg']->merge( $this->mTables
['zh-hans'] );
60 $this->mTables
['zh-tw']->merge( $this->mTables
['zh-hant'] );
63 /* there shouldn't be any latin text in Chinese conversion, so no need
65 $noParse is there for compatibility with LanguageConvert::markNoConversion
67 function markNoConversion($text, $noParse = false) {
71 function convertCategoryKey( $key ) {
72 return $this->autoConvert( $key, 'zh' );
77 * class that handles both Traditional and Simplified Chinese
78 * right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
82 class LanguageZh
extends LanguageZh_hans
{
84 function __construct() {
86 parent
::__construct();
88 $variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
89 $variantfallbacks = array(
90 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
91 'zh-hans' => array('zh-cn','zh-sg','zh-my'),
92 'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
93 'zh-cn' => array('zh-hans','zh-sg','zh-my'),
94 'zh-sg' => array('zh-hans','zh-cn','zh-my'),
95 'zh-my' => array('zh-hans','zh-sg','zh-cn'),
96 'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
97 'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
98 'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
102 'zh-hans' => 'unidirectional',
103 'zh-hant' => 'unidirectional',
106 $this->mConverter
= new ZhConverter( $this, 'zh',
107 $variants, $variantfallbacks,
111 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
114 # this should give much better diff info
115 function segmentForDiff( $text ) {
117 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
118 "' ' .\"$1\"", $text);
121 function unsegmentForDiff( $text ) {
123 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
128 function stripForSearch( $string ) {
129 $fname="LanguageZh::stripForSearch";
130 wfProfileIn( $fname );
132 // eventually this should be a word segmentation
133 // for now just treat each character as a word
135 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
136 "' ' .\"$1\"", $string);
138 //always convert to zh-hans before indexing. it should be
139 //better to use zh-hans for search, since conversion from
140 //Traditional to Simplified is less ambiguous than the
143 $t = $this->mConverter
->autoConvert($t, 'zh-hans');
144 $t = parent
::stripForSearch( $t );
145 wfProfileOut( $fname );
150 function convertForSearchResult( $termsArray ) {
151 $terms = implode( '|', $termsArray );
152 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
153 $ret = array_unique( explode('|', $terms) );