spiegel-keyman/windows/src/global/delphi/cust/Keyman.System.LocaleStrings.pas
Marc Durdin b1ed449ea6 fix(windows): start data refactor for http
Start moving data from forms to models/controllers for
onlineupdate and establish a shared data pattern for
transitional refactoring. Also establish a TLocaleStrings
class which has no global variable dependency.
2020-05-13 06:41:35 +10:00

46 lines
1.3 KiB
ObjectPascal

unit Keyman.System.LocaleStrings;
interface
uses
keymanapi_TLB,
MessageIdentifierConsts;
type
TLocaleStrings = class
class function MsgFromId(kmcom: IKeyman; const msgid: TMessageIdentifier): string;
class function MsgFromStr(kmcom: IKeyman; const str: string): string;
class function MsgFromIdFormat(kmcom: IKeyman; const msgid: TMessageIdentifier; const args: array of const): string;
end;
implementation
uses
System.SysUtils,
custinterfaces;
class function TLocaleStrings.MsgFromStr(kmcom: IKeyman; const str: string): string;
begin
if kmcom = nil
then Result := str
else Result := Trim((kmcom.Control as IKeymanCustomisationAccess).KeymanCustomisation.CustMessages.MessageFromID(str));
end;
class function TLocaleStrings.MsgFromId(kmcom: IKeyman; const msgid: TMessageIdentifier): string;
begin
if kmcom = nil
then Result := IntToStr(Ord(msgid))
else Result := Trim((kmcom.Control as IKeymanCustomisationAccess).KeymanCustomisation.CustMessages.MessageFromID(StringFromMsgId(msgid)));
end;
class function TLocaleStrings.MsgFromIdFormat(kmcom: IKeyman; const msgid: TMessageIdentifier; const args: array of const): string;
begin
try
Result := Format(MsgFromId(kmcom, msgid), args);
except
Result := MsgFromId(kmcom, msgid) + ' (error displaying message parameters)';
end;
end;
end.