?
Solved

MFC Gui in different languages

Posted on 2003-03-11
15
Medium Priority
?
188 Views
Last Modified: 2013-11-20
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!
0
Comment
Question by:FlorianJaeger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8112860

  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.





 
   

 
0
 

Author Comment

by:FlorianJaeger
ID: 8112940
Isn't it possible to do this without creating a DLL and have all this information embedded in the exe file?
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8112975

 Yeah it is but you have this problem...

 if ( GERMAN )
    LoadString ( IDR_GERMAN_WELCOME_MSG );
 else
    LoadString ( IDR_ENGLISH_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.



0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

Author Comment

by:FlorianJaeger
ID: 8115342
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 ... :(
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8115392

 You can right Click on the String table itself and choose 'Insert Copy' then pick a language.
0
 

Author Comment

by:FlorianJaeger
ID: 8115436
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!!
0
 
LVL 12

Accepted Solution

by:
williamcampbell earned 1000 total points
ID: 8115497


 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 );

 csText.LoadString ( IDS_BTNREBOOTUNIVERSE );
 m_btnSRebootUniverse.SetWindowText ( IDS_BTNREBOOTUNIVERSE );

etc
etc

 For MessageBoxes use AfxMessageBox ( IDS_MESSAGE_ERROR6 );

 

 
 
0
 

Author Comment

by:FlorianJaeger
ID: 8116184
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 !
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8120790

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

  Gutten Dag!
0
 

Author Comment

by:FlorianJaeger
ID: 8124841
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??

Thanks!
0
 

Author Comment

by:FlorianJaeger
ID: 8124913
William,

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 ...
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8129459
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.

http://www.codeproject.com/tips/internationalization.asp?target=globalization

0
 

Author Comment

by:FlorianJaeger
ID: 8130699
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? :-)
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8131525
Check this out

 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/loadkeyboardlayout.asp

 Apparently this works on a per process basis

 I think you use MAKELANGID
 Then call LoadKeyBoardLayout ();

 Worth a try
0
 

Author Comment

by:FlorianJaeger
ID: 8132634
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!
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question