Dulkan
Dulkan

Reputation: 113

How to display localized Program Files name (display name) during installation?

I'm currently creating an installer, which has Program Files as its default installation directory. To do this, I used {pf}.

It's a German program and only used in Germany and while the installer is entirely in German during selection of the destination directory, setup still displays C:\Program Files instead of the localized name C:\Programme.

Is it possible to get it to display C:\Programme instead? Functionally everything works fine, the application is installed in C:\Programme. I'm just concerned a basic user may be confused by reading C:\Program Files.

EDIT: Further information: I know C:\Programme or any other localized name for Program Files is just a display name, the physical path is always Program Files. Doesn't matter which Windows version or what language Windows has. Yet I'd still like setup to display C:\Programme during installation.

My test machines are on Windows 7 and Windows 10.

Upvotes: 1

Views: 252

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202330

Inno Setup does not support that.

You would have to fake it. You can dynamically translate contents of the DirEdit to/from a display name as needed:

  • translate to display name, when the "Select Destination Location" page is activated
  • translate to physical path, when "Browse" button is clicked.
  • translate to display name, when new path is selected.
  • translate to physical path, when "Next" button is clicked.
function ToDisplayName(Path: string): string;
begin
  Result := ???;
end;

function FromDisplayName(Path: string): string;
begin
  Result := ???;
end;

var
  DirBrowseButtonClickOrig: TNotifyEvent;
  OnSelectDir: Boolean;

procedure DirBrowseButtonClick(Sender: TObject);
begin
  WizardForm.DirEdit.Text := FromDisplayName(WizardForm.DirEdit.Text);
  DirBrowseButtonClickOrig(Sender);
  WizardForm.DirEdit.Text := ToDisplayName(WizardForm.DirEdit.Text);
end;

procedure InitializeWizard();
begin
  DirBrowseButtonClickOrig := WizardForm.DirBrowseButton.OnClick;
  WizardForm.DirBrowseButton.OnClick := @DirBrowseButtonClick;
  OnSelectDir := False;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectDir then
  begin
    OnSelectDir := True;
    WizardForm.DirEdit.Text := ToDisplayName(WizardForm.DirEdit.Text);
  end
    else
  begin
    if OnSelectDir then
    begin
      OnSelectDir := False;
      WizardForm.DirEdit.Text := FromDisplayName(WizardForm.DirEdit.Text);
    end;
  end;
end;

A tricky part is of course the implementation of the ToDisplayName and FromDisplayName functions.

A real native implementation would be pretty complex and it's even questionable if you can implement it with limited features of the Pascal Script (particularly a lack of pointers).

But for your specific needs, you can use something as trivial as:

[CustomMessages]
ProgramFilesLocalized=Programme

[Code]

function ToDisplayName(Path: string): string;
begin
  StringChange(Path, '\Program Files', '\' + CustomMessage('ProgramFilesLocalized'));
  Result := Path;
end;

function FromDisplayName(Path: string): string;
begin
  StringChange(Path, '\' + CustomMessage('ProgramFilesLocalized'), '\Program Files');
  Result := Path;
end;

enter image description here


If you need a real implementation for converting to/from display name, consider asking a separate question.

Upvotes: 1

Related Questions