Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C
Expertise: Intermediate
Jun 23, 2003

A Design for a Large Project Containing Unicode String

It has been stated before that hard-coded, literal strings are to be avoided. I disagree. There is an easy, convenient way to handle hard-coded, literal strings: use a macro directly in the code. Take a look:

    const char *msg1 = _LIT( _T("hello"), HELLO );
The _LIT macro is designed to simply return the first argument when DEBUG is defined. For release, you'd need to write a _LIT macro parser for the code to parse the _LIT macros, and create an enumerated ".h" table, and a ".dat" flat-file of literals. The flat-file can be read into an array during initialization, and all of the strings can be accessed by their index (i.e. HELLO=0). The released version of the _LIT macro might be defined as:

#define _LIT(a,b) LitArray[ b ]
You can add strings directly into your code, and not have to worry about localization. At release, the generated ".dat" file can then be translated—without changing the order of the strings.

The challenging part is making certain the strings are read in as UTF8, and that means saving the file as UTF8.

This configuration can go as far as naming the data file, based on configuration (e.g. "english.dat", or "japanese.dat"). And applications can support multiple languages at the flip of a switch.

Jamie Peabody
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date