MediaWiki  1.33.0
LanguageZh.php
Go to the documentation of this file.
1 <?php
27 class ZhConverter extends LanguageConverter {
36  function __construct( Language $langobj, $maincode,
37  $variants = [],
38  $variantfallbacks = [],
39  $flags = [],
40  $manualLevel = []
41  ) {
42  $this->mDescCodeSep = ':';
43  $this->mDescVarSep = ';';
44  parent::__construct( $langobj, $maincode,
45  $variants,
46  $variantfallbacks,
47  $flags,
48  $manualLevel
49  );
50  $names = [
51  'zh' => '原文',
52  'zh-hans' => '简体',
53  'zh-hant' => '繁體',
54  'zh-cn' => '大陆',
55  'zh-tw' => '台灣',
56  'zh-hk' => '香港',
57  'zh-mo' => '澳門',
58  'zh-sg' => '新加坡',
59  'zh-my' => '大马',
60  ];
61  $this->mVariantNames = array_merge( $this->mVariantNames, $names );
62  }
63 
64  function loadDefaultTables() {
65  $this->mTables = [
66  'zh-hans' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2Hans ),
67  'zh-hant' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2Hant ),
68  'zh-cn' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
69  'zh-hk' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2HK ),
70  'zh-mo' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2HK ),
71  'zh-my' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
72  'zh-sg' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
73  'zh-tw' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2TW ),
74  'zh' => new ReplacementArray
75  ];
76  }
77 
78  function postLoadTables() {
79  $this->mTables['zh-cn']->setArray(
80  $this->mTables['zh-cn']->getArray() + $this->mTables['zh-hans']->getArray()
81  );
82  $this->mTables['zh-hk']->setArray(
83  $this->mTables['zh-hk']->getArray() + $this->mTables['zh-hant']->getArray()
84  );
85  $this->mTables['zh-mo']->setArray(
86  $this->mTables['zh-mo']->getArray() + $this->mTables['zh-hant']->getArray()
87  );
88  $this->mTables['zh-my']->setArray(
89  $this->mTables['zh-my']->getArray() + $this->mTables['zh-hans']->getArray()
90  );
91  $this->mTables['zh-sg']->setArray(
92  $this->mTables['zh-sg']->getArray() + $this->mTables['zh-hans']->getArray()
93  );
94  $this->mTables['zh-tw']->setArray(
95  $this->mTables['zh-tw']->getArray() + $this->mTables['zh-hant']->getArray()
96  );
97  }
98 
103  function convertCategoryKey( $key ) {
104  return $this->autoConvert( $key, 'zh' );
105  }
106 }
107 
115  function __construct() {
116  parent::__construct();
117 
118  $variants = [
119  'zh',
120  'zh-hans',
121  'zh-hant',
122  'zh-cn',
123  'zh-hk',
124  'zh-mo',
125  'zh-my',
126  'zh-sg',
127  'zh-tw'
128  ];
129 
130  $variantfallbacks = [
131  'zh' => [ 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ],
132  'zh-hans' => [ 'zh-cn', 'zh-sg', 'zh-my' ],
133  'zh-hant' => [ 'zh-tw', 'zh-hk', 'zh-mo' ],
134  'zh-cn' => [ 'zh-hans', 'zh-sg', 'zh-my' ],
135  'zh-sg' => [ 'zh-hans', 'zh-cn', 'zh-my' ],
136  'zh-my' => [ 'zh-hans', 'zh-sg', 'zh-cn' ],
137  'zh-tw' => [ 'zh-hant', 'zh-hk', 'zh-mo' ],
138  'zh-hk' => [ 'zh-hant', 'zh-mo', 'zh-tw' ],
139  'zh-mo' => [ 'zh-hant', 'zh-hk', 'zh-tw' ],
140  ];
141  $ml = [
142  'zh' => 'disable',
143  'zh-hans' => 'unidirectional',
144  'zh-hant' => 'unidirectional',
145  ];
146 
147  $this->mConverter = new ZhConverter( $this, 'zh',
148  $variants, $variantfallbacks,
149  [],
150  $ml
151  );
152  }
153 
160  function segmentForDiff( $text ) {
161  return preg_replace( '/[\xc0-\xff][\x80-\xbf]*/', ' $0', $text );
162  }
163 
168  function unsegmentForDiff( $text ) {
169  return preg_replace( '/ ([\xc0-\xff][\x80-\xbf]*)/', '$1', $text );
170  }
171 
179  function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
180  // always convert to zh-hans before indexing. it should be
181  // better to use zh-hans for search, since conversion from
182  // Traditional to Simplified is less ambiguous than the
183  // other way around
184  $s = $this->mConverter->autoConvert( $string, $autoVariant );
185  // LanguageZh_hans::normalizeForSearch
186  $s = parent::normalizeForSearch( $s );
187  return $s;
188  }
189 
194  function convertForSearchResult( $termsArray ) {
195  $terms = implode( '|', $termsArray );
196  $terms = self::convertDoubleWidth( $terms );
197  $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
198  $ret = array_unique( explode( '|', $terms ) );
199  return $ret;
200  }
201 }
LanguageZh
class that handles both Traditional and Simplified Chinese right now it only distinguish zh_hans,...
Definition: LanguageZh.php:114
$s
$s
Definition: mergeMessageFileList.php:186
ZhConverter
Definition: LanguageZh.php:27
LanguageZh\convertForSearchResult
convertForSearchResult( $termsArray)
Definition: LanguageZh.php:194
LanguageZh\unsegmentForDiff
unsegmentForDiff( $text)
Definition: LanguageZh.php:168
php
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:35
LanguageZh\__construct
__construct()
Definition: LanguageZh.php:115
LanguageZh\segmentForDiff
segmentForDiff( $text)
this should give much better diff info
Definition: LanguageZh.php:160
MediaWiki
A helper class for throttling authentication attempts.
ZhConverter\__construct
__construct(Language $langobj, $maincode, $variants=[], $variantfallbacks=[], $flags=[], $manualLevel=[])
Definition: LanguageZh.php:36
Language\convertDoubleWidth
static convertDoubleWidth( $string)
convert double-width roman characters to single-width.
Definition: Language.php:2917
ZhConverter\postLoadTables
postLoadTables()
Definition: LanguageZh.php:78
ZhConverter\convertCategoryKey
convertCategoryKey( $key)
Definition: LanguageZh.php:103
ReplacementArray
Wrapper around strtr() that holds replacements.
Definition: ReplacementArray.php:24
$ret
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:1985
LanguageZh_hans
Simplified Chinese.
Definition: LanguageZh_hans.php:30
ZhConverter\loadDefaultTables
loadDefaultTables()
Definition: LanguageZh.php:64
LanguageZh\normalizeForSearch
normalizeForSearch( $string, $autoVariant='zh-hans')
auto convert to zh-hans and normalize special characters.
Definition: LanguageZh.php:179
Language
Internationalisation code.
Definition: Language.php:36