Document home

Delphi

Runtime language change

Multilingual application with runtime language change has feature where the user can change the user interface language of the application on run time. Application starts in one language. Later on the user can select a new language from the available languages and make application to translate itself into the selected language. This is the most flexible localization method for applications.

Let's see a sample. We have a .NET application, Driving.exe. It's original language is English so all strings and UI in the EXE are in English. In addition we have three satellite assemblies: de\Driving.resources.dll, fi\Driving.resources.dll and ja\Driving.resources.dll. Those satellite assemblies contains German (de), Finnish (fi) and Japanese (ja) strings and UI. If we start the application it start in English. Note! If the regional settings in your control panel are for German, Finnish or Japanese the application will actually appear in one of those languages. For simplicity's sake application appears in English.

If you choose File | Language menu the application call Soluling's SelectLanguage function that shows a language dialog that contains available languages.

Even we only have satellite assembly files for three language the select language dialog contains fourth language. English is include because it is the language of the original assembly and we can always switch back application using the original resources instead of the assembly resources.

The language dialog is still in English because the active language is English. However the language names are in native language and English (Deutsch - German, suomi - Finnish, and 日本語 - Japanese) to make it easier to select the right one. If you want to turn Finnish on select suomi - Finnish and click OK. Soluling's classes load Finnish resources (ja\Driving.resources.dll), and enumerate all existing forms/windows and translate theirs components and properties to Finnish using the new resource data. The process is very fast and flicker free. After that the application is completely in Finnish.

Let's change language again. Choose the Lanugage menu (Tiedosto | Kieli) again. The select language dialog appears again but in this case in Finnish because the active language in Finnish.

Select 日本語 - Japanese from the list. Application loads Japanese resource file (ja\Driving.resources.dll) and translates the application into Japanese.

In order to perform this only minimal changes to original application are needed. Basically you have to add one line of code that call the select language function and you have to link some Soluling's classes into your application. The files you need to deploy with your application are the application itself and the resource DLLs files.

Platforms that support initial language and/or runtime language change

Runtime language change requires a lot from the platform. In order to make it automatic (i.e. without significant code modification) the framework you use need to be modern. In practice this means that runtime language change needs an object oriented framework with components, properties and reflection. The following table shows what platforms support choosing the initial language and what platforms support runtime language change:

Platform Initial language Runtime language change Notes
Delphi Yes Yes You have to use Delphi 2009 or later if you want to change into language using different code page as your default language.
Visual C++ Yes - You have to use MFC 7 or later.
Windows Forms Yes Yes  
Universal Windows Platform Yes - Same applies to WinRT
WPF Yes Yes  
Windows Phone and Silverlight Yes -