4d93adeb5a61cf64eea184b25cc7be5cb57fbef4
2 require_once( "LanguageUtf8.php" );
3 require_once( "LanguageZh_cn.php");
4 require_once( "LanguageZh_tw.php");
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);
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.
19 class LanguageZh
extends LanguageUtf8
{
21 var $mZhLang=false, $mZhLanguageCode=false;
23 function LanguageZh() {
24 $this->mZhLanguageCode
= $this->getPreferredVariant();
25 if($this->mZhLanguageCode
== "cn") {
26 $this->mZhLang
= new LanguageZh_cn();
29 $this->mZhLang
= new LanguageZh_tw();
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.
38 function getPreferredVariant() {
41 if($this->mZhLanguageCode
)
42 return $this->mZhLanguageCode
;
44 // get language variant preference for logged in users
45 if($wgUser->getID()!=0) {
46 $this->mZhLanguageCode
= $wgUser->getOption('variant');
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-');
54 $this->mZhLanguageCode
= substr($zh,0,5);
57 return $this->mZhLanguageCode
;
61 /* the Simplified/Traditional conversion stuff */
63 function simp2trad($text) {
65 return strtr($text, $zhSimp2Trad);
68 function trad2simp($text) {
70 return strtr($text, $zhTrad2Simp);
73 function autoConvert($text) {
74 if($this->getPreferredVariant() == "zh-cn") {
75 return $this->trad2simp($text);
78 return $this->simp2trad($text);
82 function getVariants() {
83 return array("zh-cn", "zh-tw");
87 /* these just calls the method of the corresponding class */
89 function getDefaultUserOptions () {
90 return $this->mZhLang
->getDefaultUserOptions();
93 function getBookstoreList () {
94 return $this->mZhLang
->getBookstoreList() ;
97 function getNamespaces() {
98 return $this->mZhLang
->getNamespaces();
101 function getNsText( $index ) {
102 return $this->mZhLang
->getNsText($index);
105 function getNsIndex( $text ) {
106 return $this->mZhLang
->getNsIndex($text);
109 function getQuickbarSettings() {
110 return $this->mZhLang
->getQuickbarSettings();
113 function getSkinNames() {
114 return $this->mZhLang
->getSkinNames();
117 function date( $ts, $adj = false )
119 return $this->mZhLang
->date($ts,$adj);
122 function timeanddate( $ts, $adj = false )
124 return $this->mZhLang
->timeanddate($ts, $adj);
127 function getValidSpecialPages()
129 return $this->mZhLang
->getValidSpecialPages();
132 function getSysopSpecialPages()
134 return $this->mZhLang
->getSysopSpecialPages();
137 function getDeveloperSpecialPages()
139 return $this->mZhLang
->getDeveloperSpecialPages();
143 function getMessage( $key )
145 return $this->mZhLang
->getMessage($key);
148 function stripForSearch( $string ) {
149 return $this->mZhLang
->stripForSearch($string);