views:

81

answers:

3

I'm starting to modify my app, which uses all hardcoded strings for errors, GUI, etc. I'm considering these two approaches, but let me know if there is an even better way:

-Put all string in ressource (.rc) files.

-define all strings in a file, once for each language. Use a preprocessor define to decide which strings get compiled in.

Which of these two approaches is generally prefered?

A: 

Generally you see locale specific resource files containing strings referenced by key. Compiling different versions for different locales is a very rigid solution and will be a maintenance nightmare. Using resource files also allows the user to have fallback locales.

Michael Krauklis
+5  A: 

Put all the strings in resource files. Once you've done that, there's several good translation packages available. One useful thing these packages do is allow you to get translation done by somebody who doesn't program.

Remember, also, that internationalization (i18n) is a large subject, and there's a lot of things to consider. It isn't just a matter of translating strings. Do a web search on it, at the very least. You might want to read a book on it: I used International Programming for Windows by Schmitt as a guide. It's an old book from Microsoft Press, and I had to get it through a used book service; most of the more modern stuff seems to be on internationalizing .NET apps.

Without knowing more about your project (what sort of software, who the intended audience is, what sort of organization you have, what sort of budget, why you're interested in internationalization, etc.), this is about the most I can tell you.

David Thornley
+1 There's a lot more than just the text: Images need to be culturally correct, forms may need to be redesigned, currency/date formats need to be correctly handled by the code, etc. Additionally, don't concatenate strings - use String.Format so that translators can insert variable values in the correct places in the output. Also: Avoid the need for internationalisation in the first place where possible (don't use the word "Stop" on an icon where a generic image might be applicable globally, for example)
Jason Williams
And don't forget right-to-left languages - some images need to be inverted when read right to left, especially if they're inline with text
Larry Osterman
A: 

There's another approach of just putting strings in the source with somethign like tr(" ") and usign one of the tools that strips them out and converts them.

It works with any toolkit/GUI library.
You can mark text to be converted and text not to change (such as protocol strings or db keys).
It makes the source easier to read and search, isntead of having to lookup what IDS_MESSAGE34 means.

One problem with resource files, at least with Windows/MFC, is that you can't use the stringtable in dialogs. So you have some text in the stringtabel and some in the dialog section which you have to dela with separately.

Martin Beckett