Jump to content
Nico Preto

TDialogService.MessageDialog translation

Recommended Posts

I'm not sure if this is what you're looking for, but see https://www.swissdelphicenter.ch/en/showcode.php?id=946, where we found the code below.


We've been using this code from there for more than ten years with no problems:


procedure HookResourceString(rs: PResStringRec; newStr: PChar);
  oldprotect: DWORD;
  VirtualProtect(rs, SizeOf(rs^), PAGE_EXECUTE_READWRITE, @oldProtect);
  rs^.Identifier := Integer(newStr);
  VirtualProtect(rs, SizeOf(rs^), oldProtect, @oldProtect);

  NewOK: PChar = 'New Ok';
  NewCancel: PChar = 'New Cancel';

  HookResourceString(@SMsgDlgOK, NewOK);
  HookResourceString(@SMsgDlgCancel, NewCancel);


Edited by Tom F

Share this post

Link to post

I do not develop on iOS or Android so I am unable to answer that question, Nico.

Share this post

Link to post

We have made the "SetSystemText" function below, to replace the hardcoded dialog strings. It works on all platforms including iOS and Android (thought we have had problems with only a partial implementation in MacOS in previous Delphi versions - not sure if it has been fully implemented yet).


It is a part of our own language handling class, but the idea is that fLines is a list of text lines loaded from a language file, where the ID is defined by a constant. Just replace this with your own source of translations.

The "LoadLangFromStrings" procedure is in FMX.Types.


procedure tProgStr.SetSystemText;
var lStrList: TStringList;
//Load list of translations for use everywhere the "Translate" function is used in Delphi.
  lStrList := TStringList.Create;
  lStrList.AddPair(SMsgDlgInformation, fLines[cStrInformation]);
  lStrList.AddPair(SMsgDlgError,       fLines[cStrError]);
  lStrList.AddPair(SMsgDlgConfirm,     fLines[cStrConfirmation]);
  lStrList.AddPair(SMsgDlgWarning,     fLines[cStrConfirmation]); //<- We don't have the "Warning" text translated
  lStrList.AddPair(SMsgDlgYes,         fLines[cStrYes]);
  lStrList.AddPair(SMsgDlgNo,          fLines[cStrNo]);
  lStrList.AddPair(SMsgDlgCancel,      fLines[cStrCancel]);
  lStrList.AddPair(SMsgDlgClose,       fLines[cStrClose]);
  lStrList.AddPair(SMsgDlgOK,          fLines[cStrOk]);
  lStrList.AddPair(SMsgDlgHelp,        fLines[cStrHelp]);
  lStrList.AddPair(SMsgDlgHelpHelp,    fLines[cStrHelp]);



Edited by Hans♫
  • Thanks 1

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now