Soluling home   Document home

Runtime language change

Runtime language change

Multilingual application with runtime language change has a feature where the user can change the application's user interface language on run time. The application starts in one language. Later on, the user can select a new language from the available languages and make the 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. Its 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 contain German (de), Finnish (fi) and Japanese (ja) strings and UI. If we start the application, it starts in English. Note! If the regional settings in your control panel are for German, Finnish, or Japanese, the application will appear in one of those languages. For simplicity's sake, the application appears in English.

Application in English

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

Select language dialog

Even we only have satellite assembly files for three languages, the select language dialog contains the fourth language. English is included because it is the language of the original assembly, and we can always switch back the 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 the native language and English (Deutsch - German, suomi - Finnish, and 日本語 - Japanese) to make it easier to select the right one. Suppose 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 their 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.

Application in Finnish

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

Select a new language

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

Application in Japanese

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

Note! If you set any properties on runtime, you need to reset those properties after the language change. So on most larges applications, implementing the runtime language change requires some code changes.

Platforms that support initial language and/or runtime language change

Runtime language change requires a lot from the platform. To make it automatic (i.e., without significant code modification), the framework you use needs 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 and C++Builder Yes Yes You have to use Delphi 2009 or later if you want to change into the language using a 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 - The same applies to WinRT
WPF Yes Yes  
Windows Phone and Silverlight Yes -