MFC Gui in different languages

I have a GUI (not very complex, just one dialog) and I would like to have it in two languages, notably German and English.

I might also do this for more complicated GUIs if it turns out not to be too difficult.

Now ... what would the easiest thing to do be? I know that one is supposed to use the string tables - but:

* How do I add the strings in differnet languages
* How do I determine what language will be used
* How do I specify what variables/strings to use in the static controls for example?
* How do I use the string table in my code such as in custom messagebox() calls ...

Thank you!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


  You might create two resource DLL's

  Each contains the Strings and Template for your Dialog in a different language.

  At Runtime based on the language (Use GetLocale) you call LoadLibrary on the appropriate DLL. Then using FindResource you load your template. Using LoadString you load your strings.

  Should you choose to support more languages at at later date simply create another DLL.


FlorianJaegerAuthor Commented:
Isn't it possible to do this without creating a DLL and have all this information embedded in the exe file?

 Yeah it is but you have this problem...

 if ( GERMAN )
    LoadString ( IDR_GERMAN_WELCOME_MSG );

 Instead of

    LoadString ( IDR_WELCOME_MSG );

 If you dont want to do the LoadDll thing then add all the strings to your resource and two dialog templates. Then based on the language you need to make an if decision when ever they are needed.

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

FlorianJaegerAuthor Commented:
Thanks, can I not have two string tables? I tried to insert another string table but that didn't work at all.

I really have no experience with string tables ... :(

 You can right Click on the String table itself and choose 'Insert Copy' then pick a language.
FlorianJaegerAuthor Commented:
Aha! Thanks - could have figured that out myself.

OK, next question :)

So far I have only created GUIs that have one language, so when I insert a static control I just type the text in.

Now how do I do that know? Obviously I don't want to use static text anymore ...

... and the same goes for message boxes that display errors / warnings ...

Usually I would do:

MessageBox("Error 3 occured", "Error", MB_ICONSTOP)

.. but what do I do know?

And the final question: How do I determine which language to use???

Thanks a lot!!

 I *think* the Locale will be done by default. If you insert copy 'German' then that will choosen by default if the locale is german.

 For Your Dialog in the function

 'OnInitDialog'   (WM_INITDIALOG in ClassWizard)

 For each of your controls do this

 CString csText;

 csText.LoadString ( IDS_STATICLABEL1 );
 m_staticLabel1.SetWindowText ( csText );

 csText.LoadString ( IDS_EDITSTUFF );
 m_edtStuff.SetWindowText ( IDS_EDITSTUFF );

 m_btnSRebootUniverse.SetWindowText ( IDS_BTNREBOOTUNIVERSE );


 For MessageBoxes use AfxMessageBox ( IDS_MESSAGE_ERROR6 );



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FlorianJaegerAuthor Commented:
I have question regarding the automatic choice of locale. When I copy the string table I can choose between German(Germany), German(Austria) and German(Switzerland). I certainly don't want to create three string tables for the same language.

What do you think happens if I create a string table for German (Germany) and somebody in Switzerland launches the GUI?

Just curious ... maybe it doesn't matter which one I choose?

Thanks so far !

  You could change the Locale of you comp temporarily adn see what happens :)

  Gutten Dag!
FlorianJaegerAuthor Commented:
CString csText;
csText.LoadString ( IDS_STATICLABEL1 );
m_staticLabel1.SetWindowText ( csText );

seems to work fairly well, this way I can also let the user change the language at runtime.

However creating a control variable for every single static control seems like a big overhead - that's a lot of work to do!

It doesn't really matter for the current project since it's just one dialog but I was thinking about doing it for another one as well and that has about 10 dialogs ... is there not an easier way??

FlorianJaegerAuthor Commented:

There is another thing that I just realized, with the method were I don't use the DLLs I can't really determine which string table to use, right? It's determined by the OS depending on the OS language. That's not that good as I would like to give the user the option of changing the language (for example run it in English no matter what OS language they have installed).

Is there a fix for that?

Btw, changing the locale doesn't do anything, seems as if you need to run a German OS (for example) for the different string table to be used.

This whole thing seems more complicated than I thought (per usual ...)

Thanks ...
I'm afraid so..

'Operating system is responsible for loading the language specific resource'

You can change locale via the control panel.

Looks like you will have to support two sets of dialogs and strings...yes it's that difficult :(

 Here is an interesting article that you may find useful.

FlorianJaegerAuthor Commented:
Funny, I just looked at that article yesterday ... didn't find it too useful though.

I really could use the

CString csText;
csText.LoadString ( IDS_STATICLABEL1 );
m_staticLabel1.SetWindowText ( csText );

approach - and just add a button where the user can prevent the code from looking at the alternative string table - just leaving the dialog the way it is.

I think that would be a good decision.

And, as I said earlier, changing the locale didn't have any effect and I'm convinced that you need to have a OS in a different language for that to work - difficult to test though ...

What do you think? :-)
Check this out

 Apparently this works on a per process basis

 I think you use MAKELANGID
 Then call LoadKeyBoardLayout ();

 Worth a try
FlorianJaegerAuthor Commented:
Don't worry about that too much please, a friend of mine lives in Austria and can check that out for me.

I also have a german version of NT4 somewhere that I can use once I get back to my office.

I think I'll just go that way so that would be good for now.

Thanks for all your help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.