Subject: [技巧] 如何在运行时为S60程序提供多国语言支持
Lee
Administrator
Rank: 9Rank: 9Rank: 9



UID 2
Digest Posts 0
Credits 18567
Posts 133
Money 189
Reading Access 200
Registered 13-3-2007
Status Offline
Post at 14-3-2007 14:39  Profile | Blog | P.M. 
如何在运行时为S60程序提供多国语言支持

我准备示范,如何使应用程序在运行时支持多国语言。下面的例子中,我使用了3种语言:英语、法语和德语。

修改MMP文件

第一步是修改MMP文件。在MMP文件中你可以看到这样一行:

LANG                SC

修改成:

LANG                01 02 03

创建3种语言文件

我们将支持3种语言,英语、法语、德语,本地文件的扩展名分别为:l01,l02和l03。你可以在本地化使用所有的字符。

修改LOC文件

现在你需要修改成下面的LOC文件

// 01 = (British) English
#ifdef LANGUAGE_01
        #include "MultiLang.l01"
#endif

// 02 = French
#ifdef LANGUAGE_02
        #include "MultiLang.l02"
#endif

// 03 = German
#ifdef LANGUAGE_03
        #include "MultiLang.l03"
#endif

修改YourAppAif.rss文件

YourAppaif.rss 文件中需要像这样本地化你的应用程序标题:

RESOURCE AIF_DATA
    {
    caption_list=
                {
                CAPTION { code=01; caption="MultiLang"; }, // Eglish
                CAPTION { code=02; caption="MultiLang"; }, // French
                CAPTION { code=03; caption="MultiLang"; }  // German
                };
               
    app_uid=0x02a5dd83;
    num_icons=2;
    embeddability=KAppNotEmbeddable;
    newfile=KAppDoesNotSupportNewFile;
    }

修改由CAknApplication继承来的类

重写CEikApplication 中的 ResourceFileName() 函数到你的CYourApplicationApp 类.

TFileName CMultiLangApp::ResourceFileName() const
        {
        return TFileName();
        }

修改AppUi 类

首先,你需要为AppUi 类中的 ConstructL()函数的BaseConstructL() 中传递ENonStandardResourceFile 参数:

void CMultiLangAppUi::ConstructL()
    {
    BaseConstructL( ENonStandardResourceFile );
    //...
    }

接着,在你的AppUi类中创建下列新的函数:

void CMultiLangAppUi::ChooseLanguageL(TInt aLanguageIndex)
        {
        _LIT(KResourceFileName, "MultiLang.r%02d");
        TFileName resFileName;

        resFileName.Format(KResourceFileName, aLanguageIndex);

#if !defined(__WINS__) && !defined(__WINSCW__)
        // Device
        CompleteWithAppPath(resFileName);
#else
        // Emulator
        resFileName.Insert(0, KEmulatorPath);
#endif

        if (iOffset) iCoeEnv->DeleteResourceFile(iOffset);
        iOffset = iCoeEnv->AddResourceFileL(resFileName);
        }

现在你可以调用 ChooseLanguageL([LanguageIndex]) 函数来实现语言的切换了。

修改PKG文件

添加以下几行到你的打包文件中。

"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang.r01"         -"!:\system\apps\MultiLang\MultiLang.r01"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang.r02"         -"!:\system\apps\MultiLang\MultiLang.r02"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang.r03"         -"!:\system\apps\MultiLang\MultiLang.r03"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang_caption.r01" -"!:\system\apps\MultiLang\MultiLang_caption.r01"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang_caption.r02" -"!:\system\apps\MultiLang\MultiLang_caption.r02"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang_caption.r03" -"!:\system\apps\MultiLang\MultiLang_caption.r03"

关于S60第三版,你可以查看《如何在运行时为S60 3rd程序提供多国语言支持》 这篇文章。

程序下载地址

以下是应用程序的截图:

[ Last edited by  Lee at 14-3-2007 15:03 ]


 Attachment: Your usergroup does not have permission to access attachments




有其他问题请加入Symbian开发群参与讨论:群 ①:623041已满,群②:36865776已满 请加群③:76404484
Top
Lee
Administrator
Rank: 9Rank: 9Rank: 9



UID 2
Digest Posts 0
Credits 18567
Posts 133
Money 189
Reading Access 200
Registered 13-3-2007
Status Offline
Post at 14-3-2007 14:47  Profile | Blog | P.M. 
How to provide the Multi-Language support at runtime for Series 60

I’m going to demonstrate how to make an application supports mutli-language at run time. In the following example I’ve used three language support, English, French and German.

Change the MMP file.

The first step is to make a modification in the MMP file. In the MMP file you can see one line like this:

LANG                SC

Replace that with the following line:

LANG                01 02 03

Create three localization files

As we are going to give support for three languages, English, French and German, the localization file extension should be l01, l02 and l03 respectively. You can put all the strings in this localization files.

Change the LOC file.

Now you have to change the LOC file below:

// 01 = (British) English
#ifdef LANGUAGE_01
        #include "MultiLang.l01"
#endif

// 02 = French
#ifdef LANGUAGE_02
        #include "MultiLang.l02"
#endif

// 03 = German
#ifdef LANGUAGE_03
        #include "MultiLang.l03"
#endif

Change the YourAppAif.rss file

YourAppaif.rss should be like this to localize your application’s caption:

RESOURCE AIF_DATA
    {
    caption_list=
                {
                CAPTION { code=01; caption="MultiLang"; }, // Eglish
                CAPTION { code=02; caption="MultiLang"; }, // French
                CAPTION { code=03; caption="MultiLang"; }  // German
                };
               
    app_uid=0x02a5dd83;
    num_icons=2;
    embeddability=KAppNotEmbeddable;
    newfile=KAppDoesNotSupportNewFile;
    }

Change the class derived from CAknApplication

Over-ride ResourceFileName() function from CEikApplication to your CYourApplicationApp calss.

TFileName CMultiLangApp::ResourceFileName() const
        {
        return TFileName();
        }

Changes required in the AppUi class

First of all you have to pass ENonStandardResourceFile for the function call of BaseConstructL() in your AppUi class’s ConstructL() function.

void CMultiLangAppUi::ConstructL()
    {
    BaseConstructL( ENonStandardResourceFile );
    //...
    }

Next create the following new function in your AppUi class.

void CMultiLangAppUi::ChooseLanguageL(TInt aLanguageIndex)
        {
        _LIT(KResourceFileName, "MultiLang.r%02d");
        TFileName resFileName;

        resFileName.Format(KResourceFileName, aLanguageIndex);

#if !defined(__WINS__) && !defined(__WINSCW__)
        // Device
        CompleteWithAppPath(resFileName);
#else
        // Emulator
        resFileName.Insert(0, KEmulatorPath);
#endif

        if (iOffset) iCoeEnv->DeleteResourceFile(iOffset);
        iOffset = iCoeEnv->AddResourceFileL(resFileName);
        }

Now you can change the language of the application by calling ChooseLanguageL([LanguageIndex]) function.

Changes in the PKG file

Put the following lines to your package file.

"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang.r01"         -"!:\system\apps\MultiLang\MultiLang.r01"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang.r02"         -"!:\system\apps\MultiLang\MultiLang.r02"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang.r03"         -"!:\system\apps\MultiLang\MultiLang.r03"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang_caption.r01" -"!:\system\apps\MultiLang\MultiLang_caption.r01"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang_caption.r02" -"!:\system\apps\MultiLang\MultiLang_caption.r02"
"\Symbian\7.0s\Series60_v21\Epoc32\data\z\system\apps\MultiLang\MultiLang_caption.r03" -"!:\system\apps\MultiLang\MultiLang_caption.r03"

You can download the example application from here.

Users of the S60 3rd Edition platform will find an updated version of the application here.

原文地址

[ Last edited by  Lee at 14-3-2007 15:35 ]




有其他问题请加入Symbian开发群参与讨论:群 ①:623041已满,群②:36865776已满 请加群③:76404484
Top
 


All times are GMT+8, the time now is 9-9-2010 20:21

CopyRight © Symbianx.cn 2007 Powered By Discuz! 5
Clear Cookies - Contact Us - Symbian OS系统[S60,UIQ]开发中文翻译论坛 - Archiver

本站原文版权归原文作者所有,本站译文版权归本站所有,如需转载请注明原文和译文出处,否则追究法律责任