devxlogo

A Design for a Large Project Containing Unicode String

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.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist