2

Please help implement selection of language for application (not for installer).

I have a working script. I want to add combobox or other control element to select language for the application this script is used to install. First I tried to use this piece of code, and this is working:

[Languages]
Name: en; MessagesFile: "compiler:m_Default_en.isl"
; Chinese
Name: cn; MessagesFile: "compiler:m_Default_cn.isl"  

[Registry]
Root: HKCU; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}"; ValueType: string; ValueName: "language"; ValueData: "zh_CN"; Languages: cn
Root: HKCU; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}"; ValueType: string; ValueName: "language"; ValueData: "en_US"; Languages: en

What this does is asking to select language that will be used during setup (if default translation is used). Then depending on choice it writes value to register. And then after installation application reads this register on startup and uploads corresponding translation file.

The problem is I want this window with language selection to appear after "Create Desktop icon" page. But it always appears very first on launching setup.

Maybe there's another solution? I am new to Inno Setup script.

I am using Inno Setup Compiler 5.5.9.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Vadixem
  • 99
  • 9
  • *"I want this window with language selection to appear after "Create Desktop icon" page."* - Why? The dialog is there primarily to select the language of the installer. So it has to be the very first thing that the user sees. If you want to ask anywhere else, you have to use your own custom selection that will have no effect on the installer itself. – Martin Prikryl Apr 10 '18 at 15:08
  • @MartinPrikryl Thanks for reply! Yeah I mentioned that that may be not the best decision. Do you have an idea how to do that? – Vadixem Apr 10 '18 at 15:15

2 Answers2

4

You have to use your own custom selection page. You can start with CreateInputOptionPage:

[Registry]
Root: HKCU; Subkey: "Software\MyProgram"; ValueType: string; \
  ValueName: "language"; ValueData: "{code:GetAppLanguage}"

[Code]

var
  LanguagePage: TInputOptionWizardPage;
  Languages: TStrings;
  LanguageDefault: string; 

function GetAppLanguage(Param: string): string;
begin
  { Should always be true }
  if LanguagePage.SelectedValueIndex >= 0 then
    Result := Languages[LanguagePage.SelectedValueIndex];
end;

procedure AddLanguage(Code: string; Name: string);
var
  Index: Integer;
begin
  Index := LanguagePage.Add(Name);
  Languages.Add(Code);
  if Code = LanguageDefault then
  begin
    LanguagePage.Values[Index] := True;
  end;
end;

procedure InitializeWizard();
begin
  RegQueryStringValue(
    HKEY_CURRENT_USER, 'Software\MyProgram', 'language', LanguageDefault);

  LanguagePage :=
    CreateInputOptionPage(
      wpSelectTasks, 'Application language', '', '', True, True);

  Languages := TStringList.Create;
  AddLanguage('zh_CN', 'Chinese');
  AddLanguage('en_US', 'English');
  LanguagePage.CheckListBox.Color := clBtnFace
  LanguagePage.CheckListBox.WantTabs := True
  LanguagePage.CheckListBox.BorderStyle := bsNone;
  LanguagePage.CheckListBox.MinItemHeight := WizardForm.TasksList.MinItemHeight;
  if LanguagePage.SelectedValueIndex < 0 then
  begin
    LanguagePage.Values[0] := True;
  end;
end;

enter image description here


Though note that configuring user preferences in an installer (possibly running under a different local account) is problematic. See Installing application for currently logged in user from Inno Setup installer running as Administrator.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

Thanks a lot @MartinPrikryl !!! I also made some changes so now installer gets the language value from register and sets corresponding option in radio box as default:

[Registry]
Root: HKCU; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}"; ValueType: string; ValueName: "language"; ValueData: "{code:GetAppLanguage}"

[Code]

var
  LanguagePage: TInputOptionWizardPage;
  Languages: TStrings;
  LanguageDefault: String; 
  DefaultLanguageIndex: Integer;

function GetAppLanguage(Param: string): string;
begin
  { Should always be true }
  if LanguagePage.SelectedValueIndex >= 0 then
    Result := Languages[LanguagePage.SelectedValueIndex];
end;

procedure AddLanguage(Code: string; Name: string);
begin
  LanguagePage.Add(Name);
  Languages.Add(Code);
end;

procedure InitializeWizard();
begin
  LanguagePage :=
    CreateInputOptionPage(wpSelectTasks, 'Select application language', 'Which language will be used in buttons, tooltips, dialogs etc.?', 'Available translations:', True, True);
  Languages := TStringList.Create;
  AddLanguage('en_US', 'English');
  AddLanguage('zh_CN', 'Chinese');
  LanguagePage.CheckListBox.Color := clBtnFace;
  LanguagePage.CheckListBox.WantTabs := True;
  LanguagePage.CheckListBox.BorderStyle := bsNone;
  { Set language by default to English }
  DefaultLanguageIndex := 0;
  { Get language from register if application was previously installed and set corresponding radiobox on select language }                               
  if RegQueryStringValue(HKEY_CURRENT_USER, 'Software\{#MyAppPublisher}\{#MyAppName}', 'language', LanguageDefault) then begin
    if LanguageDefault = 'zh_CN' then
  DefaultLanguageIndex := 1;
  end;
  LanguagePage.Values[DefaultLanguageIndex] := True;
end;
Vadixem
  • 99
  • 9