多语言切换
phpGrace 封装了语言包机制,可以方便地进行多语言切换;

使用流程

1 添加语言包文件

<?php 
/*
文件位置 : /分组目录/lang/语言.php [ 自行创建 ]
文件命名 : zh.php、en.php, 规则 : 语种.php
语言数据 : */
return array(
    'APPNAME'     => 'phpGrace',
    'btnName'      => '提交'
);

#1.1 分组目录/lang/zh.php

<?php
return array(
    'APPNAME'     => 'phpGrace',
    'btnName'      => '提交'
);

#1.2 分组目录/lang/en.php

<?php
return array(
    'APPNAME'     => 'phpGrace',
    'btnName'     => 'submit'
);

2、语种设置  \pgSetLang($langType)

<?php
// 如 : 在某个控制器内设置及切换语言
class indexController extends grace{
    public function index(){
        // 切换语言
        $this->initGets(0, 'zh');
        pgSetLang($this->gets[0]);
    }
}

3、获取语言 \pgGetLang($key);

<!-- 在视图文件中使用 pgGetLang 函数获取语言信息 -->
<h3><?php echo pgGetLang('APPNAME');?></h3>
<h3><?php echo pgGetLang('btnName');?></h3>
<p>
    切换语言 : <a href="/test/index/index/zh">中文</a> |
    <a href="/test/index/index/en">English</a>
</p>