复制代码 代码如下:
class language
{
static $lanObject;
public $type; // unit , dashboard , menu ,other
public $lan; // language
private $special; // The common in the file
private function __construct()
{
if( isset($_GET['hl']) || isset($_POST['hl']) )
{
switch( isset($_GET['hl'])?$_GET['hl']:$_POST['hl'] )
{
case 'en':
$this->lan = 'en';
case 'zh':
$this->lan = 'zh';
case 'all':
$this->lan = 'all';
default:
$this->error();
}
}
else
$this->lan = isset($_COOKIE['hl']) ? $_COOKIE['hl']:'zh';
}
public static function getObject()
{
if( !(self::$lanObject instanceof self) )
self::$lanObject = new language();
return self::$lanObject;
}
public function lto($key) //$key is English
{
if( $this->lan !== 'zh' )
return $key;
if( empty($this->special) ) // if the $special is null
{
if( isset($this->type) )
$this->special = file_get_contents($this->type.'.txt');
else
return $key;
}
echo $this->search($key);
}
private function search($searchTozh) // PHP String
{
$key_start = strpos($this->special,$searchTozh);
$key_end = strpos($this->special,' ',$key_start);
$len_str = strlen($searchTozh);
$for_sub = $key_start + $len_str + 1;
return substr($this->special, $for_sub, $key_end - $for_sub);
}
}
复制代码 代码如下:
$la = language::getObject();
$la->type = 'unit';
$la->lto('min');
echo '<br/>';
$la->lto('hello');
新闻热点
疑难解答