Add previous/next links to old revision pages
[mediawiki.git] / languages / LanguageZh.php
blobf7b3b3ea2e9cd3b04cd86d9a9aa007f328ac5d3f
1 <?php
2 require_once( "LanguageZh_cn.php");
3 require_once( "LanguageZh_tw.php");
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);
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.
18 class LanguageZh extends LanguageZh_cn {
20 var $mZhLanguageCode=false;
22 function LanguageZh() {
23 $this->mZhLanguageCode = $this->getPreferredVariant();
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.
31 function getPreferredVariant() {
32 global $wgUser;
34 if($this->mZhLanguageCode)
35 return $this->mZhLanguageCode;
37 // get language variant preference for logged in users
38 if($wgUser->getID()!=0) {
39 $this->mZhLanguageCode = $wgUser->getOption('variant');
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);
50 return $this->mZhLanguageCode;
54 /* the Simplified/Traditional conversion stuff */
56 function simp2trad($text) {
57 global $zhSimp2Trad;
58 return strtr($text, $zhSimp2Trad);
61 function trad2simp($text) {
62 global $zhTrad2Simp;
63 return strtr($text, $zhTrad2Simp);
66 function autoConvert($text) {
67 if($this->getPreferredVariant() == "zh-cn") {
68 return $this->trad2simp($text);
70 else {
71 return $this->simp2trad($text);
75 function getVariants() {
76 return array("zh-cn", "zh-tw");