×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Albacete, Spain
    Posts
    380

    Language selection by user

    I have an application that has all string resources in two languages.
    So far, if the language use is set by the handset's language configuration.
    I want to allow the user to change language without changing the handset's language settings. Instead, when the app starts the user will be asked to select one of the languages available.

    Can this be done with the same language resource files (.l01, .l04, etc) that I already have? (How?)
    ----------------------------------------------
    Every journey starts with a small step.

  2. #2
    Super Contributor
    Join Date
    May 2004
    Posts
    2,265

    Re: Language selection by user

    Hi,

    I have a solution to let user select the perferred language during application startup, but it is not perfect.

    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 choice in some way.

    Code:
    // 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);
    	CleanupStack::PushL(array);
    	array->AppendL(KPhoneLanugage);
    	array->AppendL(KEnglish);
    	array->AppendL(KChinese);
    	// 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);
    	User::WaitForRequest(status);
    	TInt ret = status.Int();
    	if(ret>=0)
    		{
                    // ret is the index of the user selected item
                    // here we map the user selection to a language code
    		TLanguage language = ELangEnglish;
    		switch(ret)
    			{
    			case 0:
    				{
    				language = User::Language();
    				break;
    				}
    			case 1:
    				{
    				language = ELangEnglish;
    				break;
    				}
    			case 2:
    				{
    				language = ELangPrcChinese;
    				break;
    				}
    			default:
    				{
    				language = User::Language();
    				break;
    				}
    			}
    		// 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();
    	if(cleanup)
    		{
    		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.

    Code:
    #include <coeutils.h>
    ...
    TFileName CUrzpvtchApplication::ResourceFileName() const
    	{
    	TFileName filename = CAknApplication::ResourceFileName();
    	TInt language = 0;
    	TInt err = RProperty::Get(KUidUrzpvtchApplication, 0, language);
    	if(err==KErrNone)
    		{
    		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);
    		if(exists)
    			{
    			filename=fn;
    			}
    		}
    	return filename;
    	}
    Note:
    1. The title will not be changed because it is defined in _reg.rsc, so you have to update it programically according to the user selection.
    2. The system-wide strings like CBA "Options" will not be changed because they are defined in the S60 system resource file instead of the application's resource file.

    Regards

    Ziteng Chen

  3. #3
    Registered User
    Join Date
    Dec 2005
    Location
    Albacete, Spain
    Posts
    380

    Re: Language selection by user

    Thank you Ziteng Chen,

    Actually, the language selection in my app is not only limited to when the app starts.
    I have tried what is explained in http://wiki.forum.nokia.com/index.ph...rt_at_run_time but it does not work on 6210 Navigator.
    I tried also with the app in http://www.newlc.com/Change-the-appl...nguage-at.html but get the same result. It does not work.
    Has anyone tried these solutions and got them working?
    ----------------------------------------------
    Every journey starts with a small step.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,570

    Re: Language selection by user

    The Wiki article seems to be what I was going to suggest. However it is using CompleteWithAppPath with a filename, which works for S60 1st and 2nd editions only.
    For S60 3rd edition you need to specify the path yourself, because the .exe and the .rxx files reside in different directories.
    Try
    Code:
    _LIT(KResourceFileName, "\resource\apps\LangFile.r%02d");
    and you also have to modify KEmulatorPath, just I do not see its definition.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Albacete, Spain
    Posts
    380

    Re: Language selection by user

    I specify the languages paths as you say, but I get the same results.
    Actually, I am bit suspicious because

    iLangFileOffset = CEikonEnv::Static()->AddResourceFileL(KLynxBackupEnLangFile); // KLynxBackupEnLangFile = C:\\resource\\apps\\LynxBackup.r01

    returns iLangFileOffset = 1043755008 . Does not look like a normal offset value, is it?

    I checked that C:\\resource\\apps\\LynxBackup.r01 exist on the phone and has the expected content. So it is not a problem with the r0x files themselves.
    ----------------------------------------------
    Every journey starts with a small step.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Location
    Albacete, Spain
    Posts
    380

    Unhappy Re: Language selection by user

    Since I can't get the solution in the WIKI (mentioned below) to work in my app, I am trying a different approach. I open the resource file and implement a function to read the resources. Just did a small attempt with the following code (and some variants of it) to try to read TBUF resources:

    Code:
    //  In .rssi file
    RESOURCE TBUF r_initialtext_body 	{ buf=STR_initialtext_body; }
    
    //  In .l01 file
    #define STR_initialtext_body	"PLEASE, MAKE SURE THAT THE CONTACTS IN THE SIM CARD PHONEBOOK ARE COPIED TO YOUR PHONE'S PHONEBOOK BEFORE PROCEEDING."
    
    //  In .c++
    
    RResourceFile 	rf;
    RFs	        fs;
    
    User::LeaveIfError(fs.Connect());
    rf.OpenL(fs, KLynxBackupEnLangFile);
    rf.ConfirmSignatureL();
    TInt offset = rf.Offset();
    HBufC8* res = rf.AllocReadLC(R_INITIALTEXT_BODY);
    TResourceReader rr;
    rr.SetBuffer(res);
    TPtrC buffer = rr.ReadTPtrC();
    CleanupStack::PopAndDestroy(res);
    rf.Close();
    fs.Close();
    after red line, buffer = "LEASE, MAKE SURE THAT THE CONTACTS IN THE SIM CARD PHONEBOOK ARE COPIED TO YOUR "

    What seems to be happening is that P (=80) is taken as the length instead of a character, and resulting buffer.Length() = 80.

    How can I read TBUF resources from rf above?
    ----------------------------------------------
    Every journey starts with a small step.

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,570

    Re: Language selection by user

    Quote Originally Posted by juannoguera View Post
    iLangFileOffset = CEikonEnv::Static()->AddResourceFileL(KLynxBackupEnLangFile); // KLynxBackupEnLangFile = C:\\resource\\apps\\LynxBackup.r01

    returns iLangFileOffset = 1043755008 . Does not look like a normal offset value, is it?
    Yes it does, why not? Just switch it to hexadecimal (3E367000), and compare it to the number of your first resource in the .rsg file. Then you can decide if it makes sense or not...
    Quote Originally Posted by juannoguera View Post
    What seems to be happening is that P (=80) is taken as the length instead of a character, and resulting buffer.Length() = 80.
    The description of ReadTPtrC also suggest that...
    How can I read TBUF resources from rf above?
    Note that the SDK contains Examples\SysLibs\ResourceFiles, consider checking those examples.

  8. #8
    Registered User
    Join Date
    Dec 2005
    Location
    Albacete, Spain
    Posts
    380

    Re: Language selection by user

    Checked the examples, but none of them seem to contain a TBUF as resource.
    They do not should how to read a TBUF resource.

    Has anyone read a TBUF resource using code similar to my previous post?, how did you do it?
    ----------------------------------------------
    Every journey starts with a small step.

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,570

    Re: Language selection by user

    Although it is not an answer to the question itself, you can try StringLoader instead.

Similar Threads

  1. How to handele setting after selection by user
    By rahelcavalli in forum Symbian
    Replies: 8
    Last Post: 2009-07-29, 08:05
  2. SMS Encryption
    By jayakrishnan.salim in forum Mobile Java General
    Replies: 16
    Last Post: 2009-07-13, 06:26
  3. Replies: 0
    Last Post: 2004-11-24, 18:49
  4. Questionnaire on Forum Nokia user motivations
    By Maaike Spoor in forum News and Announcements
    Replies: 0
    Last Post: 2004-08-10, 09:46
  5. List item selection
    By SanDan in forum Mobile Java General
    Replies: 2
    Last Post: 2003-05-06, 10:57

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •