多语言支持篇
(1)复制Yii Framework/ messages下的config文件到项目 的protected/messages目录下,支持的语言根据需要进行修改(比如需要中、繁,英):
'languages' => array('zh_cn', 'zh_tw', 'en'),
'sourceLanguage' => 'zh_cn',
(2)在protected/components/Controller.php添加方法
public function init() {
if (isset($_GET['setlang'])) {
setcookie("setlang", $_GET['setlang'], time() + 3600, '/');
$_COOKIE['setlang'] = $_GET['setlang'];
}
if (isset($_COOKIE['setlang'])) {
Yii::app()->language = $_COOKIE['setlang'];
}
}
//额外的知识点,输出调试方法,在项目全局$this->pr()可以调用调试程序: public function pr($pr, $exit = false) {
echo '<pre>';
print_r($pr);
echo '</pre>';
if ($exit) {
exit();
}
}
(3)在protected/config/main.php最前面添加代码:
if (isset($_GET['setlang']) && !empty($_GET['setlang'])) {
setcookie("setlang", $_GET['setlang'], time() + 3600, '/');
$_COOKIE['setlang'] = $_GET['setlang'];
}
数组可添加:
'language'=>'zh_cn',
'sourceLanguage'=>'en',
(4)方法一:页面下拉框根据用户设置
<select name="footer_preferedlanguage" onChange="window.location='?setlang='+this.options[this.selectedIndex].value">
<option value="" <?php if (isset($_GET['setlang']) && $_GET['setlang'] == '') echo 'selected';?> ><?php echo Yii::t('index', 'Choose your preferred language') ?></option>
<option value="zh_cn" <?php if (isset($_GET['setlang']) && $_GET['setlang'] == 'zh_cn') echo 'selected';?>>中文(简体)</option>
<option value="en" <?php if (isset($_GET['setlang']) && $_GET['setlang'] == 'en') echo 'selected';?>>English</option>
</select>
方法二:在页面菜单里切换
<div>
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'setLang',
'enableAjaxValidation' => false,
'action' => Yii::app()->request->baseUrl . '/user/setLangMenu', 'htmlOptions' => array('class' => 'regform'),
));
$userInfo = Yii::app()->session->get('userInfo');
$user = User::model()->findByPk($userInfo['userID']);
echo CHtml::hiddenField('User[prefLang]', $user->prefLang); $this->endWidget();
?>
<ul class="language">
<li class="aa <?php echo ($user->prefLang == 'zh_tw') ? 'kk' : '' ?>" onclick="changeLang('zh_tw');">繁</li>
<li class="aa <?php echo ($user->prefLang == 'zh_cn') ? 'kk' : '' ?>" onclick="changeLang('zh_cn');">简</li>
<li class="aa <?php echo ($user->prefLang == 'en') ? 'kk' : '' ?>" onclick="changeLang('en');">EN</li>
</ul>
</div>
添加JS控制:
<script type="text/javascript" charset="utf-8">
function changeLang(lang){
$("#User_prefLang").val(lang);
$("#setLang").submit();
}
$(".language li").bind({
mousedown:function(){
$(".language li").removeClass("kk");
$(this).addClass("kk");
},
mouseout:function(){
$(".language li").removeClass("kk1");
},
mouseover:function(){
$(this).addClass("kk1");
}
});
</script>
样式效果加到<head>
<style>
.language{
margin:0px;
padding:0px;
margin-top:10px;
margin-right:80px;
float:right;
}
.language li{
margin:0px;
padding:0px;
list-style:none;
float:left;
margin-right:10px;
display:block;
font-size:15px;
padding:2px;
color:#ABC8A8;
cursor:pointer;
}
.aa{
border:1px solid transparent;
font-weight: bold;
}
.kk,.kk1{
border:1px solid #7d8892;
border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px; }
</style>
在源文件的CSS/main.css有一些样式也可以根据效果调整 #mainmenu ul li a
{
} color:#ffffff; background-color:transparent; font-size:12px; font-weight:bold; text-decoration:none; padding:5px 8px;
(5)在protected/messages目录下新建各种语言的文件夹,如中、英,繁就建文件夹名为zh_cn、en、zh_tw 文件夹新建php翻译文件,文件内容是数组形式(如中文翻译):
return array(
'Home'=>'首页',
'Login'=>'登录',
'Logout'=>'退出',
'Contact'=>'联系我们',
'About'=>'公告',
'User'=>'用户',
'View file:'=>'视图文件:',
'Layout file:'=>'布局文件:',
'For more details on how to further develop this application, please read the'=>'更多详细应用的开发,请阅读',
'documentation'=>'说明文档',
'Feel free to ask in the'=>'如果您有任何问题,可以在',
'forum'=>'论坛',
'should you have any questions.'=>'自由询问。',
'Welcome to'=>'欢迎',
'Choose your preferred language' => '选择您的语言',
'Congratulations! You have successfully created your Yii application.'=>'恭喜!您已经成功创建你的Yii应用程序。',
'You may change the content of this page by modifying the following two files:'=>'你可以修改当前页的目录通过修改下面的两个文件:',
);
(6)在所有需要翻译页面输出的文字用方法Yii::t(‘翻译文件名’,’翻译文件里数组的KEY’) 例如:<?php echo Yii::t('index','View file:') ?> ,页面选择了中文,则在messages/zh_cn/index.php文件找数组key为‘View file:‘对应的翻译‘视图文件:‘作为页面输出。
在”Catalog Item View”中选择支持MUI的组件,选择”Core
OS”->”CEBASE”->”International”->”Multilingual User Interface(MUI)”
选择菜单的Platform->Setting…,在弹出的对话框中的Custom Build Actions页的下拉框中选择Pre-Make Image
2.点击New…加入语句createmui XXXX,此处的XXXX表示要支持切换的语言,例如: createmui 0409,0804,0404
此处0409为英语(美国),0804为简体中文,0404为繁体中文。以“,”分隔。
运行成功后会生成一个MultiUI.bib文件,打开该文件,拷贝所有内容到common.bib文件的末尾。MutiUI.bib文件中可能包含k.coredll.dll.xxx,在common.bib文件中删除所有的k.coredll.dll.xxx项。
3.在platform.bib中添加如下语句:
#include $(_FLATRELEASEDIR)/MultiUI.bib
4.重新编译(Build and Sysgen Current BSP)。
WINCE6 同时支持简繁体
最近两星期在玩WINCE6,因产品需要,应用软件需支持简繁体,显示其中一种很好办,只需要加入相应的字库。如加入简体字库: CEBASE->International->Locale Specific
Support->Chinese(Simplified),选择字库SimSun & NSimSun(Subset 2_50),通常情况选择这个就够了,而SimSun & NSimSun这个太大,有10M左右,并把GB18030 Data Converter及Monotype Imaging AC3 Font Compression(对字体进行压缩,减小NK大小)勾上。编译烧入,简体字都能正常显示,但繁体字显示的就为框框,原因是没有添加繁体字库。
增加繁体字库:
CEBASE->International->Locale Specific
Support->Chinese(Traditional),选择MingLiU & PMingLiU(Subset 2_70),并把Monotype Imaging AC3 Font Compression勾上。编译烧入,繁体字也能正常显示。至此以为大功告成,问题出来了,发现简体字又不能正常显示,这就纳闷了,明明将简体字库添加到系统了,为啥不能显示呢?。。。。。
将繁体字库去掉,简体字又能显示出来,初步认为是注册表哪个地方有覆盖,最后发现工程下的Common.reg有疑问:
[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/FontLink/SystemLink] "Tahoma"="//Windows//simsun.ac3,NSimSun"
"Courier New"="//Windows//simsun.ac3,NSimSun" "Arial"="//Windows//simsun.ac3,NSimSun"
"Times New Roman"="//Windows//simsun.ac3,NSimSun" "Symbol"="//Windows//simsun.ac3,NSimSun"
; @CESYSGEN ENDIF FONTS_AC3_VERSIONS
[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/FontLink/SkipTable] "Tahoma"="005c,00a5,007e,0391-03c9,2026,2116,221a,25a0-25ff"
"Arial"="005c"
"Courier New"="005c"
; @CESYSGEN ENDIF FONTS_SIMSUN
; @CESYSGEN IF FONTS_MINGLIU || FONTS_MINGLIU_2_70 || FONTS_MINGLIU_2_80 || FONTS_MINGLIU_2_90
[HKEY_LOCAL_MACHINE/SYSTEM/GDI]
"FontLinkMethods"=dword:1
; @CESYSGEN IF !FONTS_AC3_VERSIONS
; @CESYSGEN ENDIF !FONTS_AC3_VERSIONS
; @CESYSGEN IF FONTS_AC3_VERSIONS
[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/FontLink/SystemLink] "Tahoma"="//Windows//mingliu.ac3,PMingLiU"
"Courier New"="//Windows//mingliu.ac3,PMingLiU" "Arial"="//Windows//mingliu.ac3,PMingLiU"
"Times New Roman"="//Windows//mingliu.ac3,PMingLiU" "Symbol"="//Windows//mingliu.ac3,PMingLiU"
; @CESYSGEN ENDIF FONTS_AC3_VERSIONS
注意红色 标出的两个地方,
[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/FontLink/SystemLink] 键名是相同的,前面是简体字库,后面是繁体字库,这下就可以肯定后面的注册表会将前面的覆盖。汗……,难道是MS的BUG? 最后在PB帮助文档上也看到
If your run-time image includes more than one East Asian locale, you must modify the values under the SystemLink r
egistry key in common.reg to include the font
files for all of your targeted locales. You must list all of the font files by using a semi-colon separator as shown in the following example:
[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/FontLink/SystemLink]
"Arial"="//Windows//simsun.ttc,NSimSun;//Windows//msgothic.ttc,MS UI Gothic"
"Times New Roman"="//Windows//simsun.ttc,NSimSun;//Windows//msgothic.ttc,MS UI Gothic"
"Tahoma"="//Windows//simsun.ttc,NSimSun;//Windows//msgothic.ttc,MS UI Gothic"
"Courier New"="//Windows//simsun.ttc,NSimSun;//Windows//msgothic.ttc,MS UI Gothic"
"Symbol"="//Windows//simsun.ttc,NSimSun;//Windows//msgothic.ttc,MS UI Gothic"
清楚问题原因就好办了,将注册表改成
[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/FontLink/SystemLink]
"Tahoma"="//Windows//simsun.ac3,NSimSun;//Windows//mingliu.ac3,PMingLiU"
//用分号;分隔符隔开再添加繁体字库的路径信息,当时我一直以为是要去增加image的大小,没找到//原因 2010.10.12 ylh++
"Courier
New"="//Windows//simsun.ac3,NSimSun;//Windows//mingliu.ac3,PMingLiU"
"Arial"="//Windows//simsun.ac3,NSimSun;//Windows//mingliu.ac3,PMingLiU"
"Times New
Roman"="//Windows//simsun.ac3,NSimSun;//Windows//mingliu.ac3,PMingLiU"
"Symbol"="//Windows//simsun.ac3,NSimSun;//Windows//mingliu.ac3,PMingLiU"
思想是不出声的语言中国现代作家文学研究家钱钟书围城辞达则止不贵多言南宋哲学家教育家诗人朱熹时间是大公无私的语言俄罗斯作家尤邦达列夫…
语言积累名言名句类1冬天麦盖三层被来年枕着馒头睡2瑞雪兆丰年这并不是迷信有着充分的科学根据3万事俱备只欠东风4不要想着远在下面的岩…
语言积累名言名句类七上1冬天麦盖三层被来年枕着馒头睡2瑞雪兆丰年这并不是迷信有着充分的科学根据3万事俱备只欠东风4不要想着远在下面…
公务员面试经典名言语录精选100句在公务员面试中好的语言亮点是取得高分的亮点之一结合公务员面试考查范围整理经典名言警句以供在面试中…
关于行动的名言名句行动胜于语言admin20xx028浏览1806更多书中自有颜如玉书中自有黄金屋这是人们对读书的高度评价但人们对…
支持语言简体中文繁体中文英文屏幕参数双35寸1600万色触摸屏分辩率480320pxAGPS内置谷歌电子地图WIFI内置WIFI高…
在CatalogItemView中选择支持MUI的组件选择CoreOSgtCEBASEgtInternationalgtMulti…
受支持的语言和语言环境本主题包括以下两类表表1中的表每种受支持语言的个别表下表标明了AIX支持哪些语言以及AIX文档被译成了哪些语…
序号简称英文名称中文名称1arArabic阿拉伯语2bgBulgarian保加利亚语3caCatalan加泰罗尼亚语4zhCHSC…
Android开发技术讲义之对不同语言的支持Android设备有不同的大小和形状有大量的设备类型你的app也会面对大量的用户你的a…