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 ]