1
votes

Our application has about 400 calls to MessageDlg. The problem is translating the buttons and captions. The texts are defined as resourcestring constants within VCL pas files, but don't seem to pass through GnuGetText (I have checked both with the debugger and the gnugettext.log file). GnuGetText.pas is the first unit in my uses clause of the DPR file. However, all non-VCL resource strings as well as calls to _() are translated correctly.

The English original version button texts as well as their translations do exist in the .po and .mo files.

Adding My own copy of consts.pas to the project didn't change a thing, but the following code shows the a window saying 'Sí' twice (one from GnuGetText, the other from Windows), as expected:

  UseLanguage('es');
  MessageBox(0, PChar(SYesButton), '', MB_ICONWARNING or MB_OK);

I have to compile with Delphi5 due to component compatibility. If I place the VCL50.DE into the EXE dir, the button texts are German. The application should be translated to Spanish, and I am not aware of a Spanish VCL50.xx file.

A very similar project sharing 90 % of the source, compiled with Delphi 2010 and GnuGetText does use translated button texts, but window optics and string handling are different between the two compilers.

Your thoughts on how to get the MessageDlg buttons translated?

3

3 Answers

0
votes

The solution was to use the VCL's dialogs.pas as a basis for a very similar custom unit TranslatableDialogs defining functions with equal signature.

Also, we wrote a PHP script checking if all units using any of dialogs.pas' functions uses TranslatableDialogs because accidentally using the wrong unit is not often noticed by our testers as MessageDlg is called in many exceptional situations, not many of which are part of our standard test protocol. Important: TranslatableDialogs needs to be in the uses clause alone or later then the original dialogs.pas. The PHP script runs as part of our pre-publishing test suite.

0
votes

Use this Fonction it work fin for me:

function MensagemDlg(Msg: String; Title: String; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; Cod_Ajuda: Integer) : TModalResult;
var i   : Integer;
begin
  With CreateMessageDialog(Msg, DlgType, Buttons) Do
     Try
       Caption := Title;
       HelpContext := Cod_Ajuda;

       for i:= 0 To ComponentCount - 1 Do
         If Components[i] Is TButton
         Then
           Case (Components[i] As TButton).ModalResult Of
             mrNone     : (Components[i] As TButton).Caption := '&Help';         
             mrAbort    : (Components[i] As TButton).Caption := 'Abort';
             mrAll      : (Components[i] As TButton).Caption := '&All';
             mrCancel   : (Components[i] As TButton).Caption := '&Cancel';
             mrIgnore   : (Components[i] As TButton).Caption := '&Ignore';
             mrNo       : (Components[i] As TButton).Caption := '&No';
             mrNoToAll  : (Components[i] As TButton).Caption := 'No to All';
             mrOk       : (Components[i] As TButton).Caption := '&Ok';
             mrRetry    : (Components[i] As TButton).Caption := '&Retry';
             mrYes      : (Components[i] As TButton).Caption := '&Yes';
             mrYesToAll : (Components[i] As TButton).Caption := 'Yes to All';
           End;

       RESULT := ShowModal;
     Finally
       Free;
     End;
end;

Change each caption to match your preferred language.

Use it like this:

MensagemDlg('Are you sure ?','Warning',mtWarning,[mbyes,mbno],0)
0
votes

Expanding MensajemDlg above, I used this function with cxLocalizer resources to pass the localized parameters automatically.

After Implementing the function above do the following.

    MainFrm

interface

uses
StdCtrls // needed for TButton used in the function, added automatically by the IDE when saving project.


Private

Public
Hlp, Abrt, All, Cncel, Ignr, No, NotoAll,
Ok, Rtry, Yes, Warning, Information,
Confirmation,  YestoAll : string;
 function MensagemDlg(Msg: string; Title: string; DlgType: TMsgDlgType;
 procedure TranslationChanged;


function MainFrm.MensagemDlg(Msg: String; Title: String; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; Cod_Ajuda: Integer) : TModalResult;
var i   : Integer;
begin
  With CreateMessageDialog(Msg, DlgType, Buttons) Do
     Try
       Caption := Title;
       HelpContext := Cod_Ajuda;

       for i:= 0 To ComponentCount - 1 Do
         If Components[i] Is TButton
         Then
           Case (Components[i] As TButton).ModalResult Of
          mrNone:
            (Components[i] as TButton).Caption := Hlp; // '&Help';
          mrAbort:
            (Components[i] as TButton).Caption := Abrt; // 'Abort';
          mrAll:
            (Components[i] as TButton).Caption := All; // '&All';
          mrCancel:
            (Components[i] as TButton).Caption := Cncel; //'&Cancel';
          mrIgnore:
            (Components[i] as TButton).Caption := Ignr; //'&Ignore';
          mrNo:
            (Components[i] as TButton).Caption := No; //'&No';
          mrNoToAll:
            (Components[i] as TButton).Caption := NotoAll; // 'No to All';
          mrOk:
            (Components[i] as TButton).Caption := Ok; //'&Ok';
          mrRetry:
            (Components[i] as TButton).Caption := Rtry; //'&Retry';
          mrYes:
            (Components[i] as TButton).Caption := Yes; //'&Yes';
          mrYesToAll:
            (Components[i] as TButton).Caption := YestoAll; //'Yes to All';
           End;

       RESULT := ShowModal;
     Finally
       Free;
     End;
end;

procedure TMainFrm.FormCreate(Sender: TObject);
begin
  Hlp:= '&Help';
  Abrt := 'Abort';
  All := '&All';
  Cncel := '&Cancel';
  Ignr := '&Ignore';
  No := '&No';
  NotoAll := 'No to All';
  Ok := '&Ok';
  Rtry := '&Retry';
  Yes := '&Yes';
  YestoAll := 'Yes to All';
  Warning := 'Warning';
  Information := 'Information';
  Confirmation:= 'Confirmation';
end;

procedure TMainFrm.TranslationChanged;
begin
  //********* MessageDlg Buttons
  Hlp := cxGetResourceString(sHlp);
  Abrt := cxGetResourceString(sAbrt);
  All := cxGetResourceString(sAll);
  Cncel := cxGetResourceString(sCancel);
  Ignr := cxGetResourceString(sIgnr);
  No := cxGetResourceString(sNo);
  NotoAll := cxGetResourceString(sNoToAll);
  Ok := cxGetResourceString(sOK);
  Rtry := cxGetResourceString(sRtry);
  Yes := cxGetResourceString(sYes);
  YestoAll := cxGetResourceString(sYesToAll);
  //****************************

  //**************** MessageDlg Type
  Warning := cxGetResourceString(sWarning);
  Information := cxGetResourceString(sInformation);
  Confirmation := cxGetResourceString(sConfirmation);
  //************************************************
  end;

  procedure TMainFrm.Button1Click(Sender: TObject);
    begin

      if MessageLDlg(cxGetResourceString(sSomeStringResource),
       Confirmation, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
        begin
            //Do something
        end;
    end;