MediaWiki REL1_35
ZhConverter.php
Go to the documentation of this file.
1<?php
31 public function __construct( $langobj ) {
32 $this->mDescCodeSep = ':';
33 $this->mDescVarSep = ';';
34
35 $variants = [
36 'zh',
37 'zh-hans',
38 'zh-hant',
39 'zh-cn',
40 'zh-hk',
41 'zh-mo',
42 'zh-my',
43 'zh-sg',
44 'zh-tw'
45 ];
46
47 $variantfallbacks = [
48 'zh' => [ 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ],
49 'zh-hans' => [ 'zh-cn', 'zh-sg', 'zh-my' ],
50 'zh-hant' => [ 'zh-tw', 'zh-hk', 'zh-mo' ],
51 'zh-cn' => [ 'zh-hans', 'zh-sg', 'zh-my' ],
52 'zh-sg' => [ 'zh-hans', 'zh-cn', 'zh-my' ],
53 'zh-my' => [ 'zh-hans', 'zh-sg', 'zh-cn' ],
54 'zh-tw' => [ 'zh-hant', 'zh-hk', 'zh-mo' ],
55 'zh-hk' => [ 'zh-hant', 'zh-mo', 'zh-tw' ],
56 'zh-mo' => [ 'zh-hant', 'zh-hk', 'zh-tw' ],
57 ];
58 $ml = [
59 'zh' => 'disable',
60 'zh-hans' => 'unidirectional',
61 'zh-hant' => 'unidirectional',
62 ];
63
64 parent::__construct( $langobj, 'zh',
65 $variants,
66 $variantfallbacks,
67 [],
68 $ml );
69 $names = [
70 'zh' => '原文',
71 'zh-hans' => '简体',
72 'zh-hant' => '繁體',
73 'zh-cn' => '大陆',
74 'zh-tw' => '台灣',
75 'zh-hk' => '香港',
76 'zh-mo' => '澳門',
77 'zh-sg' => '新加坡',
78 'zh-my' => '大马',
79 ];
80 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
81 }
82
83 protected function loadDefaultTables() {
84 $this->mTables = [
85 'zh-hans' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2Hans ),
86 'zh-hant' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2Hant ),
87 'zh-cn' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
88 'zh-hk' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2HK ),
89 'zh-mo' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2HK ),
90 'zh-my' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
91 'zh-sg' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2CN ),
92 'zh-tw' => new ReplacementArray( MediaWiki\Languages\Data\ZhConversion::$zh2TW ),
93 'zh' => new ReplacementArray
94 ];
95 }
96
97 protected function postLoadTables() {
98 $this->mTables['zh-cn']->setArray(
99 $this->mTables['zh-cn']->getArray() + $this->mTables['zh-hans']->getArray()
100 );
101 $this->mTables['zh-hk']->setArray(
102 $this->mTables['zh-hk']->getArray() + $this->mTables['zh-hant']->getArray()
103 );
104 $this->mTables['zh-mo']->setArray(
105 $this->mTables['zh-mo']->getArray() + $this->mTables['zh-hant']->getArray()
106 );
107 $this->mTables['zh-my']->setArray(
108 $this->mTables['zh-my']->getArray() + $this->mTables['zh-hans']->getArray()
109 );
110 $this->mTables['zh-sg']->setArray(
111 $this->mTables['zh-sg']->getArray() + $this->mTables['zh-hans']->getArray()
112 );
113 $this->mTables['zh-tw']->setArray(
114 $this->mTables['zh-tw']->getArray() + $this->mTables['zh-hant']->getArray()
115 );
116 }
117
122 public function convertCategoryKey( $key ) {
123 return $this->autoConvert( $key, 'zh' );
124 }
125}
Base class for multi-variant language conversion.
autoConvert( $text, $toVariant=false)
Dictionary-based conversion.
Wrapper around strtr() that holds replacements.
__construct( $langobj)
loadDefaultTables()
Load default conversion tables.
convertCategoryKey( $key)
postLoadTables()
Hook for post processing after conversion tables are loaded.
A helper class for throttling authentication attempts.