Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
50.62% |
41 / 81 |
|
40.00% |
4 / 10 |
CRAP | |
0.00% |
0 / 1 |
ZhConverter | |
50.62% |
41 / 81 |
|
40.00% |
4 / 10 |
22.04 | |
0.00% |
0 / 1 |
getMainCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLanguageVariants | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
getVariantsFallbacks | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
getAdditionalManualLevel | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getDescCodeSeparator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDescVarSeparator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getVariantNames | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
loadDefaultTables | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
postLoadTables | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
convertCategoryKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | use MediaWiki\Language\LanguageConverter; |
22 | use MediaWiki\Language\ReplacementArray; |
23 | |
24 | /** |
25 | * Chinese converter routine. |
26 | * |
27 | * @ingroup Languages |
28 | */ |
29 | class ZhConverter extends LanguageConverter { |
30 | |
31 | public function getMainCode(): string { |
32 | return 'zh'; |
33 | } |
34 | |
35 | public function getLanguageVariants(): array { |
36 | return [ |
37 | 'zh', |
38 | 'zh-hans', |
39 | 'zh-hant', |
40 | 'zh-cn', |
41 | 'zh-hk', |
42 | 'zh-mo', |
43 | 'zh-my', |
44 | 'zh-sg', |
45 | 'zh-tw' |
46 | ]; |
47 | } |
48 | |
49 | public function getVariantsFallbacks(): array { |
50 | return [ |
51 | 'zh' => [ |
52 | 'zh-hans', |
53 | 'zh-hant', |
54 | 'zh-cn', |
55 | 'zh-tw', |
56 | 'zh-hk', |
57 | 'zh-sg', |
58 | 'zh-mo', |
59 | 'zh-my' |
60 | ], |
61 | 'zh-hans' => [ 'zh-cn', 'zh-sg', 'zh-my' ], |
62 | 'zh-hant' => [ 'zh-tw', 'zh-hk', 'zh-mo' ], |
63 | 'zh-cn' => [ 'zh-hans', 'zh-sg', 'zh-my' ], |
64 | 'zh-sg' => [ 'zh-my', 'zh-hans', 'zh-cn' ], |
65 | 'zh-my' => [ 'zh-sg', 'zh-hans', 'zh-cn' ], |
66 | 'zh-tw' => [ 'zh-hant', 'zh-hk', 'zh-mo' ], |
67 | 'zh-hk' => [ 'zh-mo', 'zh-hant', 'zh-tw' ], |
68 | 'zh-mo' => [ 'zh-hk', 'zh-hant', 'zh-tw' ], |
69 | ]; |
70 | } |
71 | |
72 | public function getAdditionalManualLevel(): array { |
73 | return [ |
74 | 'zh' => 'disable', |
75 | 'zh-hans' => 'unidirectional', |
76 | 'zh-hant' => 'unidirectional', |
77 | ]; |
78 | } |
79 | |
80 | public function getDescCodeSeparator(): string { |
81 | return ':'; |
82 | } |
83 | |
84 | public function getDescVarSeparator(): string { |
85 | return ';'; |
86 | } |
87 | |
88 | public function getVariantNames(): array { |
89 | $names = [ |
90 | 'zh' => '原文', |
91 | 'zh-hans' => '简体', |
92 | 'zh-hant' => '繁體', |
93 | 'zh-cn' => '大陆', |
94 | 'zh-tw' => '臺灣', |
95 | 'zh-hk' => '香港', |
96 | 'zh-mo' => '澳門', |
97 | 'zh-sg' => '新加坡', |
98 | 'zh-my' => '大马', |
99 | ]; |
100 | return array_merge( parent::getVariantNames(), $names ); |
101 | } |
102 | |
103 | protected function loadDefaultTables(): array { |
104 | return [ |
105 | 'zh-hans' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_HANS ), |
106 | 'zh-hant' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_HANT ), |
107 | 'zh-cn' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_CN ), |
108 | 'zh-hk' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_HK ), |
109 | 'zh-mo' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_HK ), |
110 | 'zh-my' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_CN ), |
111 | 'zh-sg' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_CN ), |
112 | 'zh-tw' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_TW ), |
113 | 'zh' => new ReplacementArray |
114 | ]; |
115 | } |
116 | |
117 | protected function postLoadTables( &$tables ) { |
118 | $tables['zh-cn']->setArray( |
119 | $tables['zh-cn']->getArray() + $tables['zh-hans']->getArray() |
120 | ); |
121 | $tables['zh-hk']->setArray( |
122 | $tables['zh-hk']->getArray() + $tables['zh-hant']->getArray() |
123 | ); |
124 | $tables['zh-mo']->setArray( |
125 | $tables['zh-mo']->getArray() + $tables['zh-hant']->getArray() |
126 | ); |
127 | $tables['zh-my']->setArray( |
128 | $tables['zh-my']->getArray() + $tables['zh-hans']->getArray() |
129 | ); |
130 | $tables['zh-sg']->setArray( |
131 | $tables['zh-sg']->getArray() + $tables['zh-hans']->getArray() |
132 | ); |
133 | $tables['zh-tw']->setArray( |
134 | $tables['zh-tw']->getArray() + $tables['zh-hant']->getArray() |
135 | ); |
136 | } |
137 | |
138 | public function convertCategoryKey( $key ) { |
139 | return $this->autoConvert( $key, 'zh' ); |
140 | } |
141 | } |