Click here to Skip to main content
15,884,237 members
Articles / Programming Languages / C++
Article

Library for MFC applications localization using resource-only DLLs

Rate me:
Please Sign up or sign in to vote.
3.29/5 (8 votes)
31 May 20064 min read 61.4K   1.8K   59   9
Multilingual Library adds multiple UI languages support to your MFC application.

 

Introduction

Multilingual Library adds multiple UI languages support to your MFC application. Multilingual library uses resource-only DLLs (sometimes called satellite DLLs) to keep translated resources, automatically selects appropriate language according to Microsoft Windows settings, and automatically generates a menu for inclusion in your application with a list of available languages to allow a user to change the language. The library is quite easy to use as only minimal changes to the source code are required and it works with both exe and DLL files.

How it works

Sample Image - maximum width is 600 pixels

On the first run, Library finds available resource-only DLLs in the application directory, makes a list of available languages and then selects the most suitable language according to Microsoft Windows language settings. It loads selected language UI resources from corresponding resource-only DLL and then substitute them for resources in the main exe/dll file. Toolkit saves UI language setting in registry and user can select other languages using menu from your application at any time.

Using the code

Naming Convention
To use Multilingual Library you have to name satellite DLLs as Filename.LNG, where LNG is a two or three character code that identifies language (For example, English is EN, English-United States is ENU, Russian RU, German – DE). You can find full list at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_9l2r.asp.


Example
You want to translate application files below,

  • MyApp.exe
  • MyDll1.dll
  • MyDll2.dll


You have to name Resource-only DLLs in German as

  • MyApp.DE
  • MyDll1.DE
  • MyDll2.DE


In French it would be

  • MyApp.FR
  • MyDll1.FR
  • MyDll2.FR


To be found by toolkit, resource-only DLLs should be placed in the same directory as executable files.

Using the code

  1. Link to multilang.lib
  2. Initialize Multilingual Library
  3. Add language selection menu to your application.
  4. Add Multilingual Library to your application's DLL with resources
  5. Create and translate resource-only DLLs
Add Multilingual Library for Resource-Only DLLs to EXE MFC Application:

Link MFC application to Lingobit Localization Toolkit

  1. On the Project menu, click YourProjectName Properties.
  2. On the left pane, select Linker and then Input.
  3. On the right pane, select Additional Dependencies .
  4. Add path to multilang.lib to the Additional Dependencies

Changes to the source code of executable file (*.exe)

1. Add the following line to the beginning of MainFrm.cpp

#include "MultiLang.h" 

2. Add the following code between BEGIN_MESSAGE_MAP ( CMainFrame , CFrameWnd ) and END_MESSAGE_MAP () in MainFrm .cpp

ON_COMMAND_RANGE(ID_LANGUAGE_FIRST, ID_LANGUAGE_FIRST+MAX_LANGUAGES, OnLanguageFirst) 
ON_UPDATE_COMMAND_UI_RANGE(ID_LANGUAGE_FIRST, ID_LANGUAGE_FIRST+MAX_LANGUAGES, OnUpdateLanguageFirst) 

3. Add the following code to the MainFrm.cpp

<p>void CMainFrame :: OnLanguageFirst ( UINT nID ) 
{ 
    MultiLangOnClickMenu ( nID ); 
    AfxMessageBox ( _T ("Please restart application for changes to take effect")); 
} </p><p>void CMainFrame :: OnUpdateLanguageFirst ( CCmdUI * pCmdUI ) 
{ 
    MultiLang UpdateMenu ( pCmdUI ); 
} </p>

4. Add the following lines to the stdafx.h

#define ID_LANGUAGE_FIRST 32000
#define MAX_LANGUAGES 100

IDs from ID_LANGUAGE_FIRST to ID_LANGUAGE_FIRST+MAX_LANGUAGES will be used by Multilang Toolkit and should not be used for other purposes in your application.

5. Add menu item with ID_LANGUAGE_FIRST to the application menu

6. Add the following line to the beginning of YourApplicationName.cpp

#include "MultiLang.h"

7. Call Multilang Library initialization after CWinApp::InitInstance() in the InitInstance() function in YourApplicationName.cpp

MultiLangInitLocalization(ID_LANGUAGE_FIRST, MAX_LANGUAGES, HKEY_CURRENT_USER, "Software/YourCompanyName/YourProductName", "GUILanguage");

Add Multilingual Toolkit for Resource-Only DLLs to MFC Extension DLL

Link MFC Extension DLL to Lingobit Localization Toolkit

1. On the Project menu, click YourProjectName Properties.
2. On the left pane, select Linker and then Input.
3. On the right pane, select Additional Dependencies.
4. Add path to multilang.lib to the Additional Dependencies


Changes to the source code of MFC Extension DLLs files

1. Add the following line to the beginning of YourDLLName.cpp

#include "MultiLang.h"
2. Add the following line between
if (!AfxInitExtensionModule(YourDLLNameDLL, hInstance))
    return 0;
and

new CDynLinkLibrary(YourDLLNameDLL);

in DllMain function in YourDllName.cpp

YourDLLNameDLL.hResource = MultiLangLoadLibrary(hInstance, HKEY_CURRENT_USER, "Software/YourCompanyName/YourProductName", "GUILanguage");

Create a resource only DLLs


There are several ways to create resource-only DLLs.


Manual creation of resource-only DLLs


To create a resource only DLL, follow these steps:
1. Create an empty DLL project.
o In Visual Studio 6, create a "Win32 Dynamic-Link Library" with "An empty DLL project" selected.
o In VS .NET or VS 2005, use "Win32 Project" in the "Visual C++ Projects" group, and select Application type "DLL" under "Application Settings".


2. Add the linker option /NOENTRY to the linker settings for each build.
o In VS 6, add "/NOENTRY" to the "Project Options" edit field in the Project Settings/Linker/Customize tab of the "Project Settings" dialog.
o In VS.NET or VS 2005, add "/NOENTRY" to the "Additional Options" edit field in the Configuration Properties/Linker/Command line tab of the project properties dialog.


3. Create a resource file.
o In VS 6, create a new "Resource Script" and enter a file name with the extension ".rc".
o In VS .NET or VS 2005, create a new "Resource File (.rc)" and enter a file name with the extension ".rc".


4. Copy all the native-language resources from your application to your new resource file.


5. Change the language of each resource to that of the resource-only DLL, and change the text, dialogs and bitmaps as required.


For more information, see the topics "resource-only DLLs" in MSDN help.


Automatic creation of resource-only DLLs


You can use Lingobit Localizer, innovative software localization tool, to simplify and speed-up creation of resource-only DLLs. Lingobit Localizer creates resource-only DLLs in three easy steps without any changes to the source code. Lingobit Localizer not only helps with creation of resource-only DLLs, but also assists in localizability testing, translation, QA checks and collaboration with translators. You can read about it at http://www.lingobit.com/tutorial/resourceonlydll/

Points of Interest

  1. Lingobit Localizer - Software Localization Toolkit
  2. MSDN

History

2006-06-30
Multilingual Library 1.0 is released.

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


Written By
Web Developer
Russian Federation Russian Federation
I am a senior software developer at Lingobit Technologies, leading provider of software for localization industry.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Konobey17-Jun-11 3:25
Konobey17-Jun-11 3:25 
QuestionHow to convert VC++ Software in HIDI Pin
hasmukginoya28-Dec-10 1:23
hasmukginoya28-Dec-10 1:23 
QuestionJapanese Localization Pin
JothiMurugeswaran20-Nov-08 1:02
JothiMurugeswaran20-Nov-08 1:02 
Questionfrom VS 6.0 to VS .Net 2003 - Localization issue Pin
shponya23-Aug-07 11:57
shponya23-Aug-07 11:57 
GeneralJapanese Localization Pin
srisvs6-Nov-06 1:33
srisvs6-Nov-06 1:33 
Generalto Japanese Characters Not Seen Correctly. Pin
srisvs6-Nov-06 1:29
srisvs6-Nov-06 1:29 
GeneralLocalize Resource files Pin
Cees Meijer5-Jun-06 20:58
Cees Meijer5-Jun-06 20:58 
GeneralFile Extensions Pin
Blake Miller1-Jun-06 8:08
Blake Miller1-Jun-06 8:08 
By forcing the file extensions to the abbreviated name of the language, you are bypassing a lot of the Window Exlorer's default behaviors. It really expects a DLL to end in .DLL not .JP

And now, if the language happens to correspond to some other extension, like .PDF, then for exmaple Adobe Reader thinks that DLL is one of their files!

Why not go with the name of the module and either the encoding of the LCID value or append _Language, like MyApp1_JP.Dll or MyApp1.JP.Dll or something like that.

I would not use your library specificaly because of this extension obfuscation going on.


People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
GeneralLanguages directory Pin
_Stilgar_31-May-06 13:45
_Stilgar_31-May-06 13:45 

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

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