Caching the conversion tables, just like the caching of the UTF-8 case conversion...
[lhc/web/wiklou.git] / languages / LanguageZh.php
1 <?php
2 require_once( "LanguageUtf8.php" );
3 require_once( "LanguageZh_cn.php");
4 require_once( "LanguageZh_tw.php");
5
6 /* caching the conversion tables */
7 $zhSimp2Trad = $wgMemc->get($key1 = "$wgDBname:zhConvert:s2t");
8 $zhTrad2Simp = $wgMemc->get($key2 = "$wgDBname:zhConvert:t2s");
9 if(empty($zhSimp2Trad) || empty($zhTrad2Simp)) {
10 require_once("includes/ZhConversion.php");
11 $wgMemc->set($key1, $zhSimp2Trad);
12 $wgMemc->set($key2, $zhTrad2Simp);
13 }
14
15 /* class that handles both Traditional and Simplified Chinese
16 right now it only distinguish zh_cn and zh_tw (actuall, zh_cn and
17 non-zh_cn), will add support for zh_sg, zh_hk, etc, later.
18 */
19 class LanguageZh extends LanguageUtf8 {
20
21 var $mZhLang=false, $mZhLanguageCode=false;
22
23 function LanguageZh() {
24 $this->mZhLanguageCode = $this->getPreferredVariant();
25 if($this->mZhLanguageCode == "cn") {
26 $this->mZhLang = new LanguageZh_cn();
27 }
28 else {
29 $this->mZhLang = new LanguageZh_tw();
30 }
31 }
32
33 /*
34 get preferred language variants. eventually this will check the
35 user's preference setting as well, once the language option in
36 the setting pages is finalized.
37 */
38 function getPreferredVariant() {
39 global $wgUser;
40
41 if($this->mZhLanguageCode)
42 return $this->mZhLanguageCode;
43
44 // get language variant preference for logged in users
45 if($wgUser->getID()!=0) {
46 $this->mZhLanguageCode = $wgUser->getOption('variant');
47 }
48 else {
49 // see if some zh- variant is set in the http header,
50 $this->mZhLanguageCode="zh-cn";
51 $header = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
52 $zh = strstr($header, 'zh-');
53 if($zh) {
54 $this->mZhLanguageCode = substr($zh,0,5);
55 }
56 }
57 return $this->mZhLanguageCode;
58 }
59
60
61 /* the Simplified/Traditional conversion stuff */
62
63 function simp2trad($text) {
64 global $zhSimp2Trad;
65 return strtr($text, $zhSimp2Trad);
66 }
67
68 function trad2simp($text) {
69 global $zhTrad2Simp;
70 return strtr($text, $zhTrad2Simp);
71 }
72
73 function autoConvert($text) {
74 if($this->getPreferredVariant() == "zh-cn") {
75 return $this->trad2simp($text);
76 }
77 else {
78 return $this->simp2trad($text);
79 }
80 }
81
82 function getVariants() {
83 return array("zh-cn", "zh-tw");
84 }
85
86
87 /* these just calls the method of the corresponding class */
88
89 function getDefaultUserOptions () {
90 return $this->mZhLang->getDefaultUserOptions();
91 }
92
93 function getBookstoreList () {
94 return $this->mZhLang->getBookstoreList() ;
95 }
96
97 function getNamespaces() {
98 return $this->mZhLang->getNamespaces();
99 }
100
101 function getNsText( $index ) {
102 return $this->mZhLang->getNsText($index);
103 }
104
105 function getNsIndex( $text ) {
106 return $this->mZhLang->getNsIndex($text);
107 }
108
109 function getQuickbarSettings() {
110 return $this->mZhLang->getQuickbarSettings();
111 }
112
113 function getSkinNames() {
114 return $this->mZhLang->getSkinNames();
115 }
116
117 function date( $ts, $adj = false )
118 {
119 return $this->mZhLang->date($ts,$adj);
120 }
121
122 function timeanddate( $ts, $adj = false )
123 {
124 return $this->mZhLang->timeanddate($ts, $adj);
125 }
126
127 function getValidSpecialPages()
128 {
129 return $this->mZhLang->getValidSpecialPages();
130 }
131
132 function getSysopSpecialPages()
133 {
134 return $this->mZhLang->getSysopSpecialPages();
135 }
136
137 function getDeveloperSpecialPages()
138 {
139 return $this->mZhLang->getDeveloperSpecialPages();
140
141 }
142
143 function getMessage( $key )
144 {
145 return $this->mZhLang->getMessage($key);
146 }
147
148 function stripForSearch( $string ) {
149 return $this->mZhLang->stripForSearch($string);
150 }
151
152
153 }
154
155
156 ?>