Page 1 of 1
Translating the MessageBox
Posted: Thu Mar 02, 2006 3:17 pm
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
Posted: Thu Mar 02, 2006 7:07 pm
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.

Posted: Fri Mar 03, 2006 7:37 am
by rdeutsch
Hi isiticov
Thanks a lot. It works perfectly.
And with no type mistakes...
Best regards
Robert
Posted: Tue May 02, 2006 3:26 pm
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?
Posted: Wed May 03, 2006 7:57 am
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.
Posted: Wed May 03, 2006 9:31 am
by Melamori
Thank you very much - it works

Message box
Posted: Tue Aug 22, 2006 6:50 pm
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.

Posted: Wed Aug 23, 2006 3:50 am
by isiticov
Just be sure to add
in your header.

InternalMessageDlg
Posted: Wed Aug 23, 2006 3:13 pm
by many
Thanks. I'll try.
parameters to pass
Posted: Wed Aug 23, 2006 11:20 pm
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.
Posted: Thu Aug 24, 2006 3:26 am
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.
message box
Posted: Tue Aug 29, 2006 8:20 pm
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.
Posted: Wed Aug 30, 2006 4:15 am
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.
Messagebox header and buttons
Posted: Tue Nov 06, 2007 4:54 am
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.
Posted: Tue Nov 06, 2007 9:17 am
by isiticov