Inno Setup: change the setup language while setup is running

落爺英雄遲暮 提交于 2020-12-06 07:03:23

问题


In my Setup I don't want use the standard Language Dialog form.

Instead, I want to add a combobox to the Welcome page of my Inno Setup to do the same job made by the Language Dialog, so that it's able to :

  1. show all the languages included in the [Languages] section in the drop down list. So the user can select a language from this custom combobox.

  2. apply the chosen language to the whole setup.

I know that this is not possible using the "normal way", because there are no functions available in Inno Setup to perform this job (!!!).

So that, I added a couple of functions to the Inno Setup compiler and I call them from my script:

  • function GetAvailableLanguages: TStringList: it is able to return the list of all the active languages (complete data), and it works fine.

  • procedure SetChosenLanguage(const I:integer): it should set the chosen language, and it does but up now only "partially". The language is changed for everything BUT the labels in all the Setup pages. So, button captions, message boxes, dialog boxes,... everything has the language set to the chosen one, but all the labels are still in the default (OS) language.

I tried to resolve using Refresh, Invalidate, Update, sending messages without any success. The label captions are still in the original default language.

The link below is a video showing my Test setup with the combobox and language changing. My default (OS) language is Italian. The video shows that even if I change the language, for example, to Deutsch, everything will change the language to Deustch BUT the labels.

http://screencast.com/t/SDI5VN67LFL

If someone has already resolved the problem please help me!


回答1:


You would have to re-set all the labels one by one the same way the TWizardForm code initializes them to the initial language.

For example:

SelectTasksLabel.Caption := ExpandSetupMessage(msgSelectTasksLabel2);

See TWizardForm.Create code for more.

There's no easier way. The strings are copied to the Windows (Win32) controls, they won't magically learn that you have changed the language. You have to overwrite the strings with the new values.

For example the labels of the "Next" and "Back" buttons are updated with the language change, because they are always re-set, when a page is changed, from TWizardForm.SetCurPage:

procedure TWizardForm.SetCurPage(const NewPageID: Integer);
...
begin
  ...
  BackButton.Caption := SetupMessages[msgButtonBack];
  if CurPageID = wpReady then begin
    NextButton.Caption := SetupMessages[msgButtonInstall];
    CancelButton.Caption := SetupMessages[msgButtonCancel];
  end else if ((CurPageID = wpPreparing) and PrepareToInstallNeedsRestart) or (CurPageID = wpFinished) then begin
    NextButton.Caption := SetupMessages[msgButtonFinish];
    CancelButton.Caption := SetupMessages[msgButtonCancel];
  end else begin
    NextButton.Caption := SetupMessages[msgButtonNext];
    CancelButton.Caption := SetupMessages[msgButtonCancel];
  end;
  ...
end;

But most other labels are static and are never updated, so they stay to the original language.



来源:https://stackoverflow.com/questions/33370054/inno-setup-change-the-setup-language-while-setup-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!