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") {
66 // determine the preferred language from the request header
67 $tolang = $this->getPreferredLanguage();
69 $ltext = explode("-{", $text);
70 $lfirst = array_shift($ltext);
73 $text = $this->trad2simp($lfirst);
76 $text = $this->simp2trad($lfirst);
79 foreach ($ltext as $i => $txt) {
80 $a = explode("}-", $txt);
81 $b = explode("zh-", $a{0});
86 foreach ($b as $j => $lang) {
87 if(substr($lang,0,2) == $tolang) {
88 $text = $text.substr($lang, 2);
94 $text = $text.$this->trad2simp($a{1});
97 $text = $text.$this->simp2trad($a{1});
104 function getVariants() {
105 return array("zh_cn", "zh_tw");
109 /* these just calls the method of the corresponding class */
111 function getDefaultUserOptions () {
112 return $this->mZhLang
->getDefaultUserOptions();
115 function getBookstoreList () {
116 return $this->mZhLang
->getBookstoreList() ;
119 function getNamespaces() {
120 return $this->mZhLang
->getNamespaces();
123 function getNsText( $index ) {
124 return $this->mZhLang
->getNsText($index);
127 function getNsIndex( $text ) {
128 return $this->mZhLang
->getNsIndex($text);
131 function getQuickbarSettings() {
132 return $this->mZhLang
->getQuickbarSettings();
135 function getSkinNames() {
136 return $this->mZhLang
->getSkinNames();
139 function date( $ts, $adj = false )
141 return $this->mZhLang
->date($ts,$adj);
144 function timeanddate( $ts, $adj = false )
146 return $this->mZhLang
->timeanddate($ts, $adj);
149 function getValidSpecialPages()
151 return $this->mZhLang
->getValidSpecialPages();
154 function getSysopSpecialPages()
156 return $this->mZhLang
->getSysopSpecialPages();
159 function getDeveloperSpecialPages()
161 return $this->mZhLang
->getDeveloperSpecialPages();
165 function getMessage( $key )
167 return $this->mZhLang
->getMessage($key);
170 function stripForSearch( $string ) {
171 return $this->mZhLang
->stripForSearch($string);