phpGrace 语言包使用说明
1、添加语言包文件
位置:/分组目录/lang/语言.php 【自行创建】 命名: zh.php、en.php ,规则 : 语种.php //语言文件代码格式 <?php return array( 'APP_NAME' => 'phpGrace', 'btnname' => '提交' );
2、语言设置 $this->setLang($langType)
使用 $this->setLang($langType) 全局函数可以设置使用的语种,如:
class indexController extends grace{
public function index(){}
public function setLg(){
if(empty($this->gets[0])){exit;}
if(in_array($this->gets[0], array('zh', 'en'))){
$this->setLang($this->gets[0]);
header('location:/');
}
}
}
3、使用 lang($key) 函数获取语言
<?php
class indexController extends grace{
public function index(){
setLang('zh');
echo lang('btnname');
}
}
说明:
使用 setLang() 动态的设置语种即可达到语言包切换的目的 ^_^