3 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
4 require_once( dirname(__FILE__).'/LanguageZh.php' );
9 class GanConverter extends LanguageConverter {
11 function __construct($langobj, $maincode,
13 $variantfallbacks=array(),
16 $manualLevel = array() ) {
17 $this->mDescCodeSep = ':';
18 $this->mDescVarSep = ';';
19 parent::__construct($langobj, $maincode,
30 $this->mVariantNames = array_merge($this->mVariantNames,$names);
31 $this->loadNamespaceTables();
34 function loadNamespaceTables() {
35 global $wgMetaNamespace;
36 $nsproject = $wgMetaNamespace;
37 $projecttable = array(
38 'Wikipedia' => '维基百科',
39 'Wikisource' => '维基文库',
41 'Wiktionary' => '维基词典',
42 'Wikibooks' => '维基教科书',
43 'Wikiquote' => '维基语录',
45 $this->mNamespaceTables['gan-hans'] = array(
50 'User talk' => '用户談詑',
52 => isset($projecttable[$nsproject]) ?
53 $projecttable[$nsproject] : $nsproject,
55 => isset($projecttable[$nsproject]) ?
56 $projecttable[$nsproject] . '談詑' : $nsproject . '談詑',
58 'File talk' => '文件談詑',
59 'MediaWiki' => 'MediaWiki',
60 'MediaWiki talk' => 'MediaWiki談詑',
62 'Template talk' => '模板談詑',
64 'Help talk' => '帮助談詑',
66 'Category talk' => '分类談詑',
68 $this->mNamespaceTables['gan-hant'] = array_merge($this->mNamespaceTables['gan-hans']);
69 $this->mNamespaceTables['gan-hant']['File'] = '檔案';
70 $this->mNamespaceTables['gan-hant']['File talk'] = '檔案談詑';
71 $this->mNamespaceTables['gan'] = array_merge($this->mNamespaceTables['gan-hans']);
74 function loadDefaultTables() {
75 require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
76 $this->mTables = array(
77 'gan-hans' => new ReplacementArray( $zh2Hans ),
78 'gan-hant' => new ReplacementArray( $zh2Hant ),
79 'gan' => new ReplacementArray
83 /* there shouldn't be any latin text in Chinese conversion, so no need
85 $noParse is there for compatibility with LanguageConvert::markNoConversion
87 function markNoConversion($text, $noParse = false) {
91 function convertCategoryKey( $key ) {
92 return $this->autoConvert( $key, 'gan' );
97 * class that handles both Traditional and Simplified Chinese
98 * right now it only distinguish gan_hans, gan_hant.
102 class LanguageGan extends LanguageZh {
104 function __construct() {
106 parent::__construct();
108 $variants = array('gan','gan-hans','gan-hant');
109 $variantfallbacks = array(
110 'gan' => array('gan-hans','gan-hant'),
111 'gan-hans' => array('gan'),
112 'gan-hant' => array('gan'),
118 $this->mConverter = new GanConverter( $this, 'gan',
119 $variants, $variantfallbacks,
123 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
126 # this should give much better diff info
127 function segmentForDiff( $text ) {
129 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
130 "' ' .\"$1\"", $text);
133 function unsegmentForDiff( $text ) {
135 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
140 function stripForSearch( $string ) {
141 wfProfileIn( __METHOD__ );
143 // eventually this should be a word segmentation
144 // for now just treat each character as a word
145 // @fixme only do this for Han characters...
147 "/([\\xc0-\\xff][\\x80-\\xbf]*)/",
150 //always convert to gan-hans before indexing. it should be
151 //better to use gan-hans for search, since conversion from
152 //Traditional to Simplified is less ambiguous than the
155 $t = $this->mConverter->autoConvert($t, 'gan-hans');
156 $t = parent::stripForSearch( $t );
157 wfProfileOut( __METHOD__ );
162 function convertForSearchResult( $termsArray ) {
163 $terms = implode( '|', $termsArray );
164 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
165 $ret = array_unique( explode('|', $terms) );