Click here to Skip to main content
Click here to Skip to main content

IG MultiLanguage Toolkit

, 9 Sep 2002
Rate this:
Please Sign up or sign in to vote.
A multilanguage control.

Introduction

There are many programs that are used by many people who have different mother languages. In that case, English is the most commonly used, so the ones who do not know English well could get in troubles. To solve the problem, I've built an ActiveX control that is useful for programmers. Programmers only have to add the control to their project and provide a dictionary that is used by the control to translate their program's user interface to the required language.

How to use the control...

It is very simple to use the control in your program. There is two ways described here, the first is used for VC++ programs and the other is for VB programs.

...in VC++ programs

With VC++ programs, control has exposed BOOL CIGMultiLangCtrl::TranslateWindow(OLE_HANDLE hWnd) function for that purpose. Suppose you have two menu items: English and Vietnamese. The English menu item is used to translate your program's user interface into English and the other into Vietnamese. You only have to add these lines to your program.

void CTestSDIView::OnLanguageEnglish() 
{
       int nIndex = m_IGMLCtrl.LanguageByName("English");
       m_IGMLCtrl.SetActiveLanguage(nIndex);
       m_IGMLCtrl.TranslateWindow((LONG)AfxGetMainWnd()->GetSafeHwnd());
}

void CTestSDIView::OnLanguageVietNamese()
{
       int nIndex = m_IGMLCtrl.LanguageByName("VietNamese");
       m_IGMLCtrl.SetActiveLanguage(nIndex);
       m_IGMLCtrl.TranslateWindow((LONG)AfxGetMainWnd()->GetSafeHwnd());
}

...in VB programs

For programs that are written in VB, the control has exposed BOOL CIGMultiLangCtrl::TranslateWindow(LPDISPATCH lpDispatch) function to solve the problem. Because the base of almost all VB programs is on COM technique, the control has to do the task in a different way. In that case, you add these lines to your project :

Private Sub MenuItem_Click0
        IGMLCtrl.ActiveLanguage = IGMLCtrl.LanguageByName("English")
        bResult = IGMLCtrl.TranslateObject(Me)
End Sub

An important thing

One thing you should remember is to load the dictionary file before any translation. To load a specified dictionary, you can do this:

// VC++ programs
void CTestSDIView::OnInitialUpdate()
{
        // your initial code here...
        
    if (m_IGMLCtrl.LoadDictionary("Dictionary.dic"))
    {
        // Translate Window into recently used language.
        m_IGMLCtrl.TranslateWindow((LONG)GetSafeHwnd());
        m_IGMLCtrl.TranslateWindow((LONG)AfxGetMainWnd()->GetSafeHwnd());
    }
}

// VB programs
Sub Form_Load(..)
      // your initial codes
      IGMLCtrl.LoadDictionary "Dictionary.dic"
      IGMLCtrl.TranslateObject(me)
End Sub

In this example, I load the file Dictionary.dic from the location where the program is started.

Switching between languages

If you want to switch between languages at run-time, you must first set active language index and then call ::TranslateWindow(...)or TranslateObject(...) function. ActiveLanguage or NativeLanguage property is the index of language in the dictionary file. You can set it directly or by ::LanguageByName(LPCTSTR lpszLanguageName) function.

Dictionary file

Dictionary file is very important in making sure that control is working properly. It normally is a text file, so it is easier for both programmers and end-users. Its structure is described as shown:

[Configuration] 
  Active Language=VietNamese 
  Native Language=English 
  [English] 
  &File 
  &New\tCtrl+N 
  &Open 
  &Save 
  [VietNamese] 
  Tập tin 
  Tạo mới 
  Mở file 
  Lu file
Lu file với tên mới

The Active Language key is the key that specifies the current language that is used by the program. The Native Language key specifies the language that is used by programmers at design-time.

Note: You must make sure that the number of text between languages is equal, otherwise there will be errors.

Update later ....

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Truong Pham Dang Khoa
Web Developer
Vietnam Vietnam
I working for Twinstar Systems Inc., a semiconductor company, as Senior Software Engineer.

Comments and Discussions

 
QuestionHow to declare the m_IGMLCtrl in the project. Pinmembergloriousgopi2-Aug-06 20:43 
QuestionWhy to use an ActiveX? PinmemberNicolas Stuardo30-Sep-05 6:26 
Generalerror "Cannot open file mfc42u.lib in winXP Pinmemberinbha10-Mar-05 4:09 
Hi,
 
I have extracted the source file and run it in wimdows XP plotform and vc6.0.
It shown the error "cannot open file mfc42u.dll, but in this file avilable in c:\windows\system32 directory and i include manually in current folder, but it should not run again show the error.
 
write your suggestionsRoll eyes | :rolleyes:
Generalewfgyewygfyu PinsussAnonymous7-Oct-04 19:43 
GeneralNon practical PinmemberPhilippe Lhoste19-Sep-02 4:14 
GeneralRe: Non practical PinmemberSynetech1-Jun-05 14:51 
GeneralRe: Non practical Pinmvp CPallini29-Apr-08 2:47 
Generalok Pinsusshspecg10-Sep-02 19:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141216.1 | Last Updated 10 Sep 2002
Article Copyright 2002 by Truong Pham Dang Khoa
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid