SiComponents Home Page SiComponents Forums
Here you will be able to get help and share your experience
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Translating the MessageBox

 
Post new topic   Reply to topic    SiComponents Forums Forum Index -> TsiLang Components Suite
View previous topic :: View next topic  
Author Message
rdeutsch



Joined: 23 Feb 2006
Posts: 6

PostPosted: Thu Mar 02, 2006 3:17 pm    Post subject: Translating the MessageBox Reply with quote

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
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2103

PostPosted: Thu Mar 02, 2006 7:07 pm    Post subject: Reply with quote

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

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. Smile
Back to top
View user's profile Send private message
rdeutsch



Joined: 23 Feb 2006
Posts: 6

PostPosted: Fri Mar 03, 2006 7:37 am    Post subject: Reply with quote

Hi isiticov

Thanks a lot. It works perfectly. Very Happy

And with no type mistakes...Wink

Best regards
Robert
Back to top
View user's profile Send private message
Melamori



Joined: 02 May 2006
Posts: 5

PostPosted: Tue May 02, 2006 3:26 pm    Post subject: Reply with quote

Can you write this code for c++ builder, please?
Is it necessary to add this code to every file in which I use MessagBox?
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2103

PostPosted: Wed May 03, 2006 7:57 am    Post subject: Reply with quote

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

Code:
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.
Back to top
View user's profile Send private message
Melamori



Joined: 02 May 2006
Posts: 5

PostPosted: Wed May 03, 2006 9:31 am    Post subject: Reply with quote

Thank you very much - it works Smile
Back to top
View user's profile Send private message
many



Joined: 16 Aug 2006
Posts: 6

PostPosted: Tue Aug 22, 2006 6:50 pm    Post subject: Message box Reply with quote

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. Very Happy
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2103

PostPosted: Wed Aug 23, 2006 3:50 am    Post subject: Reply with quote

Just be sure to add
Code:
#include "siComp.hpp"
in your header. Wink
Back to top
View user's profile Send private message
many



Joined: 16 Aug 2006
Posts: 6

PostPosted: Wed Aug 23, 2006 3:13 pm    Post subject: InternalMessageDlg Reply with quote

Thanks. I'll try.
Back to top
View user's profile Send private message
many



Joined: 16 Aug 2006
Posts: 6

PostPosted: Wed Aug 23, 2006 11:20 pm    Post subject: parameters to pass Reply with quote

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.
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2103

PostPosted: Thu Aug 24, 2006 3:26 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
many



Joined: 16 Aug 2006
Posts: 6

PostPosted: Tue Aug 29, 2006 8:20 pm    Post subject: message box Reply with quote

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.
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2103

PostPosted: Wed Aug 30, 2006 4:15 am    Post subject: Reply with quote

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/CPP_MessageBox.zip

Hope this helps.
Back to top
View user's profile Send private message
Angus



Joined: 10 Dec 2006
Posts: 21
Location: New Zealand

PostPosted: Tue Nov 06, 2007 4:54 am    Post subject: Messagebox header and buttons Reply with quote

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.
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2103

PostPosted: Tue Nov 06, 2007 9:17 am    Post subject: Reply with quote

http://www.tsilang.com/delphiglobalizationtool_faq.html#21 Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SiComponents Forums Forum Index -> TsiLang Components Suite All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by p h p B B  © 2001, 2005 p h p B B  Group