Re: Multiple Language Support
"Mohit" <behappy.mohit@gmail.com> wrote in message
news:fb86fd65-4611-4bd3-877a-84b28488c5af@i4g2000prm.googlegroups.com...
I have to develop an application which support multiple language
depend upon user choice.Can u please suggest easiest method for this.
The way I do it is as follows:
I have a program MyProg.exe with resources in English.
I create resource only DLLs - one for each supported language
MyProgFRA.DLL MyProgESP.DLL MyProgDEU.DLL etc.
All resource strings, menus, and dialogue boxes of MyProg.exe are duplicated
in translated form in the resource DLLs. All bitmaps icons cursors etc are
also duplicated for convenience.
I have a class which manages all resources - schematically:
class RESOURCEMANAGER
{
static HINSTANCE hInstance;
HINSTANCE hOldInstance;
...
}
hInstance is set to the module which implements current language, and only
changed if the user selects a new language.
RESOURCEMANAGER has static methods to load strings, images, etc from the
module hInstance.
LoadString() is never used from outside RESOURCEMANAGER; - always
RESOURCEMANAGER::LoadString(). Similarly for images etc.
The constructor, RESOURCEMANAGER::RESOURCEMANAGER() calls
AfxSetResourceHandle( hInstance ), storing the old resource handle in
hOldInstance. The destructor calls AfxSetResourceHandle( hOldInstance ).
Every dialogue is wrapped by a non-static method of RESOURCEMANAGER.
bool RESOURCEMANAGER::doDialogueNumber42( .... );
Thus modal dialogues are simple done with
{
RESOURCEMANAGER rm;
bool bResult = rm.doDialogueNumber42( .... );
....
}
It works fine.
I create a menu of available languages, by checking the program directory
for fileswith names MyProg???.dll
In each there is a resource string IDS_LANGUAGENAME which names the language
the DLL applies to (in its own language).
My menu is constructed from these and reads
Deutsch
English
Espanol
Francais
Nederlands
Selecting the appropriate one, just sets the appropriate static hInstance in
RESOURCEMANAGER and refreshes anything which is showing.
If you want to see it in action, just download the evaluation copy from
http://www.mozart.co.uk (It helps if you read music, but in fact the
language selector is available in the "language" tab on the dialogue you get
with View/GlobalPreferences, and you can do that and watchthe menus change
without actually opening a music document!)
( My next version will add Czech to the list of languages. But that needs
UNICODE as it uses a different code page, and so I'm not adding it to the
current (non-unicode) version. With Unicode it is no more difficult than
the others. So far, in the up-and-coming Unicode version, I am confident
of any Latin-alphabet language, fairly confident of other left-right
languages (Greek,Russian,...) but I'm pretty sure I'll need to do more work
for right->left languages like Arabic or Hebrew. )
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm