c80a4afa560e2ddf7e09ad008e92d3c0505f34ba
2 require_once( "includes/ZhClient.php" );
3 require_once( "LanguageZh_cn.php");
4 require_once( "LanguageZh_tw.php");
5 require_once( "LanguageZh_sg.php");
6 require_once( "LanguageZh_hk.php");
8 /* class that handles both Traditional and Simplified Chinese
9 right now it only distinguish zh_cn and zh_tw (actuall, zh_cn and
10 non-zh_cn), will add support for zh_sg, zh_hk, etc, later.
12 class LanguageZh
extends LanguageZh_cn
{
14 var $mZhLanguageCode=false;
16 function LanguageZh() {
17 global $wgUseZhdaemon, $wgZhdaemonHost, $wgZhdaemonPort;
18 global $wgDisableLangConversion;
20 $this->mZhLanguageCode
= $this->getPreferredVariant();
22 $this->mZhClient
=new ZhClient($wgZhdaemonHost, $wgZhdaemonPort);
23 if(!$this->mZhClient
->isconnected())
24 $this->mZhClient
= false;
26 // fallback to fake client
27 if($this->mZhClient
== false)
28 $this->mZhClient
=new ZhClientFake();
32 get preferred language variants. eventually this will check the
33 user's preference setting as well, once the language option in
34 the setting pages is finalized.
36 function getPreferredVariant() {
39 if($this->mZhLanguageCode
)
40 return $this->mZhLanguageCode
;
42 // get language variant preference for logged in users
43 if($wgUser->getID()!=0) {
44 $this->mZhLanguageCode
= $wgUser->getOption('variant');
47 // see if some zh- variant is set in the http header,
48 $this->mZhLanguageCode
="zh-cn";
49 $header = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
50 $zh = strstr($header, 'zh-');
52 $this->mZhLanguageCode
= substr($zh,0,5);
55 return $this->mZhLanguageCode
;
60 function autoConvert($text, $toVariant=false) {
62 $toVariant = $this->getPreferredVariant();
64 wfProfileIn( $fname );
65 $t = $this->mZhClient
->convert($text, $toVariant);
66 wfProfileOut( $fname );
70 # only convert titles having more than one character
71 function convertTitle($text) {
73 if( function_exists( 'mb_strlen' ) )
74 $len = mb_strlen($text);
76 $len = strlen($text)/3;
78 return $this->autoConvert( $text);
82 function getVariants() {
83 return array("zh-cn", "zh-tw", "zh-sg", "zh-hk");
86 function getVariantFallback($v) {
88 case 'zh-cn': return 'zh-sg'; break;
89 case 'zh-sg': return 'zh-cn'; break;
90 case 'zh-tw': return 'zh-hk'; break;
91 case 'zh-hk': return 'zh-tw'; break;
96 // word segmentation through ZhClient
97 function stripForSearch( $string ) {
99 wfProfileIn( $fname );
100 $t = $this->mZhClient
->segment($string);
101 wfProfileOut( $fname );