本文整理匯總了PHP中i18n::setLanguage方法的典型用法代碼示例。如果您正苦於以下問題:PHP i18n::setLanguage方法的具體用法?PHP i18n::setLanguage怎麽用?PHP i18n::setLanguage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類i18n
的用法示例。
在下文中一共展示了i18n::setLanguage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: indexAction
public function indexAction()
{
try {
echo "\r\n <br /> hello, i'm indexAction in controller_index, nice 2 meet u! <br />\r\n ";
echo "\r\n <br /> now set language to zh-cn! <br />\r\n ";
i18n::setLanguage('en-us');
echo "\r\n <br /> in english, my name is: " . i18n::get('author') . " <br />\r\n ";
echo "\r\n <br /> now set language to zh-cn! <br />\r\n ";
i18n::setLanguage('zh-cn');
echo "\r\n <br /> in chinese, my name is: " . i18n::get('author') . " <br />\r\n ";
$mDemo = new model_demo();
$uin = 10000;
$uinfo = $mDemo->getUserInfo($uin);
$uinfo2 = $mDemo->getUserInfo2($uin);
$update = $mDemo->updateInfo(6, 1);
var_dump($uinfo, $uinfo2, $update);
$confs = array('title' => 'page title', 'time' => date('Ymd H:i:s'), 'name' => 'ricolau');
log::add('error', 'im test~!');
} catch (exception_i18n $e) {
//i18n 的異常,一般是由於語言包不存在
$code = $e->getCode();
if ($code == exception_i18n::type_language_not_exist) {
echo "\r\n <br /> exception: language of " . i18n::getLanguage() . ' not exist!\\r\\n <br />';
}
echo $e->getMessage();
} catch (Exception $e) {
//如果實在還是有exception,那就捕捉到這裏吧,ignore 忽略處理的話。代碼繼續執行 $this->render(),不會白頁。
//throw $e; //如果把這個異常拋上去,當前頁麵就木有了,上層接收到的話自己處理就好了,比如報個異常啥的
$code = $e->getCode();
echo $e->getMessage();
}
//一般來說 render 這塊兒可以不用 try 和 cache,隻有 template 或 slot 不存在才會有異常而已。
//但是建議和上麵部分業務代碼的try cache 結構分離,從而可以更好的決定,如果業務數據有問題,頁麵是否還繼續render()
try {
//按變量單獨 assign
$this->assign('uinfo', $uinfo);
$this->assign('updateresult', $update);
//批量assign 一個數組可以!
$this->massign($confs);
$this->render();
} catch (exception_render $e) {
//一般來說這個exception 不會有,模板放好了就行了麽
$code = $e->getCode();
if ($code == exception_render::type_tpl_not_exist) {
echo '\\r\\n <br /> exception: template not exist!\\r\\n <br />';
} elseif ($code == exception_render::type_slot_not_exist) {
echo '\\r\\n <br /> exception: template not exist!\\r\\n <br />';
}
echo $e->getMessage();
}
// equals to $this->render('index', 'index');
return;
//絕對不要用 exit!!!!!
}
示例2: main
public function main()
{
try {
echo "\r\n <br /> hello, i'm indexAction in Controller_Index, nice 2 meet u! <br />\r\n ";
echo "\r\n <br /> now set language to zh-cn! <br />\r\n ";
i18n::setLanguage('en-us');
echo "\r\n <br /> in english, my name is: " . i18n::get('author') . " <br />\r\n ";
echo "\r\n <br /> now set language to zh-cn! <br />\r\n ";
i18n::setLanguage('zh-cn');
echo "\r\n <br /> in chinese, my name is: " . i18n::get('author') . " <br />\r\n ";
$mDemo = new Model_Demo();
$uin = 10000;
$uinfo = $mDemo->getUserInfo($uin);
$uinfo2 = $mDemo->getUserInfo2($uin);
$update = $mDemo->updateInfo(6, 1);
var_dump($uinfo, $uinfo2, $update);
} catch (Exception $e) {
Tools_Exceptionhandler::topDeal($e);
}
}
示例3: testI18n
public function testI18n()
{
i18n::setLanguage('nl');
$this->assertEquals('App Shared String', t('home|some shared string'));
$this->assertEquals('Alpha Shared String', t('alpha|some shared string'));
$this->assertEquals('Do Not Translate Me', t('Do Not Translate Me'));
}