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 | /** |
22 | * Chinese converter routine. |
23 | * |
24 | * @ingroup Languages |
25 | */ |
26 | class ZhConverter extends LanguageConverter { |
27 | |
28 | public function getMainCode(): string { |
29 | return 'zh'; |
30 | } |
31 | |
32 | public function getLanguageVariants(): array { |
33 | return [ |
34 | 'zh', |
35 | 'zh-hans', |
36 | 'zh-hant', |
37 | 'zh-cn', |
38 | 'zh-hk', |
39 | 'zh-mo', |
40 | 'zh-my', |
41 | 'zh-sg', |
42 | 'zh-tw' |
43 | ]; |
44 | } |
45 | |
46 | public function getVariantsFallbacks(): array { |
47 | return [ |
48 | 'zh' => [ |
49 | 'zh-hans', |
50 | 'zh-hant', |
51 | 'zh-cn', |
52 | 'zh-tw', |
53 | 'zh-hk', |
54 | 'zh-sg', |
55 | 'zh-mo', |
56 | 'zh-my' |
57 | ], |
58 | 'zh-hans' => [ 'zh-cn', 'zh-sg', 'zh-my' ], |
59 | 'zh-hant' => [ 'zh-tw', 'zh-hk', 'zh-mo' ], |
60 | 'zh-cn' => [ 'zh-hans', 'zh-sg', 'zh-my' ], |
61 | 'zh-sg' => [ 'zh-my', 'zh-hans', 'zh-cn' ], |
62 | 'zh-my' => [ 'zh-sg', 'zh-hans', 'zh-cn' ], |
63 | 'zh-tw' => [ 'zh-hant', 'zh-hk', 'zh-mo' ], |
64 | 'zh-hk' => [ 'zh-mo', 'zh-hant', 'zh-tw' ], |
65 | 'zh-mo' => [ 'zh-hk', 'zh-hant', 'zh-tw' ], |
66 | ]; |
67 | } |
68 | |
69 | public function getAdditionalManualLevel(): array { |
70 | return [ |
71 | 'zh' => 'disable', |
72 | 'zh-hans' => 'unidirectional', |
73 | 'zh-hant' => 'unidirectional', |
74 | ]; |
75 | } |
76 | |
77 | public function getDescCodeSeparator(): string { |
78 | return ':'; |
79 | } |
80 | |
81 | public function getDescVarSeparator(): string { |
82 | return ';'; |
83 | } |
84 | |
85 | public function getVariantNames(): array { |
86 | $names = [ |
87 | 'zh' => '原文', |
88 | 'zh-hans' => '简体', |
89 | 'zh-hant' => '繁體', |
90 | 'zh-cn' => '大陆', |
91 | 'zh-tw' => '臺灣', |
92 | 'zh-hk' => '香港', |
93 | 'zh-mo' => '澳門', |
94 | 'zh-sg' => '新加坡', |
95 | 'zh-my' => '大马', |
96 | ]; |
97 | return array_merge( parent::getVariantNames(), $names ); |
98 | } |
99 | |
100 | protected function loadDefaultTables(): array { |
101 | return [ |
102 | 'zh-hans' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_HANS ), |
103 | 'zh-hant' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_HANT ), |
104 | 'zh-cn' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_CN ), |
105 | 'zh-hk' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_HK ), |
106 | 'zh-mo' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_HK ), |
107 | 'zh-my' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_CN ), |
108 | 'zh-sg' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_CN ), |
109 | 'zh-tw' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::ZH_TO_TW ), |
110 | 'zh' => new ReplacementArray |
111 | ]; |
112 | } |
113 | |
114 | protected function postLoadTables( &$tables ) { |
115 | $tables['zh-cn']->setArray( |
116 | $tables['zh-cn']->getArray() + $tables['zh-hans']->getArray() |
117 | ); |
118 | $tables['zh-hk']->setArray( |
119 | $tables['zh-hk']->getArray() + $tables['zh-hant']->getArray() |
120 | ); |
121 | $tables['zh-mo']->setArray( |
122 | $tables['zh-mo']->getArray() + $tables['zh-hant']->getArray() |
123 | ); |
124 | $tables['zh-my']->setArray( |
125 | $tables['zh-my']->getArray() + $tables['zh-hans']->getArray() |
126 | ); |
127 | $tables['zh-sg']->setArray( |
128 | $tables['zh-sg']->getArray() + $tables['zh-hans']->getArray() |
129 | ); |
130 | $tables['zh-tw']->setArray( |
131 | $tables['zh-tw']->getArray() + $tables['zh-hant']->getArray() |
132 | ); |
133 | } |
134 | |
135 | public function convertCategoryKey( $key ) { |
136 | return $this->autoConvert( $key, 'zh' ); |
137 | } |
138 | } |