总体来说,要实现信息翻译,需要执行如下几步:
在合适的位置调用 Yii::t() ;
以 protected/messages/LocaleID/CategoryName.php 的格式创建 PHP 翻译文件。 每个文件简单的返回一个信息翻译数组。 注意,这是假设你使用默认的 CPhpMessageSource 存储翻译信息。
配置 CApplication::sourceLanguage 和 CApplication::language。
因此第一步为Application添加合适的配置:
[php]
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'sourceLanguage'=>'en',
'language'=>'zh_cn',
'name'=>'i18nDemo',
...
// application components
'components'=>array(
'coreMessages'=>array(
'basePath'=>'protected/messages',
),),
);
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'sourceLanguage'=>'en',
'language'=>'zh_cn',
'name'=>'i18nDemo',
...
// application components
'components'=>array(
'coreMessages'=>array(
'basePath'=>'protected/messages',
),),
);
源语言为en,目录语言为中文(zh_cn) ,翻译信息的目录为protected/messages.
然后再protected/messages 创建zh_cn 目录,如果还需要支持其它语言,可以创建相应的目录,然后在zh_cn创建一个yii.php ,其中yii 做为翻译时的分类名(你可以选择你自己喜欢的名字)。
检查代码中需要翻译的地方,然后在yii.php 文件中定义对应的翻译:
[php]
return array (
'Application Name' => '应用程序名称',
'Greetings from Santa'=>'来自圣诞老人的问候',
'firstName'=>'名',
'lastName'=>'姓',
'Choose your Christmas Gift'=>'选择你喜欢的圣诞礼物',
'iPad'=>'iPad',
'Remote control helicopter'=>'遥控直升飞机',
'60 inch 3D LED TV'=>'60寸3D LED电视',
'Holy Bible'=>'圣经',
'Choose your Christmas dinner'=>'选择你圣诞节晚餐',
'Egg'=>'鸡蛋',
'Ham'=>'火腿',
'Chicken'=>'鸡',
'Pork'=>'猪肉',
'Beer'=>'啤酒',
'Coke'=>'可乐',
'Wine'=>'白酒',
'Submit'=>'提交',
'Merry Christmas'=>'圣诞快乐',
'On Christmas Day,You will be given'=>'圣诞节那天你将获得',
'And you will have'=>'你可以有',
'for Christmas dinner'=>'作为圣诞晚餐',
'Start Again'=>'重新选择'
);
1
然后将原先使用英文字符串的地方换成yii::t('yii',xxx);比如DataModel.php
1
public function getGifts()
{
return array(
'1'=>Yii::t('yii','iPad'),
'2'=>Yii::t('yii','Remote control helicopter'),
'3'=>Yii::t('yii','60 inch 3D LED TV'),
'4'=>Yii::t('yii','Holy Bible'),
);
}
public function getMeals()
{
return array(
'1'=>Yii::t('yii','Egg'),
'2'=>Yii::t('yii','Ham'),
'3'=>Yii::t('yii','Chicken'),
'4'=>Yii::t('yii','Pork'),
'5'=>Yii::t('yii','Beer'),
'6'=>Yii::t('yii','Coke'),
'7'=>Yii::t('yii','Wine'),
);
}
return array (
'Application Name' => '应用程序名称',
'Greetings from Santa'=>'来自圣诞老人的问候',
'firstName'=>'名',
'lastName'=>'姓',
'Choose your Christmas Gift'=>'选择你喜欢的圣诞礼物',
'iPad'=>'iPad',
'Remote control helicopter'=>'遥控直升飞机',
'60 inch 3D LED TV'=>'60寸3D LED电视',
'Holy Bible'=>'圣经',
'Choose your Christmas dinner'=>'选择你圣诞节晚餐',
'Egg'=>'鸡蛋',
'Ham'=>'火腿',
'Chicken'=>'鸡',
'Pork'=>'猪肉',
'Beer'=>'啤酒',
'Coke'=>'可乐',
'Wine'=>'白酒',
'Submit'=>'提交',
'Merry Christmas'=>'圣诞快乐',
'On Christmas Day,You will be given'=>'圣诞节那天你将获得',
'And you will have'=>'你可以有',
'for Christmas dinner'=>'作为圣诞晚餐',
'Start Again'=>'重新选择'
);
1
然后将原先使用英文字符串的地方换成yii::t('yii',xxx);比如DataModel.php
1
public function getGifts()
{
return array(
'1'=>Yii::t('yii','iPad'),
'2'=>Yii::t('yii','Remote control helicopter'),
'3'=>Yii::t('yii','60 inch 3D LED TV'),
'4'=>Yii::t('yii','Holy Bible'),
);
}
public function getMeals()
{
return array(
'1'=>Yii::t('yii','Egg'),
'2'=>Yii::t('yii','Ham'),
'3'=>Yii::t('yii','Chicken'),
'4'=>Yii::t('yii','Pork'),
'5'=>Yii::t('yii','Beer'),
'6'=>Yii::t('yii','Coke'),
'7'=>Yii::t('yii','Wine'),
);
}

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3汉化版
中文版,非常好用

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中