Fixes for r60599:
[lhc/web/wiklou.git] / languages / classes / LanguageGan.php
1 <?php
2
3 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
4 require_once( dirname(__FILE__).'/LanguageZh.php' );
5
6 /**
7 * @ingroup Language
8 */
9 class GanConverter extends LanguageConverter {
10
11 function __construct($langobj, $maincode,
12 $variants=array(),
13 $variantfallbacks=array(),
14 $flags = array(),
15 $manualLevel = array() ) {
16 $this->mDescCodeSep = ':';
17 $this->mDescVarSep = ';';
18 parent::__construct($langobj, $maincode,
19 $variants,
20 $variantfallbacks,
21 $flags,
22 $manualLevel);
23 $names = array(
24 'gan' => '原文',
25 'gan-hans' => '简体',
26 'gan-hant' => '繁體',
27 );
28 $this->mVariantNames = array_merge($this->mVariantNames,$names);
29 $this->loadNamespaceTables();
30 }
31
32 function loadNamespaceTables() {
33 global $wgMetaNamespace;
34 $nsproject = $wgMetaNamespace;
35 $projecttable = array(
36 'Wikipedia' => '维基百科',
37 'Wikisource' => '维基文库',
38 'Wikinews' => '维基新闻',
39 'Wiktionary' => '维基词典',
40 'Wikibooks' => '维基教科书',
41 'Wikiquote' => '维基语录',
42 );
43 $this->mNamespaceTables['gan-hans'] = array(
44 'Media' => '媒体',
45 'Special' => '特殊',
46 'Talk' => '談詑',
47 'User' => '用户',
48 'User talk' => '用户談詑',
49 $nsproject
50 => isset($projecttable[$nsproject]) ?
51 $projecttable[$nsproject] : $nsproject,
52 $nsproject . ' talk'
53 => isset($projecttable[$nsproject]) ?
54 $projecttable[$nsproject] . '談詑' : $nsproject . '談詑',
55 'File' => '文件',
56 'File talk' => '文件談詑',
57 'MediaWiki' => 'MediaWiki',
58 'MediaWiki talk' => 'MediaWiki談詑',
59 'Template' => '模板',
60 'Template talk' => '模板談詑',
61 'Help' => '帮助',
62 'Help talk' => '帮助談詑',
63 'Category' => '分类',
64 'Category talk' => '分类談詑',
65 );
66 $this->mNamespaceTables['gan-hant'] = array_merge($this->mNamespaceTables['gan-hans']);
67 $this->mNamespaceTables['gan-hant']['File'] = '檔案';
68 $this->mNamespaceTables['gan-hant']['File talk'] = '檔案談詑';
69 $this->mNamespaceTables['gan'] = array_merge($this->mNamespaceTables['gan-hans']);
70 }
71
72 function loadDefaultTables() {
73 require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
74 $this->mTables = array(
75 'gan-hans' => new ReplacementArray( $zh2Hans ),
76 'gan-hant' => new ReplacementArray( $zh2Hant ),
77 'gan' => new ReplacementArray
78 );
79 }
80
81 /* there shouldn't be any latin text in Chinese conversion, so no need
82 to mark anything.
83 $noParse is there for compatibility with LanguageConvert::markNoConversion
84 */
85 function markNoConversion($text, $noParse = false) {
86 return $text;
87 }
88
89 function convertCategoryKey( $key ) {
90 return $this->autoConvert( $key, 'gan' );
91 }
92 }
93
94 /**
95 * class that handles both Traditional and Simplified Chinese
96 * right now it only distinguish gan_hans, gan_hant.
97 *
98 * @ingroup Language
99 */
100 class LanguageGan extends LanguageZh {
101
102 function __construct() {
103 global $wgHooks;
104 parent::__construct();
105
106 $variants = array('gan','gan-hans','gan-hant');
107 $variantfallbacks = array(
108 'gan' => array('gan-hans','gan-hant'),
109 'gan-hans' => array('gan'),
110 'gan-hant' => array('gan'),
111 );
112 $ml=array(
113 'gan' => 'disable',
114 );
115
116 $this->mConverter = new GanConverter( $this, 'gan',
117 $variants, $variantfallbacks,
118 array(),
119 $ml);
120
121 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
122 }
123
124 # this should give much better diff info
125 function segmentForDiff( $text ) {
126 return preg_replace(
127 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
128 "' ' .\"$1\"", $text);
129 }
130
131 function unsegmentForDiff( $text ) {
132 return preg_replace(
133 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
134 "\"$1\"", $text);
135 }
136
137 // word segmentation
138 function stripForSearch( $string, $doStrip = true, $autoVariant = 'gan-hans' ) {
139 // LanguageZh::stripForSearch
140 return parent::stripForSearch( $string, $doStrip, $autoVariant );
141 }
142
143 function convertForSearchResult( $termsArray ) {
144 $terms = implode( '|', $termsArray );
145 $terms = self::convertDoubleWidth( $terms );
146 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
147 $ret = array_unique( explode('|', $terms) );
148 return $ret;
149 }
150 }