Fixed dependencies for jquery.collapsibleTabs
[lhc/web/wiklou.git] / languages / classes / LanguageGan.php
1 <?php
2 /**
3 * Gan Chinese specific code.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Language
22 */
23
24 require_once( __DIR__ . '/../LanguageConverter.php' );
25 require_once( __DIR__ . '/LanguageZh.php' );
26
27 /**
28 * @ingroup Language
29 */
30 class GanConverter extends LanguageConverter {
31
32 /**
33 * @param $langobj Language
34 * @param $maincode string
35 * @param $variants array
36 * @param $variantfallbacks array
37 * @param $flags array
38 * @param $manualLevel array
39 */
40 function __construct( $langobj, $maincode,
41 $variants = array(),
42 $variantfallbacks = array(),
43 $flags = array(),
44 $manualLevel = array() ) {
45 $this->mDescCodeSep = ':';
46 $this->mDescVarSep = ';';
47 parent::__construct( $langobj, $maincode,
48 $variants,
49 $variantfallbacks,
50 $flags,
51 $manualLevel );
52 $names = array(
53 'gan' => '原文',
54 'gan-hans' => '简体',
55 'gan-hant' => '繁體',
56 );
57 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
58 }
59
60 function loadDefaultTables() {
61 require( __DIR__ . "/../../includes/ZhConversion.php" );
62 $this->mTables = array(
63 'gan-hans' => new ReplacementArray( $zh2Hans ),
64 'gan-hant' => new ReplacementArray( $zh2Hant ),
65 'gan' => new ReplacementArray
66 );
67 }
68
69 /**
70 * there shouldn't be any latin text in Chinese conversion, so no need
71 * to mark anything.
72 * $noParse is there for compatibility with LanguageConvert::markNoConversion
73 *
74 * @param $text string
75 * @param $noParse bool
76 *
77 * @return string
78 */
79 function markNoConversion( $text, $noParse = false ) {
80 return $text;
81 }
82
83 /**
84 * @param $key string
85 * @return String
86 */
87 function convertCategoryKey( $key ) {
88 return $this->autoConvert( $key, 'gan' );
89 }
90 }
91
92 /**
93 * class that handles both Traditional and Simplified Chinese
94 * right now it only distinguish gan_hans, gan_hant.
95 *
96 * @ingroup Language
97 */
98 class LanguageGan extends LanguageZh {
99
100 function __construct() {
101 global $wgHooks;
102 parent::__construct();
103
104 $variants = array( 'gan', 'gan-hans', 'gan-hant' );
105 $variantfallbacks = array(
106 'gan' => array( 'gan-hans', 'gan-hant' ),
107 'gan-hans' => array( 'gan' ),
108 'gan-hant' => array( 'gan' ),
109 );
110 $ml = array(
111 'gan' => 'disable',
112 );
113
114 $this->mConverter = new GanConverter( $this, 'gan',
115 $variants, $variantfallbacks,
116 array(),
117 $ml );
118
119 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
120 }
121
122 /**
123 * this should give much better diff info
124 *
125 * @param $text string
126 * @return string
127 */
128 function segmentForDiff( $text ) {
129 return preg_replace(
130 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
131 "' ' .\"$1\"", $text );
132 }
133
134 /**
135 * @param $text string
136 * @return string
137 */
138 function unsegmentForDiff( $text ) {
139 return preg_replace(
140 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
141 "\"$1\"", $text );
142 }
143
144 /**
145 * word segmentation
146 *
147 * @param $string string
148 * @param $autoVariant string
149 * @return String
150 */
151 function normalizeForSearch( $string, $autoVariant = 'gan-hans' ) {
152 // LanguageZh::normalizeForSearch
153 return parent::normalizeForSearch( $string, $autoVariant );
154 }
155
156 /**
157 * @param $termsArray array
158 * @return array
159 */
160 function convertForSearchResult( $termsArray ) {
161 $terms = implode( '|', $termsArray );
162 $terms = self::convertDoubleWidth( $terms );
163 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
164 $ret = array_unique( explode( '|', $terms ) );
165 return $ret;
166 }
167 }