How can I switch language run-time in an application developed with Delphi/C++Builder?


After installation of Multilizer (along with demos) there are Multilizer units that enable run-time language switch of applications that are localized with Multilizer.

The units are located in

  • \Multilizer\demos\vcl demos\ (for Delphi/C++Builder 2-2007)
  • \Multilizer\demos\unicode vcl demos\ (for Delphi/C++Builder 2009, XE-XE7 or newer)

To enable language switch in your app, you need to do the following:
1) Add some code in your app. (please see below)
2) Create localized resource DLLs with Multilizer. Ensure they are in the same directory as the EXE.
3) Run the app.

The code that needs to be inserted in your application:

In order to have this work, you need to include following units to your uses clause: MlzI18N,  MlzResDll,  MlzResLangD.

Here’s typical code for changing language on run-time:

procedure TForm1.LanguageButtonClick(Sender: TObject);

begin

  // Select the new language and set it on
  if GetAvailableResourceCount = 0 then
    MessageDlg(
      'You must first use Multilizer to create resource DLLs.',
      mtInformation,
      [mbOk],
      0)
  else if SelectResourceLocale(poScreenCenter, []) then
    SetCurrentDefaultLocaleReg;
end;

The above code
1) checks, if there are resource DLL’s in application dir (GetAvailableResourceCount)
2) sets the new language3) stores language setting into registry (so that next time app starts in the same language)