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->getPreferredVariant();
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 getPreferredVariant() {
33 if($this->mZhLanguageCode
)
34 return $this->mZhLanguageCode
;
36 /* get language variant preference for logged in users */
37 if($wgUser->getID()!=0) {
38 $this->mZhLanguageCode
= $wgUser->getOption('variant');
40 else { // see if it is in the http header, otherwise default to zh_cn
41 $this->mZhLanguageCode
="zh-cn";
42 $value = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
43 $zh = explode("zh-", $value);
45 $l = array_shift($zh);
47 $this->mZhLanguageCode
= "zh-".strtolower(substr($l,0,2));
49 // also set the variant option of anons
50 $wgUser->setOption('variant', $this->mZhLanguageCode
);
52 return $this->mZhLanguageCode
;
56 /* the Simplified/Traditional conversion stuff */
58 function simp2trad($text) {
59 global $wgZhSimp2Trad;
60 return strtr($text, $wgZhSimp2Trad);
63 function trad2simp($text) {
64 global $wgZhTrad2Simp;
65 return strtr($text, $wgZhTrad2Simp);
68 function convert($text) {
70 // no conversion if redirecting
71 if(substr($text,0,9) == "#REDIRECT") {
75 // determine the preferred language from the request header
76 $tolang = $this->getPreferredVariant();
78 $ltext = explode("-{", $text);
79 $lfirst = array_shift($ltext);
81 if($tolang == "zh-cn") {
82 $text = $this->trad2simp($lfirst);
85 $text = $this->simp2trad($lfirst);
88 foreach ($ltext as $txt) {
89 $a = explode("}-", $txt);
90 $b = explode("zh-", $a{0});
95 foreach ($b as $lang) {
96 if(substr($lang,0,2) == substr($tolang,-2)) {
97 $text = $text.substr($lang, 2);
102 if($tolang == "zh-cn") {
103 $text = $text.$this->trad2simp($a{1});
106 $text = $text.$this->simp2trad($a{1});
113 function getVariants() {
114 return array("zh_cn", "zh_tw");
118 /* these just calls the method of the corresponding class */
120 function getDefaultUserOptions () {
121 return $this->mZhLang
->getDefaultUserOptions();
124 function getBookstoreList () {
125 return $this->mZhLang
->getBookstoreList() ;
128 function getNamespaces() {
129 return $this->mZhLang
->getNamespaces();
132 function getNsText( $index ) {
133 return $this->mZhLang
->getNsText($index);
136 function getNsIndex( $text ) {
137 return $this->mZhLang
->getNsIndex($text);
140 function getQuickbarSettings() {
141 return $this->mZhLang
->getQuickbarSettings();
144 function getSkinNames() {
145 return $this->mZhLang
->getSkinNames();
148 function date( $ts, $adj = false )
150 return $this->mZhLang
->date($ts,$adj);
153 function timeanddate( $ts, $adj = false )
155 return $this->mZhLang
->timeanddate($ts, $adj);
158 function getValidSpecialPages()
160 return $this->mZhLang
->getValidSpecialPages();
163 function getSysopSpecialPages()
165 return $this->mZhLang
->getSysopSpecialPages();
168 function getDeveloperSpecialPages()
170 return $this->mZhLang
->getDeveloperSpecialPages();
174 function getMessage( $key )
176 return $this->mZhLang
->getMessage($key);
179 function stripForSearch( $string ) {
180 return $this->mZhLang
->stripForSearch($string);