1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
unit PoFamilyLists;
{$mode objfpc}{$H+}
interface
Uses
Classes, SysUtils, ContNrs, LCLProc, LazFileUtils,
//{$IFDEF UNIX}{$IFNDEF DisableCWString}, cwstring{$ENDIF}{$ENDIF},
PoFamilies, PoCheckerConsts;
type
{ TPoFamilyList }
TPoFamilyList = class
private
FLangID: TLangID;
FList: TFPObjectList;
FOnTestEnd: TTestEndEvent;
FOnTestStart: TTestStartEvent;
FPoFamilyStats: TPoFamilyStats;
FTestOptions: TPoTestOptions;
FTestTypes: TPoTestTypes;
function GetItem(Index: Integer): TPoFamily;
//procedure SetItem(Index: Integer; AValue: TPoFamily);
protected
procedure DoTestStart(const ATestName, APoFileName: String);
procedure DoTestEnd(const ATestName: String; const ErrorCount: Integer);
public
constructor Create(AMasterList: TStrings; ALangID: TLangID; out Msg: String);
destructor Destroy; override;
procedure Add(PoFamily: TPofamily);
function Count: Integer;
procedure RunTests(out ErrorCount, NonFuzzyErrorCount, WarningCount,
TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount: Integer;
ErrorLog, StatLog, DupLog: TStringList);
property Items[Index: Integer]: TPoFamily read GetItem; // write SetItem;
property PoFamilyStats: TPoFamilyStats read FPoFamilyStats;
property TestTypes: TPoTestTypes read FTestTypes write FTestTypes;
property TestOptions: TPoTestOptions read FTestOptions write FTestOptions;
property OnTestStart: TTestStartEvent read FOnTestStart write FOnTestStart;
property OnTestEnd: TTestEndEvent read FOnTestEnd write FOnTestEnd;
end;
implementation
{ TPoFamilyList }
function TPoFamilyList.GetItem(Index: Integer): TPoFamily;
begin
Result := TPoFamily(FList.Items[Index]);
end;
procedure TPoFamilyList.DoTestStart(const ATestName, APoFileName: String);
begin
if Assigned(FOnTestStart) then FOnTestStart(ATestName, APoFileName);
end;
procedure TPoFamilyList.DoTestEnd(const ATestName: String; const ErrorCount: Integer);
begin
if Assigned(FOnTestEnd) then FOnTestEnd(ATestName, ErrorCount);
end;
constructor TPoFamilyList.Create(AMasterList: TStrings; ALangID: TLangID; out Msg: String);
var
i: Integer;
MasterName, ChildName: String;
APoFamily: TPoFamily;
begin
FList := TFPObjectList.Create(True);
Msg := '';
FPoFamilyStats := TPoFamilyStats.Create;
FLangID := ALangID;
for i := 0 to AMasterList.Count - 1 do
begin
MasterName := AMasterList[i];
ChildName := '';
if FileExistsUtf8(MasterName) then
begin
if (ALangID <> lang_all) then
ChildName := ChangeFileExt(MasterName, '.' + LanguageAbbr[ALangID] + '.po');
//debugln('TPoFamilyList.Create: i = ',DbgS(i),' Adding TPoFamily.Create(''',ExtractFileName(MasterName),
// ''',',ExtractFileName(ChildName),''')');
if (ALangID = lang_all) or FileExistsUtf8(ChildName) then
begin
APoFamily := TPoFamily.Create(MasterName, ChildName);
Add(APoFamily);
end
else
Msg := Msg + Format('"%s"',[ChildName]) + LineEnding;
end
else
Msg := Msg + Format('"%s"',[MasterName]) + LineEnding;
end;
end;
destructor TPoFamilyList.Destroy;
begin
//debugln('TPoFamilyList.Destroy: FList.Count = ',DbgS(FList.Count));
PoFamilyStats.Free;
FList.Free;
inherited Destroy;
end;
procedure TPoFamilyList.Add(PoFamily: TPofamily);
begin
FList.Add(PoFamily);
end;
function TPoFamilyList.Count: Integer;
begin
Result := FList.Count;
end;
procedure TPoFamilyList.RunTests(out ErrorCount, NonFuzzyErrorCount, WarningCount, TotalTranslatedCount, TotalUntranslatedCount, TotalFuzzyCount: Integer;
ErrorLog, StatLog, DupLog: TStringList);
var
Index, ThisErrorCount, ThisNonFuzzyErrorCount, ThisWarningCount: Integer;
ThisTranslatedCount, ThisUntranslatedCount, ThisFuzzyCount: Integer;
PoFamily: TPoFamily;
begin
if (FLangID = lang_all) then
Include(FTestOptions,ptoFindAllChildren)
else
Exclude(FTestOptions,ptoFindAllChildren);
ErrorCount := NoError;
NonFuzzyErrorCount := NoError;
WarningCount := NoError;
TotalTranslatedCount := 0;
TotalUntranslatedCount := 0;
TotalFuzzyCount := 0;
FPoFamilyStats.Clear;
for Index := 0 to FList.Count - 1 do
begin
PoFamily := GetItem(Index);
PoFamily.OnTestStart := FOnTestStart;
PoFamily.OnTestEnd := FOnTestEnd;
PoFamily.TestTypes := FTesttypes;
PoFamily.TestOptions := FTestOptions;
PoFamily.RunTests(ThisErrorCount, ThisNonFuzzyErrorCount, ThisWarningCount, ThisTranslatedCount, ThisUntranslatedCount, ThisFuzzyCount, ErrorLog, StatLog, DupLog);
PoFamily.PoFamilyStats.AddItemsTo(FPoFamilyStats);
ErrorCount := ErrorCount + ThisErrorCount;
NonFuzzyErrorCount := NonFuzzyErrorCount + ThisNonFuzzyErrorCount;
WarningCount := WarningCount + ThisWarningCount;
TotalTranslatedCount := TotalTranslatedCount + ThisTranslatedCount;
TotalUntranslatedCount := TotalUntranslatedCount + ThisUntranslatedCount;
TotalFuzzyCount := TotalFuzzyCount + ThisFuzzyCount;
end;
end;
end.
|