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__
);
142 global $wgSearchType;
144 // always convert to gan-hans before indexing. it should be
145 // better to use gan-hans for search, since conversion from
146 // Traditional to Simplified is less ambiguous than the
148 $s = $this->mConverter
->autoConvert($string, 'gan-hans');
150 // Double-width roman characters: ff00-ff5f ~= 0020-007f
151 $s = preg_replace( '/\xef\xbc([\x80-\xbf])/e', 'chr((ord("$1") & 0x3f) + 0x20)', $s );
152 $s = preg_replace( '/\xef\xbd([\x80-\x99])/e', 'chr((ord("$1") & 0x3f) + 0x60)', $s );
154 if ( $wgSearchType != 'LuceneSearch' ) {
155 // eventually this should be a word segmentation;
156 // for now just treat each character as a word.
157 // Not for LuceneSearch, because LSearch will
158 // split the text to words itself.
159 // @todo Fixme: only do this for Han characters...
161 "/([\\xc0-\\xff][\\x80-\\xbf]*)/",
163 $s = preg_replace( '/ +/', ' ', $s );
168 // Do general case folding and UTF-8 armoring
169 $s = parent
::stripForSearch( $s );
170 wfProfileOut( __METHOD__
);
175 function convertForSearchResult( $termsArray ) {
176 $terms = implode( '|', $termsArray );
177 $terms = implode( '|', $this->mConverter
->autoConvertToAllVariants( $terms ) );
178 $ret = array_unique( explode('|', $terms) );