Nico Preto 0 Posted September 6, 2022 Any tip to translate TDialogService.MessageDialog method? Thanks Share this post Link to post
Tom F 83 Posted September 7, 2022 (edited) 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); var oldprotect: DWORD; begin VirtualProtect(rs, SizeOf(rs^), PAGE_EXECUTE_READWRITE, @oldProtect); rs^.Identifier := Integer(newStr); VirtualProtect(rs, SizeOf(rs^), oldProtect, @oldProtect); end; const NewOK: PChar = 'New Ok'; NewCancel: PChar = 'New Cancel'; initialization HookResourceString(@SMsgDlgOK, NewOK); HookResourceString(@SMsgDlgCancel, NewCancel); Edited September 7, 2022 by Tom F Share this post Link to post
Nico Preto 0 Posted September 8, 2022 This code works on iOS and Android? Share this post Link to post
Tom F 83 Posted September 8, 2022 I do not develop on iOS or Android so I am unable to answer that question, Nico. Share this post Link to post
Hans♫ 75 Posted September 9, 2022 (edited) 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; begin //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]); LoadLangFromStrings(lStrList); lStrList.Free; end; Edited September 9, 2022 by Hans♫ 1 Share this post Link to post