b450a7a5d13b1281159ca83b4144594f8e0519b6
[lhc/web/wiklou.git] / languages / LanguageZh.php
1 <?php
2 require_once( "LanguageZh_cn.php");
3 require_once( "LanguageZh_tw.php");
4
5 /* caching the conversion tables */
6 $zhSimp2Trad = $wgMemc->get($key1 = "$wgDBname:zhConvert:s2t");
7 $zhTrad2Simp = $wgMemc->get($key2 = "$wgDBname:zhConvert:t2s");
8 if(empty($zhSimp2Trad) || empty($zhTrad2Simp)) {
9 require_once("includes/ZhConversion.php");
10 $wgMemc->set($key1, $zhSimp2Trad);
11 $wgMemc->set($key2, $zhTrad2Simp);
12 }
13
14 /* class that handles both Traditional and Simplified Chinese
15 right now it only distinguish zh_cn and zh_tw (actuall, zh_cn and
16 non-zh_cn), will add support for zh_sg, zh_hk, etc, later.
17 */
18 class LanguageZh extends LanguageZh_cn {
19
20 var $mZhLanguageCode=false;
21
22 function LanguageZh() {
23 $this->mZhLanguageCode = $this->getPreferredVariant();
24 }
25
26 /*
27 get preferred language variants. eventually this will check the
28 user's preference setting as well, once the language option in
29 the setting pages is finalized.
30 */
31 function getPreferredVariant() {
32 global $wgUser;
33
34 if($this->mZhLanguageCode)
35 return $this->mZhLanguageCode;
36
37 // get language variant preference for logged in users
38 if($wgUser->getID()!=0) {
39 $this->mZhLanguageCode = $wgUser->getOption('variant');
40 }
41 else {
42 // see if some zh- variant is set in the http header,
43 $this->mZhLanguageCode="zh-cn";
44 $header = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
45 $zh = strstr($header, 'zh-');
46 if($zh) {
47 $this->mZhLanguageCode = substr($zh,0,5);
48 }
49 }
50 return $this->mZhLanguageCode;
51 }
52
53
54 /* the Simplified/Traditional conversion stuff */
55
56 function simp2trad($text) {
57 global $zhSimp2Trad;
58 return strtr($text, $zhSimp2Trad);
59 }
60
61 function trad2simp($text) {
62 global $zhTrad2Simp;
63 return strtr($text, $zhTrad2Simp);
64 }
65
66 function autoConvert($text, $toVariant=false) {
67 if(!$toVariant)
68 $toVariant = $this->getPreferredVariant();
69
70 if($toVariant == "zh-cn") {
71 return $this->trad2simp($text);
72 }
73 else {
74 return $this->simp2trad($text);
75 }
76 }
77
78 function getVariants() {
79 return array("zh-cn", "zh-tw");
80 }
81 }
82 ?>