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.

Revision as of 04:38, 30 May 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to define localization messages

From Wiki
Jump to: navigation, search
Article Metadata
Created: Den123 (26 Jun 2007)
Last edited: hamishwillee (30 May 2013)

The language constants are defined in e32const.h.

Define the languages that your component is localized to in your .mmp file:

// file: MyApp.mmp
LANG 01 02 16 // UK English, French, Russian

Place logical strings for different languages in different language-specific files. Dont forget to define the file encoding for those languages that use character sets beyond basic ASCII. For instance:

// file: MyApp.l01 (ELangEnglish = 01)
#define message_wait "Please wait..."
#define mess_with_param ¨You have %N new messages.¨
// file: MyApp.l02 (ELangFrench = 02)
// the file has to be encoded in UTF-8 for the strings to be rendered correctly:
#define message_wait "Attendez, s'il-vous plait..."
#define mess_with_param ¨Vous avez %N nouveaux messages.¨
// file: MyApp.l16 (ELangRussian = 16)
// the file has to be encoded in UTF-8 for the strings to be rendered correctly:
#define message_wait "Пожалуйста, подождите ..."
#define mess_with_param ¨Количество новых сообщений: %N¨

In file MyApp.loc, include the correct language-specific file:

// file: MyApp.loc
#if defined LANGUAGE_01
#include "MyApp.l01"
#elif defined LANGUAGE_02
#include "MyApp.l02"
#elif defined LANGUAGE_16
#include "MyApp.l16"

In MyApp.rss, define the resources based on the strings defined in the language-specific file that was included by MyApp.loc:

// file: MyApp.rss
#include <eikon.rh>
#include "MyApp.loc"
RESOURCE TBUF r_message_wait { buf = message_wait; }
RESOURCE TBUF r_mess_with_param { buf = mess_with_param; }

In your code, use the localized strings as follows. The string denoted by R_MESSAGE_WAIT will be displayed in the appropriate language. Note the change from lower-case to upper-case.

//file: testexample.cpp
#include <stringloader.h>
// how to load simple message
HBufC* message = StringLoader::LoadL( R_MESSAGE_WAIT );
// how to load message with params
TInt msgCount = 10;
message = StringLoader::LoadL( R_MESS_WITH_PARAM, msgCount ); // You have 10 new messages.
CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
note->ExecuteLD( *message );
delete message;

Finally, add the localized language resources to the package file:

  • if you want to support only current langauge of the device, use following approach:
;; file: MyApp.pkg 
; languages supported:
; localization:
  • if you want to allow user select necessary languages, you could use following approach:
;; file: MyApp.pkg 
; languages supported:
; localization:
!({¨English¨, ¨English¨, ¨English¨ }, { ¨French¨, ¨French¨, ¨French¨ }, { ¨Russian¨, ¨Russian¨,¨Russian¨ })
IF (Option1)
IF (Option2)
IF (Option3)

There are two ways to add localized resource files into a .pkg file and generate the SIS package. Read Knowledge Base article for details.

This page was last modified on 30 May 2013, at 04:38.
100 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.