On-The-Fly UI (User Interface) Language Changing

Environment: VC++.NET on Windows XP

Dear Reader,

Hello! Many people have sent me messages asking about how to make language DLL's and so on and so forth. But, if you are looking for a quick and easy solution, why not give this a whirl? This is just one example of how to change the interface's language on-the-fly. There are many, many ways to do this, so don't think I'm giving a "this is the only way to do it" tutorial. I just want to broaden your mind.

The "insane" demo includes some other interesting things, such as how to change your menus, tooltips, statusbar text, and so forth dynamically at runtime. I think that I've gotten most of the bugs worked out of it. Anyway, here it goes! It's gonna be a rocky ride, but just bear with me! Hope you can follow!

From, Omoshima

P.S. THIS IS ONLY AN EXAMPLE, TAKE THIS AND RUN WITH IT!!!
P.P.S. BTW, I'll soon be uploading a tutorial based around DLLs.

Vague, Hard-To-Follow Instructions (hopefully not!!)

  1. First and foremost, you must add the "LangIni.h" and "LangIni.cpp" files to the project.
  2. Then, add a variable to your C****App class.
  3. In your C****Dlg::OnInitDialog() function, call (or not) a function to set up all the buttons/texts in your dialog. I called mine "InitControls".
  4. void C****Dlg::InitControls(void)
    {
        SetDlgItemText(IDOK, 
                       theApp.m_langINI.GetValue("Button",
                       "OK"));
        SetDlgItemText(IDCANCEL,
                       theApp.m_langINI.GetValue("Button",
                                                 "Cancel"));
        SetDlgItemText(IDC_PROMPT,
                       theApp.m_langINI.GetValue("Prompt",
                                                 "Prompt"));
        SetDlgItemText(IDC_PROMPT_ENGLISH, 
                       theApp.m_langINI.GetValue("Prompt",
                                                 "Lang1"));
        SetDlgItemText(IDC_PROMPT_JAPANESE,
                       theApp.m_langINI.GetValue("Prompt",
                                                 "Lang2"));
      }
    
  5. Then, add handlers for ON_BN_CLICKED for the radio buttons.
  6. void CUILangDlg::OnBnClickedPromptEnglish()
    {
    // TODO: Add your control notification handler
    // code here
    theApp.m_langINI.LoadFile("english.ini");
    InitControls();
    }
    
    void CUILangDlg::OnBnClickedPromptJapanese()
    {
    // TODO: Add your control notification handler 
    //code here
    theApp.m_langINI.LoadFile("japanese.ini");
    InitControls();
    }
    

Downloads

Download the easy demo's source - 20.5 KB (21,029 bytes)
Download easy demo - 174 KB (178,778 bytes)

Download the insane demo's source - 34.9 KB (35,779 bytes)
Download insane demo - 205 KB (210,689 bytes)


Comments

  • Yes, but...

    Posted by Legacy on 09/08/2002 12:00am

    Originally posted by: omoshima

    Well, this isn't meant to be used... i just wanted to show one way. but, thanks for pointing out the issue. people should know about them:)

    peace

    Reply
  • OK but...

    Posted by Legacy on 09/06/2002 12:00am

    Originally posted by: Philippe Lhoste

    I tried the demo on NT 4 sp 5 + IE4's new shell (Active Desktop).

    First, system complained about a missing file. It was oleacc.dll, I located it on the Net and with it, it ran fine. I think it is a common plague for applications compiled with VC++7.

    Second, as I failed to put the ini files in a Lang sub-directory, the program correctly complained about missing them, but made the switch anyway. It resulted in blank texts... A bit disturbing, you should have more robust error handling. Also you probably should load dynamically the list of languages from the content of this directory, instead of hard-coding it.

    Third, when I switched to Japanese, I got strange characters (ƒtƒ@ƒCƒ‹(&F) •ҏW(&E) •\Ž�(&V) Œ�Œ� ƒwƒ‹ƒv(&H)) instead of Japanese chars. That's because I use Comic Sans as menu font. I have Japanese fonts installed, they were not used. I don't know if it is simple to handle.
    Oh well, I suppose that this setting is mostly used on Japanese system, and so there is no problem here. Just wanted to mention the issue.

    Regards.

    Reply
  • good

    Posted by Legacy on 08/24/2002 12:00am

    Originally posted by: anonymous

    you did a wonderful job
    it's what i am looking for
    3x

    Reply
  • Good Article, Bad Comments

    Posted by Legacy on 08/20/2002 12:00am

    Originally posted by: Jim Groffen

    I enjoyed the article and assumed that when you said you would be working on a DLL tutorial that it would be for switching lang resources. It takes a long time to write an article well and I enjoyed this one. I guess some people can only take the time to be critics and not contributers.

    Reply
  • Using external language packs instead of DLLs

    Posted by Legacy on 08/17/2002 12:00am

    Originally posted by: Herman Kwan

    Well, there're three main methods for supporting multilingual in Windows platforms:

    Method 1, Independent release for each language (e.g. Microsoft Windows)

    Method 2, Single executable file includes more than one language resources, or independent resource .dll file for each language (e.g. IsoBuster)

    Method 3, Single executable file with external language packs (e.g. Tweak-XP, PatchWise Free)

    Just like Netants, FlashGet, Tweak-XP, PatchWise Free, etc. More and more applications use external language packs (*.ini or *.lng) instead of DLLs for supporting multilingual. It's not necessary to recompile the whole project because the language packs can be added or modified dynamically. Absolutely, it's easy to translate and maintain the external language packs which are just like an INI-like text file. And, language can be shifted on the fly.

    Reply
  • Excelent!!

    Posted by Legacy on 08/15/2002 12:00am

    Originally posted by: Anonymous

    Nice tutorial!!

    Indeed not the only sollution... but the only one here.
    >> If anyone else has some thoughts please post them. <<

    Reply
  • Missing Source Code?

    Posted by Legacy on 08/13/2002 12:00am

    Originally posted by: Munish

    The source code is missing. Both the zip files only contain EXEs and INIs. No source files!!?
    Can you upload the source also?

    Reply
  • MSDN example

    Posted by Legacy on 08/13/2002 12:00am

    Originally posted by: Wang

    Have a quick look on my MSDN, Noticed that there is a good artical in April 1999 issue of MSJ. It also comes with sample source code. The artical is celled "Design a Single Unicode App that Runs on Both Windows 98 and Windows 2000"

    Reply
  • Another example of reinventing the wheel

    Posted by Legacy on 08/13/2002 12:00am

    Originally posted by: Andrew White

    Hi,

    The code is OK, if not fairly simple - but why do people
    keep on writing such functions?
    I mean there are 3 trillion packages on the market that
    do the same job and most of all better!
    e.g.
    1) What happens with right to left languages?
    2) What happens (as someone said) when the text becomes too long?
    And increasing the width of the caption will cause it
    to go over the screen's edge?
    3) Is an ini-file really a nice way of translating words?
    i.e. how do I find all words which have not been translated.
    How can I make sure that I have a kind of base lexicon
    (so that i don't translate "Ja" with "Yes" in one part of
    the code and with "Yeah" in another part.
    4) I have to put in extra source code in all my programs
    I would recommend using something like Multilizer (www.Multilizer.com)

    Regards,
    Andrew White

    Reply
  • I wouldn't use this in all languages

    Posted by Legacy on 08/12/2002 12:00am

    Originally posted by: Ben Hooper

    Hi

    Great idea, and really fast to get off the ground. However you will hit massive problems with some languages when they use 15 words when 3 will do. You dlg will look so horrible and nothing will fit properly. The way I have done it is to produce a separate resource DLL. Then your dlg layouts etc will always fit.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds