MediaWiki REL1_28
LanguageZh.php
Go to the documentation of this file.
1<?php
36 function __construct( $langobj, $maincode,
37 $variants = [],
38 $variantfallbacks = [],
39 $flags = [],
40 $manualLevel = [] ) {
41 $this->mDescCodeSep = ':';
42 $this->mDescVarSep = ';';
43 parent::__construct( $langobj, $maincode,
44 $variants,
45 $variantfallbacks,
46 $flags,
47 $manualLevel );
48 $names = [
49 'zh' => '原文',
50 'zh-hans' => '简体',
51 'zh-hant' => '繁體',
52 'zh-cn' => '大陆',
53 'zh-tw' => '台灣',
54 'zh-hk' => '香港',
55 'zh-mo' => '澳門',
56 'zh-sg' => '新加坡',
57 'zh-my' => '大马',
58 ];
59 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
60 }
61
62 function loadDefaultTables() {
63 $this->mTables = [
64 'zh-hans' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2Hans ),
65 'zh-hant' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2Hant ),
66 'zh-cn' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
67 'zh-hk' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2HK ),
68 'zh-mo' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2HK ),
69 'zh-my' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
70 'zh-sg' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
71 'zh-tw' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2TW ),
72 'zh' => new ReplacementArray
73 ];
74 }
75
76 function postLoadTables() {
77 $this->mTables['zh-cn']->setArray(
78 $this->mTables['zh-cn']->getArray() + $this->mTables['zh-hans']->getArray()
79 );
80 $this->mTables['zh-hk']->setArray(
81 $this->mTables['zh-hk']->getArray() + $this->mTables['zh-hant']->getArray()
82 );
83 $this->mTables['zh-mo']->setArray(
84 $this->mTables['zh-mo']->getArray() + $this->mTables['zh-hant']->getArray()
85 );
86 $this->mTables['zh-my']->setArray(
87 $this->mTables['zh-my']->getArray() + $this->mTables['zh-hans']->getArray()
88 );
89 $this->mTables['zh-sg']->setArray(
90 $this->mTables['zh-sg']->getArray() + $this->mTables['zh-hans']->getArray()
91 );
92 $this->mTables['zh-tw']->setArray(
93 $this->mTables['zh-tw']->getArray() + $this->mTables['zh-hant']->getArray()
94 );
95 }
96
101 function convertCategoryKey( $key ) {
102 return $this->autoConvert( $key, 'zh' );
103 }
104}
105
113 function __construct() {
114 parent::__construct();
115
116 $variants = [
117 'zh',
118 'zh-hans',
119 'zh-hant',
120 'zh-cn',
121 'zh-hk',
122 'zh-mo',
123 'zh-my',
124 'zh-sg',
125 'zh-tw'
126 ];
127
128 $variantfallbacks = [
129 'zh' => [ 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ],
130 'zh-hans' => [ 'zh-cn', 'zh-sg', 'zh-my' ],
131 'zh-hant' => [ 'zh-tw', 'zh-hk', 'zh-mo' ],
132 'zh-cn' => [ 'zh-hans', 'zh-sg', 'zh-my' ],
133 'zh-sg' => [ 'zh-hans', 'zh-cn', 'zh-my' ],
134 'zh-my' => [ 'zh-hans', 'zh-sg', 'zh-cn' ],
135 'zh-tw' => [ 'zh-hant', 'zh-hk', 'zh-mo' ],
136 'zh-hk' => [ 'zh-hant', 'zh-mo', 'zh-tw' ],
137 'zh-mo' => [ 'zh-hant', 'zh-hk', 'zh-tw' ],
138 ];
139 $ml = [
140 'zh' => 'disable',
141 'zh-hans' => 'unidirectional',
142 'zh-hant' => 'unidirectional',
143 ];
144
145 $this->mConverter = new ZhConverter( $this, 'zh',
146 $variants, $variantfallbacks,
147 [],
148 $ml );
149 }
150
157 function segmentForDiff( $text ) {
158 return preg_replace( '/[\xc0-\xff][\x80-\xbf]*/', ' $0', $text );
159 }
160
165 function unsegmentForDiff( $text ) {
166 return preg_replace( '/ ([\xc0-\xff][\x80-\xbf]*)/', '$1', $text );
167 }
168
176 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
177
178 // always convert to zh-hans before indexing. it should be
179 // better to use zh-hans for search, since conversion from
180 // Traditional to Simplified is less ambiguous than the
181 // other way around
182 $s = $this->mConverter->autoConvert( $string, $autoVariant );
183 // LanguageZh_hans::normalizeForSearch
184 $s = parent::normalizeForSearch( $s );
185 return $s;
186
187 }
188
193 function convertForSearchResult( $termsArray ) {
194 $terms = implode( '|', $termsArray );
195 $terms = self::convertDoubleWidth( $terms );
196 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
197 $ret = array_unique( explode( '|', $terms ) );
198 return $ret;
199 }
200}
Base class for language conversion.
autoConvert( $text, $toVariant=false)
Dictionary-based conversion.
Simplified Chinese.
class that handles both Traditional and Simplified Chinese right now it only distinguish zh_hans,...
convertForSearchResult( $termsArray)
segmentForDiff( $text)
this should give much better diff info
unsegmentForDiff( $text)
normalizeForSearch( $string, $autoVariant='zh-hans')
auto convert to zh-hans and normalize special characters.
static convertDoubleWidth( $string)
convert double-width roman characters to single-width.
Wrapper around strtr() that holds replacements.
loadDefaultTables()
Load default conversion tables.
convertCategoryKey( $key)
__construct( $langobj, $maincode, $variants=[], $variantfallbacks=[], $flags=[], $manualLevel=[])
postLoadTables()
Hook for post processing after conversion tables are loaded.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2710
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:1949
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
A helper class for throttling authentication attempts.