Jalaj

April 17, 2007

Changing UI Language during Runtime

Filed under: Indian Languages, Visual Basic — Jalaj @ 9:37 am

This post is subsequent to Phil’s comment for creating a user interface where the language can be changed during runtime with a press of a button or so. I had intention to post a detailed post, but due to time contraints posting only a part of it, but hope this would clarify on all steps required to get going.

Let’s start with my post VB Forms in Hindi Unicode Fonts. Here I designed a form where all text were in English. As soon as the form was loaded, a text file containing corresponding strings was read and caption/text on each form control was changed to Hindi one.

To achieve UI toggling, why not store the strings read from the file to some array or so and also the corresponding English version to another. Now add a Button “Toggle Language” which would check for the current language (stored in yet another variable), replace all texts with those of the other language, and accordingly change the variable for current Language (mentioned above). Pressing button again would resore the preious UI. The caption of this button can also be changed while changing others.

That should be enough to achieve results.

Now to store the language strings there is a better approach, using a Resource file, which can be created using the VB6 Resource Editor under Tools menu, (You may require to add it through Add-in Manager… under Add-Ins menu)… I kept away from using it as the strings I intended to store were in Hindi Unicode and the Resource Editor doesn’t seem to support it… Third Party Tools as Resource Builder can be used for creatign Resource Files with unicode texts. Resource strings as stored above can be read by using LoadResString function available with VB6.

Syntax :
<SomeVariable> = LoadResString (id as long)

The LoadResString function reads from the default string table of the Resource File. There can be additional language/locale specific string tables containing corresponding language/locale strings. In case a string table matching the Regional Settings of the Operating System is found, strings from this table is read instead of the default table.

The above method however does not cater to this specific requirement. However a non-conventional way for storing all language strings in a single table is listed at Load internationalization data from a resource file with a single string table, which can be also be used for this specific purpose.

While LoadResString function available with VB6 doesnot allow you to specify Language/Locale, WinAPI function FindResourceEx, as below, allows you to read language specific strings.

Declare Function FindResourceEx Lib "kernel32.dll" Alias "FindResourceExA" _
        (ByVal hModule As Long, ByVal lpType As Long, ByVal lpName As String, _
        ByVal wLanguage As Long) As Long

Const RT_STRING = 6

For reading from string table the parameter lpType should be RT_STRING as above. The full discussion on this function is out for current scope which I will take up later sometime.

9 Comments »

  1. Voila!! Thanks very much .. much needed article.. I have been posting lot of ANNOUNCEMENT in different fourms…about this SPOT of yours!!!

    Great IDEA…Thanks very much once again

    Comment by phil — April 17, 2007 @ 11:41 am

  2. Thanks Phil,

    It’s heartening to know that you liked my blog so much

    Comment by Jalaj — April 17, 2007 @ 12:26 pm

  3. Hello!!!

    Is it possible to Mirror a form?? Well what i mean is a normal form has control buttons(Max, Min) at the right hand corner..is it possible to shift it to left hand corner.

    Sorry for all such silly questions!!!!

    regards

    Comment by phil — April 18, 2007 @ 5:46 am

  4. [...] Skip navigation StatsIdeas ? « Changing UI Language during Runtime [...]

    Pingback by Mirroring Form for RTL languages as Arabic « Jalaj — April 18, 2007 @ 8:54 am

  5. Hi Phil! I did not carefully read your comment…

    About mirroring the form… there is no straight forward way… If you need to make such implementation it would be better if you use a form with “borderstyle” property set to 0 (None) and then manually clone the buttons.. Then these buttons will also mirror as shown in post Mirroring Form for RTL Languages as Arabic

    Comment by Jalaj — April 18, 2007 @ 9:33 am

  6. hi Sir,
    i have one boubt in my mind.
    is it possible to change the font style in vb6 at run time.
    like i have two textboxes on a form, in which one of them i want that text should b in english and in another textbox it should apper in some other language.
    if its’ possible then how can we do so.
    plz help me

    Comment by Dharmender — May 19, 2007 @ 11:10 am

  7. Hi !!

    There is already a post on this issue
    http://jalaj.wordpress.com/2007/04/16/switching-ime-during-runtime/

    Comment by phil — May 21, 2007 @ 5:00 am

  8. Dear Sir,
    I have a problem in my MS Excel,my work sheet language has been change please tell me how’s change the language.

    Thank you

    Comment by Abid — June 6, 2007 @ 6:21 am

  9. Hi Abid,
    I did not get what you meant by “Language” change in worksheet. Below are what I guess your problem might be.

    If you are working in a language that rights right-to-left that used to be your default and now the excel is starting up with layout left-to-right… slect on menu bar Tools –> Options –> International tab –> and under fram right-to-left select appropriate option and OK…

    If its related to default font on worksheet then there is option under “General” Tab

    If there is some other problem, then it needs to be detailed.

    Comment by Jalaj — June 8, 2007 @ 4:33 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.