constant global strings Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Experienced Solver
Experienced Solver
Posts: 53
Joined: Wed Jun 06, 2012 4:44 pm
Location: Calgary, Canada

Re: constant global strings

Post by wxBen » Thu Dec 13, 2012 8:10 pm

I have a little bit of experience with this, and here are a few thoughts, also expressed above:

If you use ANSI strings (non UNICODE) and you make use of extended characters (ASCII codes above 127), then those extended ASCII characters will definitely NOT display correctly on all machines. Windows for example changes what those extended characters look like depending on the regional, application and font settings. You may see Russian or Chinese or block characters depending on the machine. So this is not really a solution, plus there is no simple way to clean it up either after the fact.

What we do in our of our applications is make our application Unicode aware (wx 2.9 is by default I think), and then all of our strings are ASCII English. But we allow the user to select or create a Unicode text translation file (UTF-16 or UTF8), which we can read in. And then whenever we open up a view, we translate the strings, for example:

wxString label = item->xLabel();

wxCheckBox* checkBox = new wxCheckBox(owner, item->eventId, label);

wxString tooltip = item->xTooltip();

The Translate function takes a wxString by reference, checks to see if there is a translation table active, and if, use the string passed in as a key and finds and returns the translation. wxWidgets has some nice support for Unicode text files and maps and such.

So it works very well, you just have to make sure your widgets and layouts are large enough as Russian and French for example can be wordier. Also make sure the font used is a unicode font, though that should typically already be sorted out. I know it is on most (newer) Windows version machines, on some old ones you may have to install regional language packs from Microsoft (or make sure Office is installed and use that Unicode font) and some standard unicode characters are not available in some fonts (for example \u2713 which is a checkmark ✓ displays fine on Windows 7 and 8 but you get a block on XP by default).

Earned some good credits
Earned some good credits
Posts: 119
Joined: Tue May 10, 2005 10:29 am

Re: constant global strings

Post by Dummy » Fri Dec 14, 2012 6:35 am

Hi wxBen,

thanks for your tips!

For translations I am using the message catalogs of GNU gettext, which are supported by wxWidgets.
As encoding of these catalogs, I am using UTF-8.
My application is build as unicode (using wxWidgets-2.9).
So translated strings should be shown correct on every machine.

The second point are constant strings, which have not to be translated.
I checked the EXE file with a hex editor and saw, that these strings are stored as unicode in it. So I think these strings should be also shown correct on every machine!?

I am using VC++2008 Express, which is set to build an unicode application. The encoding of the source code is windows-1252, but constant strings are stored as unicode in the EXE.
So my question is, does it depend only on the compiler, that constant strings are stored as unicode in the EXE file?
Or could it be sometimes necessary (e.g. with another compiler) to have the source code also in unicode to get the strings stored as unicode in the EXE?

Post Reply