More documentation!
[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 /**
12 * @param $langobj Language
13 * @param $maincode string
14 * @param $variants array
15 * @param $variantfallbacks array
16 * @param $flags array
17 * @param $manualLevel array
18 */
19 function __construct( $langobj, $maincode,
20 $variants = array(),
21 $variantfallbacks = array(),
22 $flags = array(),
23 $manualLevel = array() ) {
24 $this->mDescCodeSep = ':';
25 $this->mDescVarSep = ';';
26 parent::__construct( $langobj, $maincode,
27 $variants,
28 $variantfallbacks,
29 $flags,
30 $manualLevel );
31 $names = array(
32 'gan' => '原文',
33 'gan-hans' => '简体',
34 'gan-hant' => '繁體',
35 );
36 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
37 }
38
39 function loadDefaultTables() {
40 require( dirname( __FILE__ ) . "/../../includes/ZhConversion.php" );
41 $this->mTables = array(
42 'gan-hans' => new ReplacementArray( $zh2Hans ),
43 'gan-hant' => new ReplacementArray( $zh2Hant ),
44 'gan' => new ReplacementArray
45 );
46 }
47
48 /**
49 * there shouldn't be any latin text in Chinese conversion, so no need
50 * to mark anything.
51 * $noParse is there for compatibility with LanguageConvert::markNoConversion
52 *
53 * @param $text string
54 * @param $noParse bool
55 *
56 * @return string
57 */
58 function markNoConversion( $text, $noParse = false ) {
59 return $text;
60 }
61
62 /**
63 * @param $key string
64 * @return String
65 */
66 function convertCategoryKey( $key ) {
67 return $this->autoConvert( $key, 'gan' );
68 }
69 }
70
71 /**
72 * class that handles both Traditional and Simplified Chinese
73 * right now it only distinguish gan_hans, gan_hant.
74 *
75 * @ingroup Language
76 */
77 class LanguageGan extends LanguageZh {
78
79 function __construct() {
80 global $wgHooks;
81 parent::__construct();
82
83 $variants = array( 'gan', 'gan-hans', 'gan-hant' );
84 $variantfallbacks = array(
85 'gan' => array( 'gan-hans', 'gan-hant' ),
86 'gan-hans' => array( 'gan' ),
87 'gan-hant' => array( 'gan' ),
88 );
89 $ml = array(
90 'gan' => 'disable',
91 );
92
93 $this->mConverter = new GanConverter( $this, 'gan',
94 $variants, $variantfallbacks,
95 array(),
96 $ml );
97
98 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
99 }
100
101 /**
102 * this should give much better diff info
103 *
104 * @param $text string
105 * @return string
106 */
107 function segmentForDiff( $text ) {
108 return preg_replace(
109 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
110 "' ' .\"$1\"", $text );
111 }
112
113 /**
114 * @param $text string
115 * @return string
116 */
117 function unsegmentForDiff( $text ) {
118 return preg_replace(
119 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
120 "\"$1\"", $text );
121 }
122
123 /**
124 * word segmentation
125 *
126 * @param $string string
127 * @param $autoVariant string
128 * @return String
129 */
130 function normalizeForSearch( $string, $autoVariant = 'gan-hans' ) {
131 // LanguageZh::normalizeForSearch
132 return parent::normalizeForSearch( $string, $autoVariant );
133 }
134
135 /**
136 * @param $termsArray array
137 * @return array
138 */
139 function convertForSearchResult( $termsArray ) {
140 $terms = implode( '|', $termsArray );
141 $terms = self::convertDoubleWidth( $terms );
142 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
143 $ret = array_unique( explode( '|', $terms ) );
144 return $ret;
145 }
146 }