views:

133

answers:

2

I'm trying to localize a large MFC project where all the strings are hard-coded into the source code. (It was the easiest thing to do at the time, back before we had any idea we'd expand into other markets.) I've looked at localization tools, and invariably they say to put all the strings into the .rc file first, or just assume it has been done. Of the ones I've checked, appTranslator is the only one that even hints it may be a problem, and provides a couple of convenience functions to cut down on the wordiness of the resulting source code.

Does anybody have a better idea than going through hundreds of files manually, and making the occasional mistake along the way?

Is there some sort of product out there to help?

Does anybody have experience with doing this?

+2  A: 

It is a tedious process to be sure. I participated in an effort like this many years ago. We did it manually. You can probably write some common code that makes the loading, checking, etc all pretty clean with minimal bloat.

I don't know of any products that will do it for you.

CStrings might be your friend - using the LoadString() member.

I would either derive from CString or write some other code that encapsulates default values (their current hard-coded values probably) and other error conditions and then use that in place of the hard-coded strings.

If you prefer not to use CString, then deriving from std::string and using the global LoadString() works fine too.

as for tools: not sure they will work for your case: http://www.modelmakertools.com/articles/hard-coded-strings.html

apparently this tool can find all the strings in your exe files: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx Then you can search for them and replace.

I think writing a tool would be fairly straightforward - look for " character and then create an entry in an rc file that corresponds to the .cpp or .h file it came from. You will have a lot of culling to do, but it is a start. You can do a replace of the text, or insert comments, etc. You can use the line number and file name for the resource id/name in a #include.

Tim
Thanks, although the tools you mentioned don't look like they'll do what I need. I could probably write something in Perl in a few days, but thought that buying a tool would be cheaper, easier, and more reliable.
David Thornley
If it were me I would just throw together a tool to list all the strings in a file, along with line numbers, etc., then do the rest manually. Polishing it for a one-time use is diminishing returns in my opinion. I don;t envy your task... good luck
Tim
+1  A: 

I know it's too late but just for the search engine.
There is a feature of CString to initialize it from a resource ID.

CString((LPCTSTR)IDS_RESOURCE_ID)
Martin Beckett
Thanks, but this still means doing everything by hand, which is what I was trying to avoid.
David Thornley
There are two approaches - the manually putting everything into string tables is the approved method. Although this is tricky for dialogs. There is another set of translation tools that simply do a search/replace in the finished exe.
Martin Beckett