6ed75a90eb5f2fe3807bd17b2a3ed2f83392e66f
[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 // determine the preferred language from the request header
66 $tolang = $this->getPreferredLanguage();
67
68 $ltext = explode("-{", $text);
69 $lfirst = array_shift($ltext);
70
71 if($tolang == "cn") {
72 $text = $this->trad2simp($lfirst);
73 }
74 else {
75 $text = $this->simp2trad($lfirst);
76 }
77
78 foreach ($ltext as $i => $txt) {
79 $a = explode("}-", $txt);
80 $b = explode("zh-", $a{0});
81 if($b{1}==NULL) {
82 $text = $text.$b{0};
83 }
84 else {
85 foreach ($b as $j => $lang) {
86 if(substr($lang,0,2) == $tolang) {
87 $text = $text.substr($lang, 2);
88 break;
89 }
90 }
91 }
92 if($tolang == "cn") {
93 $text = $text.$this->trad2simp($a{1});
94 }
95 else {
96 $text = $text.$this->simp2trad($a{1});
97 }
98 }
99 return $text;
100 }
101
102
103
104
105 /* these just calls the method of the corresponding class */
106
107 function getDefaultUserOptions () {
108 return $this->mZhLang->getDefaultUserOptions();
109 }
110
111 function getBookstoreList () {
112 return $this->mZhLang->getBookstoreList() ;
113 }
114
115 function getNamespaces() {
116 return $this->mZhLang->getNamespaces();
117 }
118
119 function getNsText( $index ) {
120 return $this->mZhLang->getNsText($index);
121 }
122
123 function getNsIndex( $text ) {
124 return $this->mZhLang->getNsIndex($text);
125 }
126
127 function getQuickbarSettings() {
128 return $this->mZhLang->getQuickbarSettings();
129 }
130
131 function getSkinNames() {
132 return $this->mZhLang->getSkinNames();
133 }
134
135 function date( $ts, $adj = false )
136 {
137 return $this->mZhLang->date($ts,$adj);
138 }
139
140 function timeanddate( $ts, $adj = false )
141 {
142 return $this->mZhLang->timeanddate($ts, $adj);
143 }
144
145 function getValidSpecialPages()
146 {
147 return $this->mZhLang->getValidSpecialPages();
148 }
149
150 function getSysopSpecialPages()
151 {
152 return $this->mZhLang->getSysopSpecialPages();
153 }
154
155 function getDeveloperSpecialPages()
156 {
157 return $this->mZhLang->getDeveloperSpecialPages();
158
159 }
160
161 function getMessage( $key )
162 {
163 return $this->mZhLang->getMessage($key);
164 }
165
166 function stripForSearch( $string ) {
167 return $this->mZhLang->stripForSearch($string);
168 }
169
170
171 }
172
173
174 ?>