Changing UI Language during Runtime
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.



April 17th, 2007 - 11:41
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
April 17th, 2007 - 12:26
Thanks Phil,
It’s heartening to know that you liked my blog so much
April 18th, 2007 - 05:46
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
April 18th, 2007 - 09:33
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
May 19th, 2007 - 11:10
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
May 21st, 2007 - 05:00
Hi !!
There is already a post on this issue
http://jalaj.wordpress.com/2007/04/16/switching-ime-during-runtime/
June 6th, 2007 - 06:21
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
June 8th, 2007 - 04:33
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.
November 10th, 2008 - 06:45
I HAVE COME ACROSS AT LEAST A COUPLE OF EXCEL ADDINS WHICH CONVERT NUMERALS TO WORDS FOR EXAMPLE IF YOU ENTER 1,12,12,212 IN CELL A1, CELL B1 WILL CONVERT THE NUMERALS TO WORDS IN THIS CASE : RUPEES ONE CRORE TWELVE LAKH TWELVE THOUSAND TWO HUNDRED AND TWELVE ONLY. I AM IN SEARCH OF A SIMILAR ADDIN WHICH SHOULD CONVERT THE NUMERALS TO HINDI WORDS LIKE IN THE INSTANT EXAMPLE TO रुपये एक करोड़ बारह लाख बारह हज़ार दो सौ बारह मात्र. I HAVE BEEN IN SEARCH OF SUCH AN ADDIN FOR ALMOST A YEAR BY NOW BUT TO NO AVAIL. SINCE I HAVE A VERY BASIC KNOWLEDGE OF EXCEL, I AM UNABLE TO DO IT MYSELF. WILL SOMEBODY HELP ME? I HAVE THE CODE IN ENGLISH AND CAN SEND THE FILE BY MAIL TO THE PERSON INTERESTED. THANKS