views:

113

answers:

4

I need to localize error messages from a compiler. As it stands, all error messages are spread throughout the source code as string literals in English. We want to translate these error messages into German. What would be the best way to approach this? Leave the string literals as-is, and map the char* to another language inside the error reporting routine, or replace the english literals with a descriptive macro, eg. ERR_UNDEFINED_LABEL_NAME and have this map to the correct string at compile time?

How is such a thing approached in similar projects?

+5  A: 

On Windows, typically this is done by replacing the string with integer constants, and then using LoadString or similar to get them from a resource in a DLL or EXE. Then you can have multiple language DLLs and a single EXE.

On Unixy systems I believe the most typical approach is gettext. The end result is similar, but instead of defining integer constants, you wrap your English string literals in a macro, and it will apply some magic to turn that into a localized string.

asveikau
+3  A: 

The most flexible way would be for the compiler to read the translated messages from message catalogs, with the choice of language being made according to the locale. This would require changing the compiler to use some tool like gettext.

carnieri
+1, was going to suggest gettext.
Artelius
+1  A: 

Just a quick thought...

Could you overload your error reporting routine? Say you are using

printf("MESSAGE")

You could overload it in a way that "MESSAGE" is the input, and you hash it to the corresponding message in German.

Could this work?

Arrieta
this is essentially how gettext works. the english string is used as a key to get the localized one.
asveikau
+1  A: 

You could use my CMsg() and CFMsg() wrappers around the LoadString() API. They make your life easier to load and format the strings pulled out of the resources.

And of course, appTranslator is your best friend to translate your resources ;-)

Disclaimer: I'm the author of appTranslator.

Serge - appTranslator