Skip to content

Commit

Permalink
Issue #719: For message dialog button captions, prefer localized stri…
Browse files Browse the repository at this point in the history
…ngs from user32.dll over our translation from Transifex
  • Loading branch information
ansgarbecker committed Sep 26, 2019
1 parent 9b52648 commit 1f22580
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions source/apphelpers.pas
Expand Up @@ -337,6 +337,7 @@ TAppSettings = class(TObject)
function MessageDialog(const Title, Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; KeepAskingSetting: TAppSettingIndex=asUnused): Integer; overload; function MessageDialog(const Title, Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; KeepAskingSetting: TAppSettingIndex=asUnused): Integer; overload;
function ErrorDialog(Msg: string): Integer; overload; function ErrorDialog(Msg: string): Integer; overload;
function ErrorDialog(const Title, Msg: string): Integer; overload; function ErrorDialog(const Title, Msg: string): Integer; overload;
function GetLocaleString(const ResourceId: Integer): WideString;
function GetHTMLCharsetByEncoding(Encoding: TEncoding): String; function GetHTMLCharsetByEncoding(Encoding: TEncoding): String;
procedure ParseCommandLine(CommandLine: String; var ConnectionParams: TConnectionParameters; var FileNames: TStringList); procedure ParseCommandLine(CommandLine: String; var ConnectionParams: TConnectionParameters; var FileNames: TStringList);
function f_(const Pattern: string; const Args: array of const): string; function f_(const Pattern: string; const Args: array of const): string;
Expand Down Expand Up @@ -366,6 +367,7 @@ TAppSettings = class(TObject)
mtCriticalConfirmation: TMsgDlgType = mtCustom; mtCriticalConfirmation: TMsgDlgType = mtCustom;
ConfirmIcon: TIcon; ConfirmIcon: TIcon;
NumberChars: TSysCharSet; NumberChars: TSysCharSet;
LibHandleUser32: THandle;


implementation implementation


Expand Down Expand Up @@ -2341,19 +2343,24 @@ function MessageDialog(const Title, Msg: string; DlgType: TMsgDlgType; Buttons:
Hotkeys: String; Hotkeys: String;
WebSearchUrl, WebSearchHost: String; WebSearchUrl, WebSearchHost: String;


procedure AddButton(BtnCaption: String; BtnResult: TModalResult); procedure AddButton(BtnCaption: String; BtnResult: TModalResult; ResourceId: Integer=0);
var var
i: Integer; i: Integer;
cap: String; cap: String;
begin begin
Btn := TTaskDialogButtonItem(Dialog.Buttons.Add); Btn := TTaskDialogButtonItem(Dialog.Buttons.Add);
cap := _(BtnCaption); if ResourceId > 0 then begin
for i:=1 to Length(cap) do begin // Prefer string from user32.dll
// Auto apply hotkey cap := GetLocaleString(ResourceId)
if (Pos(LowerCase(cap[i]), Hotkeys) = 0) and Character.TCharacter.IsLetter(cap[i]) then begin end else begin
Hotkeys := Hotkeys + LowerCase(cap[i]); cap := _(BtnCaption);
Insert('&', cap, i); for i:=1 to Length(cap) do begin
break; // Auto apply hotkey
if (Pos(LowerCase(cap[i]), Hotkeys) = 0) and Character.TCharacter.IsLetter(cap[i]) then begin
Hotkeys := Hotkeys + LowerCase(cap[i]);
Insert('&', cap, i);
break;
end;
end; end;
end; end;
Btn.Caption := cap; Btn.Caption := cap;
Expand Down Expand Up @@ -2421,17 +2428,17 @@ function MessageDialog(const Title, Msg: string; DlgType: TMsgDlgType; Buttons:
// Add buttons // Add buttons
for MsgButton in Buttons do begin for MsgButton in Buttons do begin
case MsgButton of case MsgButton of
mbYes: AddButton('Yes', mrYes); mbYes: AddButton('Yes', mrYes, 805);
mbNo: AddButton('No', mrNo); mbNo: AddButton('No', mrNo, 806);
mbOK: AddButton('OK', mrOk); mbOK: AddButton('OK', mrOk, 800);
mbCancel: AddButton('Cancel', mrCancel); mbCancel: AddButton('Cancel', mrCancel, 801);
mbAbort: AddButton('Abort', mrAbort); mbAbort: AddButton('Abort', mrAbort, 802);
mbRetry: AddButton('Retry', mrRetry); mbRetry: AddButton('Retry', mrRetry, 803);
mbIgnore: AddButton('Ignore', mrIgnore); mbIgnore: AddButton('Ignore', mrIgnore, 804);
mbAll: AddButton('All', mrAll); mbAll: AddButton('All', mrAll);
mbNoToAll: AddButton('No to all', mrNoToAll); mbNoToAll: AddButton('No to all', mrNoToAll);
mbYesToAll: AddButton('Yes to all', mrYesToAll); mbYesToAll: AddButton('Yes to all', mrYesToAll);
mbClose: AddButton('Close', mrClose); mbClose: AddButton('Close', mrClose, 807);
end; end;
end; end;


Expand Down Expand Up @@ -2489,6 +2496,21 @@ function ErrorDialog(const Title, Msg: string): Integer;
end; end;




function GetLocaleString(const ResourceId: Integer): WideString;
var
Buffer: WideString;
BufferLen: Integer;
begin
Result := '';
if LibHandleUser32 <> 0 then begin
SetLength(Buffer, 255);
BufferLen := LoadStringW(LibHandleUser32, ResourceId, PWideChar(Buffer), Length(Buffer));
if BufferLen <> 0 then
Result := Copy(Buffer, 1, BufferLen);
end;
end;


function GetHTMLCharsetByEncoding(Encoding: TEncoding): String; function GetHTMLCharsetByEncoding(Encoding: TEncoding): String;
begin begin
Result := ''; Result := '';
Expand Down Expand Up @@ -4201,6 +4223,7 @@ initialization


NumberChars := ['0'..'9', FormatSettings.DecimalSeparator, FormatSettings.ThousandSeparator]; NumberChars := ['0'..'9', FormatSettings.DecimalSeparator, FormatSettings.ThousandSeparator];


LibHandleUser32 := LoadLibrary('User32.dll');


end. end.


Expand Down

0 comments on commit 1f22580

Please sign in to comment.