2 require_once( "LanguageZh_cn.php");
4 /* caching the conversion tables */
5 $zhSimp2Trad = $wgMemc->get($key1 = "$wgDBname:zhConvert:s2t");
6 $zhTrad2Simp = $wgMemc->get($key2 = "$wgDBname:zhConvert:t2s");
7 if(empty($zhSimp2Trad) ||
empty($zhTrad2Simp)) {
8 require_once("includes/ZhConversion.php");
9 $wgMemc->set($key1, $zhSimp2Trad);
10 $wgMemc->set($key2, $zhTrad2Simp);
13 /* class that handles both Traditional and Simplified Chinese
14 right now it only distinguish zh_cn and zh_tw (actuall, zh_cn and
15 non-zh_cn), will add support for zh_sg, zh_hk, etc, later.
17 class LanguageZh
extends LanguageZh_cn
{
19 var $mZhLanguageCode=false;
21 function LanguageZh() {
22 $this->mZhLanguageCode
= $this->getPreferredVariant();
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');
41 // see if some zh- variant is set in the http header,
42 $this->mZhLanguageCode
="zh-cn";
43 $header = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
44 $zh = strstr($header, 'zh-');
46 $this->mZhLanguageCode
= substr($zh,0,5);
49 return $this->mZhLanguageCode
;
53 /* the Simplified/Traditional conversion stuff */
55 function simp2trad($text) {
57 return strtr($text, $zhSimp2Trad);
60 function trad2simp($text) {
62 return strtr($text, $zhTrad2Simp);
65 function autoConvert($text) {
66 if($this->getPreferredVariant() == "zh-cn") {
67 return $this->trad2simp($text);
70 return $this->simp2trad($text);
74 function getVariants() {
75 return array("zh-cn", "zh-tw");