[FileBackend] Some documentation and minor cleanups.
[mediawiki.git] / languages / classes / LanguageGan.php
blob99b4c29e21197021784c6a00e393b7439ffd9378
1 <?php
3 require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
4 require_once( dirname( __FILE__ ) . '/LanguageZh.php' );
6 /**
7 * @ingroup Language
8 */
9 class GanConverter extends LanguageConverter {
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
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' => '繁體',
36 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
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
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
53 * @param $text string
54 * @param $noParse bool
56 * @return string
58 function markNoConversion( $text, $noParse = false ) {
59 return $text;
62 /**
63 * @param $key string
64 * @return String
66 function convertCategoryKey( $key ) {
67 return $this->autoConvert( $key, 'gan' );
71 /**
72 * class that handles both Traditional and Simplified Chinese
73 * right now it only distinguish gan_hans, gan_hant.
75 * @ingroup Language
77 class LanguageGan extends LanguageZh {
79 function __construct() {
80 global $wgHooks;
81 parent::__construct();
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' ),
89 $ml = array(
90 'gan' => 'disable',
93 $this->mConverter = new GanConverter( $this, 'gan',
94 $variants, $variantfallbacks,
95 array(),
96 $ml );
98 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
102 * this should give much better diff info
104 * @param $text string
105 * @return string
107 function segmentForDiff( $text ) {
108 return preg_replace(
109 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
110 "' ' .\"$1\"", $text );
114 * @param $text string
115 * @return string
117 function unsegmentForDiff( $text ) {
118 return preg_replace(
119 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
120 "\"$1\"", $text );
124 * word segmentation
126 * @param $string string
127 * @param $autoVariant string
128 * @return String
130 function normalizeForSearch( $string, $autoVariant = 'gan-hans' ) {
131 // LanguageZh::normalizeForSearch
132 return parent::normalizeForSearch( $string, $autoVariant );
136 * @param $termsArray array
137 * @return array
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;