总体来说,要实现信息翻译,需要执行如下几步:
在合适的位置调用 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 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기
