(4)多语言支持

多语言支持篇

(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"

相关推荐