Translating the MessageBox

All announcements, questions and issues related to the TsiLang Components Suite.
Post Reply
rdeutsch
Posts: 6
Joined: Thu Feb 23, 2006 3:23 pm

Translating the MessageBox

Post by rdeutsch »

Hi

We have many message dialogs of the windows-type "MessageBox" in our code.
Is there a way to internationalize these type of dialog box? Yes, we can translate the messagetext, no problem, but what about the "Yes", "No", etc. buttoncaptions?

I've read the FAQ and i know that there are the tsilang versions of MessageDlg and MessageDlgPos, but these dialog boxes have not the same possibilites like the windows messagebox. What we need is to set the headerline of a dialog box.

Thanks and best regards
Robert
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

In order to internationalize this you will still need to use TsiLang's methods with small trick:

Code: Select all

type
  TAccessLang = class(TsiCustomLang)
  end;
function InternalMessageDlg(const siLang: TsiCustomLang; const MsgCaption: string; const Msg: string; DlgType:  TMsgDlgType;  Buttons: TMsgDlgButtons; HelpCtx: Longint;  const DefaultBtn: TMsgDlgBtn = mbOK;  const CancelBtn: TMsgDlgBtn = mbCancel): Integer;
begin
  with TAccessLang(siLang).CreateMessageDialog(Msg, DlgType, Buttons, DefaultBtn, CancelBtn) do
  try
    HelpContext := HelpCtx;
    HelpFile := Application.HelpFile;
    Caption := MsgCaption;
    Result := ShowModal;
  finally
    Release;
  end;
end;
And use InternalMessageDlg() in your code instead of MessageBox, passing there the TsiLang instance and needed captions for dialogs.
Does this help?

P.S. Typed from scratch so it may contain mistypes. :)
Best regards,
Igor Siticov.
rdeutsch
Posts: 6
Joined: Thu Feb 23, 2006 3:23 pm

Post by rdeutsch »

Hi isiticov

Thanks a lot. It works perfectly. :D

And with no type mistakes...:wink:

Best regards
Robert
Melamori
Posts: 5
Joined: Tue May 02, 2006 2:35 pm

Post by Melamori »

Can you write this code for c++ builder, please?
Is it necessary to add this code to every file in which I use MessagBox?
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

I'm not a C++ Guru but you can try:

Code: Select all

class PASCALIMPLEMENTATION TAccessLang : public TsiCustomLang
{
	typedef TsiCustomLang inherited;
  public:
    Forms::TForm* __fastcall CreateMessageDialog(const AnsiString Msg, Dialogs::TMsgDlgType DlgType, Dialogs::TMsgDlgButtons Buttons, const Dialogs::TMsgDlgBtn DefaultBtn = (Dialogs::TMsgDlgBtn)(0x2), const Dialogs::TMsgDlgBtn CancelBtn = (Dialogs::TMsgDlgBtn)(0x3)) {
      return (TsiCustomLang::CreateMessageDialog(Msg, DlgType, Buttons, DefaultBtn, CancelBtn));
    }
};


int __fastcall InternalMessageDlg(const TsiCustomLang * siLang, const AnsiString MsgCaption, const AnsiString Msg, Dialogs::TMsgDlgType DlgType, Dialogs::TMsgDlgButtons Buttons, int HelpCtx, const Dialogs::TMsgDlgBtn DefaultBtn = (Dialogs::TMsgDlgBtn)(0x2), const Dialogs::TMsgDlgBtn CancelBtn = (Dialogs::TMsgDlgBtn)(0x3)){
  TAccessLang * ALang = (TAccessLang *)siLang;
  TForm * MsgForm = ALang->CreateMessageDialog(Msg, DlgType, Buttons, DefaultBtn, CancelBtn);
  int I;
  try
  {
    MsgForm->HelpContext = HelpCtx;
    MsgForm->HelpFile = Application->HelpFile;
    MsgForm->Caption = MsgCaption;
    I = MsgForm->ShowModal();
    return (I);
  }
  __finally
  {
    MsgForm->Release();
  }
  return (I);
}
You can place this code in some global unit and just call it instead of MessageBox.
Hope this helps.
Best regards,
Igor Siticov.
Melamori
Posts: 5
Joined: Tue May 02, 2006 2:35 pm

Post by Melamori »

Thank you very much - it works :)
many
Posts: 6
Joined: Wed Aug 16, 2006 5:15 pm

Message box

Post by many »

I use C++Builder as well. I copy the 2nd code into a unit, compiled it. I got quite a few errorr:
Error: E2303 type name expected @
class PASCALIMPLEMENTATION TAccessLang : public TsiCustomLang
{

Error: E2090 Qulifier "TsiCustomLang' is not a class or namespace name @
return (TsiCustomLang::CreateMessageDialog(Msg, DlgType, Buttons, DefaultBtn, CancelBtn));

and some more. Please point me what's wrong there. Thank you. :D
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Just be sure to add

Code: Select all

#include "siComp.hpp"
in your header. :wink:
Best regards,
Igor Siticov.
many
Posts: 6
Joined: Wed Aug 16, 2006 5:15 pm

InternalMessageDlg

Post by many »

Thanks. I'll try.
many
Posts: 6
Joined: Wed Aug 16, 2006 5:15 pm

parameters to pass

Post by many »

It works. No more error as I included #include "siComp.hpp".
Another question:
What is the last two parameters to pass when make the call?
const Dialogs::TMsgDlgBtn DefaultBtn = (Dialogs::TMsgDlgBtn)(0x2),
const Dialogs::TMsgDlgBtn CancelBtn = (Dialogs::TMsgDlgBtn)(0x3))
Thankyou.
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hello,

These are just default button and cancel button (with default values set to mbOK and mbCancel). So you can either omit these parameters or pas your values you need to be used as default or cancel button.
Best regards,
Igor Siticov.
many
Posts: 6
Joined: Wed Aug 16, 2006 5:15 pm

message box

Post by many »

I still struggle with the code you provided to replace the mesaage box.
What is the first parameter to pass when making the call?
InternalMessageDlg(const TsiCustomLang * siLang, ...
The TsiCustomLang data type.
If possible, please give me an example of the call.
Thanks for your help so far.
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hi,

You can use something like this:
InternalMessageDlg(siLang1, "Some caption", "Some message text!", mtWarning, TMsgDlgButtons() << mbOK << mbCancel << mbYes << mbNo, 0, mbOK, mbCancel);


The full example (BCB6) project could be downloaded from:
http://www.sicomponents.com/soft/demos/ ... ageBox.zip

Hope this helps.
Best regards,
Igor Siticov.
Angus
Posts: 21
Joined: Sun Dec 10, 2006 11:39 pm
Location: New Zealand

Messagebox header and buttons

Post by Angus »

Hi,
I've used siComponents example code for Messagebox

InternalMessageDlg(siLang1,siLang1->GetTextOrDefault("IDS_8" /* "Test" */ ),siLang1->GetTextOrDefault("IDS_8" /* "Test" */ ),mtWarning, mbOKCancel , 0 );

However, in Japanese the message itself comes out as it should, but the dialogs Header caption and buttons are garbled. How do i get these to also show in Japanese? (the Dialogs section in the Translations tree view on the translation Editor have all be translated into Japanese.

Many Thanks
Angus.
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Best regards,
Igor Siticov.
Post Reply