关于S60 3rd资源本地化的实现

来源:互联网 发布:淘宝个人店铺过户 编辑:程序博客网 时间:2024/04/28 22:15

     以前做了一个Feisoon的项目,是基于S60 2nd开发的。现在做S60 3rd的移植,需要支持中文,所以需要进行程序本地化处理。中文的本地化还是比较麻烦的,有些朋友经常也遇到同样的问题,因此,我把自己本地化实现的过程记录下来和大家一起分享,有什么不对的地方,希望多加评论。

    首先了解一下S60资源相关知识,下面一些文件是必须了解的。rss是资源源文件;rls是定义本地化的字符串的文件,包含在资源源文件中;rh  资源头文件,包含在资源源文件中;hrh 普通的C++头文件,包含在各种源文件中。rsg 资源编译器输出的资源头文件,一般在CPP文件中需要引用;rsc 编译后的资源文件;aif是应用程序信息文件;在OS8.0以前,使用aif文件定制应用程序的信息,在OS8.0中兼容aif和registration两种文件,在OS9.0中只支持registration文件。registration文件就是我们在工程中看到的增加_reg后缀的资源源文件。一般文件名是AppName_reg.rss。所谓的本地化,就是rss资源源文件编译后支持两种或者多种语言。在此处我们用系统自带的HelloWorldBasic经典例程来实现中文的本地化。

    如果程序没有做本地化处理,那么rss文件编译后会生成rSC文件。如果程序中做了本地化处理,即在mmp文件中增加了多种语言的支持,例如支持英文和中文需要在名面怕mmp文件中做如下的实现。

START RESOURCE    HelloWorldBasic.rss
HEADER
TARGETPATH resourceapps
LANG  
01 31 
END 
//RESOURCE 

 再次编译时会发现生成了两个本地化的资源文件HelloWorldBasic.r01和HelloWorldBasic.r31。这是本地化的第一步。

   接下来需要定义本地化的字符串,这时会用到rls文件。rls文件很简单,就是存放本地化后的字符串。在这里我们创建两个rls文件。这时大家都明白了,一个是英文的rls,一个是中文的rls。在这里我定义的两个文件名为:HelloWorldBasic01.rls;HelloWorld31.rls。

英文的内容如下:

/*
* ==============================================================================
*  Name        : helloworldbasic01.rls
*  Part of     : Helloworldbasic
*  Interface   : 
*  Description : 
*  Version     : 
*
*  Copyright (c) 2005-2006 Nokia Corporation.
*  This material, including documentation and any related 
*  computer programs, is protected by copyright controlled by 
*  Nokia Corporation.
* ==============================================================================
*/


//  LOCALISATION STRINGS

//d:Caption string for app.
rls_string STRING_hewb_caption_string "HelloWorld"

//d:Short caption string for app.
rls_string STRING_hewb_short_caption_string "HW"

//d:First item in "Options" menu pane, "hello" event.
rls_string STRING_hewb_command1 "Hello"

//d:Second item in "Options" menu pane, "exit" event.
rls_string STRING_hewb_command2 "Hello from file"

//d:Third item in "Options" menu pane, "exit" event.
rls_string STRING_hewb_exit "Exit"

//d:When user requests EHelloWorldBasicCommand1 event, text below is shown.
rls_string STRING_hewb_command1_text "Hello!"

rls_string STRING_helloworldbasic_loc_resource_file_1 
"/resource/apps/HelloWorldBasic"

// End of File

中文的内容如下:

/*
* ==============================================================================
*  Name        : helloworldbasic31.rls
*  Part of     : Helloworldbasic
*  Interface   : 
*  Description : 
*  Version     : 
*
*  Copyright (c) 2005-2006 Nokia Corporation.
*  This material, including documentation and any related 
*  computer programs, is protected by copyright controlled by 
*  Nokia Corporation.
* ==============================================================================
*/


//  LOCALISATION STRINGS
CHARACTER_SET UTF8

//d:Caption string for app.
rls_string STRING_hewb_caption_string "例程"

//d:Short caption string for app.
rls_string STRING_hewb_short_caption_string "HW"

//d:First item in "Options" menu pane, "hello" event.
rls_string STRING_hewb_command1 "显示你好"

//d:Second item in "Options" menu pane, "exit" event.
rls_string STRING_hewb_command2 "从文件中显示你好"

//d:Third item in "Options" menu pane, "exit" event.
rls_string STRING_hewb_exit "退出"

//d:When user requests EHelloWorldBasicCommand1 event, text below is shown.
rls_string STRING_hewb_command1_text "你好!"

rls_string STRING_helloworldbasic_loc_resource_file_1 
"/resource/apps/HelloWorldBasic"

// End of File

这两个文件的内容大家一看就明白了。另外需要注意的一点是Symbain中文本地化的字符串文件需要使用UTF8编码。如果大家注意看上面的代码就会看到“CHARACTER_SET UTF8”这行代码。这说明此文件使用的是UTF8编码,如果采用其他编码,那么在程序中显示的就是乱码,而不是大家熟悉的中文。UTF8文件的生产可以借助一些工具来实现。我的做法是现创建一个TXT文件,TXT文件的编码是GB2312的,在用charconv 工具转换为UTF8的文件。具体的指令如下:   

charconv -input=gb2312 helloworldbasic_loc.rls -output=utf8 helloworldbasic31.rls

最后需要在rss资源源文件中根据语言环境引用不同的文件。此处用预定义宏来实现。LANGUAGE_01和LANGUAGE_31分别表示当前系统是英文或者中文系统,根据不同的系统选择不同的字符串定义文件。 

#ifdef LANGUAGE_01
#include 
"HelloWorldBasic01.rls"
#elif defined LANGUAGE_31
#include 
"HelloWorldBasic31.rls"
#endif

 现在编译运行程序,就看到一个中文的HelloWorldBasic经典程序了。

                                                                                                                                         Chris 写于2006-09-28

我的联系方式:
MSN: MSNChris.li@hotmail.com
QQ: 
360660916
Fetion号: 
435241500 (www.fetion.com.cn)
原创粉丝点击