Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Language selection by user during application startup

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibilityArticle
Created: chenziteng (06 Oct 2009)
Last edited: hamishwillee (13 Sep 2012)



By default the Symbian/S60 applications will use the current phone language as its language, but many developers want to give the user a chance to change the application's language without changing the phone language.

"Language selection by user"


Here is a solution to let user select the preferred language during application startup.

Step 1: At the very beginning of the application startup we show a global list query to offer a list of supported languages for the user, and then we remember the user's selection in some way. In the sample project we define a P&S property to save the user's choice.

// begin by chen
#include <badesca.h>
#include <akngloballistquery.h>
#include <e32property.h>
void MainL()
_LIT(KPhoneLanugage, "Phone language");
_LIT(KEnglish, "English");
_LIT(KChinese, "Chinese");
CDesCArray* array = new(ELeave) CDesCArrayFlat(5);
// the application framework has not be created yet so we the notifier service to show the list
CAknGlobalListQuery* query = CAknGlobalListQuery::NewLC();
TRequestStatus status = KRequestPending;
query->ShowListQueryL(array, status);
TInt ret = status.Int();
// ret is the index of the user selected item
// here we map the user selection to a language code
TLanguage language = ELangEnglish;
case 0:
language = User::Language();
case 1:
language = ELangEnglish;
case 2:
language = ELangPrcChinese;
language = User::Language();
// here we define a property to hold the user selection, but this is definitely not the only way, for example you can also save it to a file.
RProperty::Define(KUidUrzpvtchApplication, 0, RProperty::EInt);
RProperty::Set(KUidUrzpvtchApplication, 0, (TInt)language);
CleanupStack::PopAndDestroy(2, array);
GLDEF_C TInt E32Main()
// begin by chen
// at this stage we have to create the cleanup stack by ourself
// Cleanup stack needed
CTrapCleanup* cleanup = CTrapCleanup::New();
TRAPD(err, MainL());
if(err != KErrNone)
_LIT(KUserPanic,"Failed to start");
User::Panic(KUserPanic, err);
delete cleanup;
// end by chen
return EikStart::RunApplication( NewApplication );

Step 2: During application framework initialization we replace the default resource file with the one selected by the user. The application's resource file can be changed from the default by overriding ResourceFileName(), see below.

#include <coeutils.h>
TFileName CUrzpvtchApplication::ResourceFileName() const
TFileName filename = CAknApplication::ResourceFileName();
TInt language = 0;
TInt err = RProperty::Get(KUidUrzpvtchApplication, 0, language);
TFileName fn = filename;
_LIT(KExtFormat, "r%d");
TBuf<16> buf;
buf.Format(KExtFormat, language);
if(buf.Length()<=2) // for example "r1"
_LIT(KZero, "0");
buf.Insert(1, KZero); // now should be "r01"
TInt pos = fn.LocateReverse('.');
fn.SetLength(pos+1); // remove the extention
fn.Append(buf); // add new extention
// make sure that the filename actually exists, or there will be a User 23 panic
TBool exists = ConeUtils::FileExists(fn);
return filename;

Source Code

Full example: Urzpvtch(LanguageSelection).zip


1. The title will not be changed because it is defined in _reg.rsc

2. The system strings like CBA "Options"/"Select"/"Cancel" will not be changed because they are defined in avkon.rsc

This page was last modified on 13 September 2012, at 06:21.
196 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.