* Allow TFormatSettings.Create with string (using callback)

This commit is contained in:
Michaël Van Canneyt 2025-02-19 20:36:54 +01:00
parent e062a54716
commit 35a21de57c
2 changed files with 19 additions and 1 deletions

View File

@ -54,6 +54,17 @@ begin
Result:=DefaultFormatSettings;
end;
class function TFormatSettings.Create(const LocaleName: string): TFormatSettings;
begin
// Catch
if LocaleName.StartsWith('en-US') then
Result:=TFormatSettings.Invariant
else if assigned(InitFormatSettingsHook) then
InitFormatSettingsHook(LocaleName,Result)
else
Raise ENotSupportedException.Create('No support for transforming locale name to format settings')
end;
procedure InitInternationalGeneric;
begin
fillchar(SysLocale,sizeof(SysLocale),0);

View File

@ -31,6 +31,8 @@ type
TMonthNameArray = array[1..12] of string;
TWeekNameArray = array[1..7] of string;
{ TFormatSettings }
TFormatSettings = record
CurrencyFormat: Byte;
NegCurrFormat: Byte;
@ -55,9 +57,11 @@ type
class function Invariant : TFormatSettings; static;
class function Create: TFormatSettings; overload; static; inline;
// class function Create(Locale: TLocaleID): TFormatSettings; overload; platform; static;
// class function Create(const LocaleName: string): TFormatSettings; overload; static;
class function Create(const LocaleName: string): TFormatSettings; overload; static;
end;
TInitFormatSettingsHook = Procedure(const aLocale : string; var aSettings : TFormatSettings);
var
DefaultFormatSettings : TFormatSettings = (
CurrencyFormat: 1;
@ -84,7 +88,10 @@ var
TwoDigitYearCenturyWindow: 50;
);
FormatSettings : TFormatSettings absolute DefaultFormatSettings;
InitFormatSettingsHook : TInitFormatSettingsHook;
{ ---------------------------------------------------------------------
Date formatting settings
---------------------------------------------------------------------}