2 require_once( "LanguageUtf8.php" );
3 require_once( "LanguageZh_cn.php");
4 require_once( "LanguageZh_tw.php");
5 require_once( "ZhConversion.php");
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.
11 class LanguageZh
extends LanguageUtf8
{
13 var $mZhLang=false, $mZhLanguageCode=false;
15 function LanguageZh() {
16 $this->mZhLanguageCode
= $this->getPreferredLanguage();
17 if($this->mZhLanguageCode
== "cn") {
18 $this->mZhLang
= new LanguageZh_cn();
21 $this->mZhLang
= new LanguageZh_tw();
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.
30 function getPreferredLanguage() {
31 if($this->mZhLanguageCode
)
32 return $this->mZhLanguageCode
;
34 $this->mZhLanguageCode
="cn";
35 $value = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
36 $zh = explode("zh-", $value);
38 $l = array_shift($zh);
40 $this->mZhLanguageCode
= strtolower(substr($l,0,2));
43 return $this->mZhLanguageCode
;
47 /* the Simplified/Traditional conversion stuff */
49 function simp2trad($text) {
50 global $wgZhSimp2Trad;
51 return strtr($text, $wgZhSimp2Trad);
54 function trad2simp($text) {
55 global $wgZhTrad2Simp;
56 return strtr($text, $wgZhTrad2Simp);
59 function convert($text) {
61 // no conversion if redirecting
62 if(substr($text,0,9) == "#REDIRECT") {
65 // determine the preferred language from the request header
66 $tolang = $this->getPreferredLanguage();
68 $ltext = explode("-{", $text);
69 $lfirst = array_shift($ltext);
72 $text = $this->trad2simp($lfirst);
75 $text = $this->simp2trad($lfirst);
78 foreach ($ltext as $i => $txt) {
79 $a = explode("}-", $txt);
80 $b = explode("zh-", $a{0});
85 foreach ($b as $j => $lang) {
86 if(substr($lang,0,2) == $tolang) {
87 $text = $text.substr($lang, 2);
93 $text = $text.$this->trad2simp($a{1});
96 $text = $text.$this->simp2trad($a{1});
105 /* these just calls the method of the corresponding class */
107 function getDefaultUserOptions () {
108 return $this->mZhLang
->getDefaultUserOptions();
111 function getBookstoreList () {
112 return $this->mZhLang
->getBookstoreList() ;
115 function getNamespaces() {
116 return $this->mZhLang
->getNamespaces();
119 function getNsText( $index ) {
120 return $this->mZhLang
->getNsText($index);
123 function getNsIndex( $text ) {
124 return $this->mZhLang
->getNsIndex($text);
127 function getQuickbarSettings() {
128 return $this->mZhLang
->getQuickbarSettings();
131 function getSkinNames() {
132 return $this->mZhLang
->getSkinNames();
135 function date( $ts, $adj = false )
137 return $this->mZhLang
->date($ts,$adj);
140 function timeanddate( $ts, $adj = false )
142 return $this->mZhLang
->timeanddate($ts, $adj);
145 function getValidSpecialPages()
147 return $this->mZhLang
->getValidSpecialPages();
150 function getSysopSpecialPages()
152 return $this->mZhLang
->getSysopSpecialPages();
155 function getDeveloperSpecialPages()
157 return $this->mZhLang
->getDeveloperSpecialPages();
161 function getMessage( $key )
163 return $this->mZhLang
->getMessage($key);
166 function stripForSearch( $string ) {
167 return $this->mZhLang
->stripForSearch($string);