views:

408

answers:

2

Hi,

I am new to MFC and I need to build a multi-language application that should be able to change the language at runtime.

AFAIK the common way for internationalization with MFC is to create resource-only DLLs. But there seems to be no simple way (that means, load DLL, call some function, and MFC updates all stuff automatically or something like that) to switch resource-DLLs at runtime, right?

So I will have to update all controls and so on manually. I already managed to load strings from the string-table of a DLL but since captions of controls like buttons are stored in the corresponding dialog (if I trust my resource-hacker :)) I thought there must be a way to load them and avoid storing an additional string in the string-table manually.

Or is there another way I don't know about?

If it makes any difference...I have to use MS embedded visual c++ 4

+1  A: 

I work on a large localized MFC project. Here is our strategy:

  1. A dictionary of key -> localized string, specific to each language. There are a few ways to implement this, more later.

  2. Control IDs or captions in the dialog resource are set to the key used to look up the translation

  3. Create a base CDialog, CFormView, etc and in at init call ::EnumChildWindows. In the callback, look up the translation and replace the control's caption with the translation.

For your dictionary, you can go a few ways.

  • If you want to rely on the built-in localized resource selection and string tables, you have to somehow match the control to the string ID. You can carefully ensure that the control ID matches the string ID, or you can ASCII-encode the ID in the caption and then use atoi to parse the int value.

  • You can forgo the built-in localized string table deal and maintain your own string -> string dictionary for each language. This lets you set the caption to the non-localized string in the resource which makes layout easier (although you'll still need to test in all languages.) It will require you to do your own "dependency injection" to make sure you load up the right dictionary. You want to be able to release updated/additional languages without rebuilding the core binaries.

Aidan Ryan
+1  A: 

If you don't want to require a restart of the application (by far the easiest solution, and the one you should use IMO), you can use resource dll's and recreate the main windows when the user switches languages. That way MFC will recreate the menus etc. in the new language. New dialogs will be displayed in the new language already anyway, from the moment you've switched the resource handle around.

I'm not sure how this relates to the embedded world, my experiences are from the desktop MFC.

Roel