Reputation: 99
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.
Upvotes: 2
Views: 1116
Reputation: 202594
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;
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.
Upvotes: 5