added the getVariant() interface to get a list of supported language variants
[lhc/web/wiklou.git] / languages / LanguageZh.php
1 <?php
2 require_once( "LanguageUtf8.php" );
3 require_once( "LanguageZh_cn.php");
4 require_once( "LanguageZh_tw.php");
5 require_once( "ZhConversion.php");
6
7 /* class that handles both Traditional and Simplified Chinese
8 right now it only distinguish zh_cn and zh_tw (actuall, zh_cn and
9 non-zh_cn), will add support for zh_sg, zh_hk, etc, later.
10 */
11 class LanguageZh extends LanguageUtf8 {
12
13 var $mZhLang=false, $mZhLanguageCode=false;
14
15 function LanguageZh() {
16 $this->mZhLanguageCode = $this->getPreferredLanguage();
17 if($this->mZhLanguageCode == "cn") {
18 $this->mZhLang = new LanguageZh_cn();
19 }
20 else {
21 $this->mZhLang = new LanguageZh_tw();
22 }
23 }
24
25 /*
26 get preferred language variants. eventually this will check the
27 user's preference setting as well, once the language option in
28 the setting pages is finalized.
29 */
30 function getPreferredLanguage() {
31 if($this->mZhLanguageCode)
32 return $this->mZhLanguageCode;
33
34 $this->mZhLanguageCode="cn";
35 $value = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
36 $zh = explode("zh-", $value);
37 array_shift($zh);
38 $l = array_shift($zh);
39 if($l != NULL) {
40 $this->mZhLanguageCode = strtolower(substr($l,0,2));
41 }
42
43 return $this->mZhLanguageCode;
44 }
45
46
47 /* the Simplified/Traditional conversion stuff */
48
49 function simp2trad($text) {
50 global $wgZhSimp2Trad;
51 return strtr($text, $wgZhSimp2Trad);
52 }
53
54 function trad2simp($text) {
55 global $wgZhTrad2Simp;
56 return strtr($text, $wgZhTrad2Simp);
57 }
58
59 function convert($text) {
60
61 // no conversion if redirecting
62 if(substr($text,0,9) == "#REDIRECT") {
63 return $text;
64 }
65
66 // determine the preferred language from the request header
67 $tolang = $this->getPreferredLanguage();
68
69 $ltext = explode("-{", $text);
70 $lfirst = array_shift($ltext);
71
72 if($tolang == "cn") {
73 $text = $this->trad2simp($lfirst);
74 }
75 else {
76 $text = $this->simp2trad($lfirst);
77 }
78
79 foreach ($ltext as $i => $txt) {
80 $a = explode("}-", $txt);
81 $b = explode("zh-", $a{0});
82 if($b{1}==NULL) {
83 $text = $text.$b{0};
84 }
85 else {
86 foreach ($b as $j => $lang) {
87 if(substr($lang,0,2) == $tolang) {
88 $text = $text.substr($lang, 2);
89 break;
90 }
91 }
92 }
93 if($tolang == "cn") {
94 $text = $text.$this->trad2simp($a{1});
95 }
96 else {
97 $text = $text.$this->simp2trad($a{1});
98 }
99 }
100
101 return $text;
102 }
103
104 function getVariants() {
105 return array("zh_cn", "zh_tw");
106 }
107
108
109 /* these just calls the method of the corresponding class */
110
111 function getDefaultUserOptions () {
112 return $this->mZhLang->getDefaultUserOptions();
113 }
114
115 function getBookstoreList () {
116 return $this->mZhLang->getBookstoreList() ;
117 }
118
119 function getNamespaces() {
120 return $this->mZhLang->getNamespaces();
121 }
122
123 function getNsText( $index ) {
124 return $this->mZhLang->getNsText($index);
125 }
126
127 function getNsIndex( $text ) {
128 return $this->mZhLang->getNsIndex($text);
129 }
130
131 function getQuickbarSettings() {
132 return $this->mZhLang->getQuickbarSettings();
133 }
134
135 function getSkinNames() {
136 return $this->mZhLang->getSkinNames();
137 }
138
139 function date( $ts, $adj = false )
140 {
141 return $this->mZhLang->date($ts,$adj);
142 }
143
144 function timeanddate( $ts, $adj = false )
145 {
146 return $this->mZhLang->timeanddate($ts, $adj);
147 }
148
149 function getValidSpecialPages()
150 {
151 return $this->mZhLang->getValidSpecialPages();
152 }
153
154 function getSysopSpecialPages()
155 {
156 return $this->mZhLang->getSysopSpecialPages();
157 }
158
159 function getDeveloperSpecialPages()
160 {
161 return $this->mZhLang->getDeveloperSpecialPages();
162
163 }
164
165 function getMessage( $key )
166 {
167 return $this->mZhLang->getMessage($key);
168 }
169
170 function stripForSearch( $string ) {
171 return $this->mZhLang->stripForSearch($string);
172 }
173
174
175 }
176
177
178 ?>