PoChecker: Add function to check for troublesome po-files. Patch by Péter Gábor. Issue #0027093.

git-svn-id: trunk@51904 -
This commit is contained in:
bart 2016-03-10 17:22:11 +00:00
parent b6be126cf2
commit 3ef7eb18fb
3 changed files with 120 additions and 40 deletions

View File

@ -97,6 +97,12 @@ resourcestring
sPercUntranslated = '%s: %4.1f%% untranslated strings.'; sPercUntranslated = '%s: %4.1f%% untranslated strings.';
sPercFuzzy = '%s: %4.1f%% fuzzy strings.'; sPercFuzzy = '%s: %4.1f%% fuzzy strings.';
sFindTroublesomeFiles = 'Find troublesome files';
sNoTroublesomePoFilesFound = 'No troublesome .po files found';
sTheFollowingMasterPoFileSAddedToTheList = 'The following %s master .po file(s) added to the list:';
sTheFollowingOrphanedPoFileSFound = 'The following %s orphaned .po file(s) found:';
sTroublesomeFiles = 'Troublesome files';
const const
mrOpenEditorFile = mrNone+100; mrOpenEditorFile = mrNone+100;

View File

@ -21,7 +21,7 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 201 Left = 201
Height = 118 Height = 118
Top = 29 Top = 27
Width = 436 Width = 436
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6 BorderSpacing.Top = 6
@ -34,7 +34,7 @@ object PoCheckerForm: TPoCheckerForm
'sCheckForDuplicateUntranslatedValues' 'sCheckForDuplicateUntranslatedValues'
'sCheckStatistics' 'sCheckStatistics'
) )
ItemHeight = 17 ItemHeight = 19
TabOrder = 3 TabOrder = 3
Data = { Data = {
06000000000000000000 06000000000000000000
@ -44,9 +44,9 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideLeft.Control = OpenBtn AnchorSideLeft.Control = OpenBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
Left = 201 Left = 201
Height = 15 Height = 13
Top = 8 Top = 8
Width = 93 Width = 82
BorderSpacing.Left = 9 BorderSpacing.Left = 9
Caption = 'Select test types' Caption = 'Select test types'
Font.Style = [fsBold] Font.Style = [fsBold]
@ -61,7 +61,7 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideBottom.Control = ScanDirBtn AnchorSideBottom.Control = ScanDirBtn
Left = 8 Left = 8
Height = 50 Height = 50
Top = 29 Top = 27
Width = 184 Width = 184
BorderSpacing.Bottom = 10 BorderSpacing.Bottom = 10
Caption = '&Open a po-file' Caption = '&Open a po-file'
@ -111,7 +111,7 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 8 Left = 8
Height = 50 Height = 50
Top = 149 Top = 147
Width = 184 Width = 184
BorderSpacing.Top = 5 BorderSpacing.Top = 5
Caption = '&Run Selected Tests' Caption = '&Run Selected Tests'
@ -122,9 +122,9 @@ object PoCheckerForm: TPoCheckerForm
end end
object NoErrLabel: TLabel object NoErrLabel: TLabel
Left = 8 Left = 8
Height = 25 Height = 23
Top = 451 Top = 453
Width = 146 Width = 145
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
Caption = 'No errors found' Caption = 'No errors found'
Font.Color = clGreen Font.Color = clGreen
@ -139,8 +139,8 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 201 Left = 201
Height = 25 Height = 25
Top = 153 Top = 151
Width = 117 Width = 99
AutoSize = True AutoSize = True
BorderSpacing.Top = 6 BorderSpacing.Top = 6
Caption = 'Select Basic Tests' Caption = 'Select Basic Tests'
@ -152,10 +152,10 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideLeft.Control = SelectBasicTestsBtn AnchorSideLeft.Control = SelectBasicTestsBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = SelectBasicTestsBtn AnchorSideTop.Control = SelectBasicTestsBtn
Left = 322 Left = 304
Height = 25 Height = 25
Top = 153 Top = 151
Width = 104 Width = 85
AutoSize = True AutoSize = True
BorderSpacing.Left = 4 BorderSpacing.Left = 4
Caption = 'Select All Tests' Caption = 'Select All Tests'
@ -167,10 +167,10 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideLeft.Control = SelectAllTestsBtn AnchorSideLeft.Control = SelectAllTestsBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = SelectAllTestsBtn AnchorSideTop.Control = SelectAllTestsBtn
Left = 430 Left = 393
Height = 25 Height = 25
Top = 153 Top = 151
Width = 118 Width = 97
AutoSize = True AutoSize = True
BorderSpacing.Left = 4 BorderSpacing.Left = 4
Caption = 'Unselect All Tests' Caption = 'Unselect All Tests'
@ -183,17 +183,17 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideTop.Control = SelectBasicTestsBtn AnchorSideTop.Control = SelectBasicTestsBtn
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 201 Left = 201
Height = 19 Height = 22
Top = 184 Top = 182
Width = 152 Width = 147
BorderSpacing.Top = 6 BorderSpacing.Top = 6
Caption = 'sIgnoreFuzzyTranslations' Caption = 'sIgnoreFuzzyTranslations'
TabOrder = 7 TabOrder = 7
end end
object StatusBar: TStatusBar object StatusBar: TStatusBar
Left = 0 Left = 0
Height = 23 Height = 17
Top = 490 Top = 496
Width = 644 Width = 644
Panels = <> Panels = <>
end end
@ -206,7 +206,7 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideBottom.Control = RunBtn AnchorSideBottom.Control = RunBtn
Left = 8 Left = 8
Height = 50 Height = 50
Top = 89 Top = 87
Width = 184 Width = 184
BorderSpacing.Top = 5 BorderSpacing.Top = 5
BorderSpacing.Bottom = 10 BorderSpacing.Bottom = 10
@ -257,8 +257,8 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = NoErrLabel AnchorSideBottom.Control = NoErrLabel
Left = 8 Left = 8
Height = 185 Height = 186
Top = 208 Top = 209
Width = 629 Width = 629
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 5 BorderSpacing.Top = 5
@ -268,9 +268,11 @@ object PoCheckerForm: TPoCheckerForm
OnDrawItem = MasterPoListBoxDrawItem OnDrawItem = MasterPoListBoxDrawItem
OnResize = MasterPoListBoxResize OnResize = MasterPoListBoxResize
OnSelectionChange = MasterPoListBoxSelectionChange OnSelectionChange = MasterPoListBoxSelectionChange
ScrollWidth = 627
Sorted = True Sorted = True
Style = lbOwnerDrawFixed Style = lbOwnerDrawFixed
TabOrder = 8 TabOrder = 8
TopIndex = -1
end end
object LangFilter: TComboBox object LangFilter: TComboBox
AnchorSideLeft.Control = MasterPoListBox AnchorSideLeft.Control = MasterPoListBox
@ -278,12 +280,12 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideRight.Control = TestListBox AnchorSideRight.Control = TestListBox
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 8 Left = 8
Height = 23 Height = 25
Top = 400 Top = 399
Width = 629 Width = 629
Anchors = [akLeft, akRight] Anchors = [akLeft, akRight]
BorderSpacing.Top = 5 BorderSpacing.Top = 5
ItemHeight = 15 ItemHeight = 0
ItemIndex = 0 ItemIndex = 0
Items.Strings = ( Items.Strings = (
'All languages' 'All languages'
@ -323,8 +325,8 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideBottom.Control = NoErrLabel AnchorSideBottom.Control = NoErrLabel
Left = 8 Left = 8
Height = 25 Height = 25
Top = 426 Top = 428
Width = 53 Width = 37
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Top = 10 BorderSpacing.Top = 10
@ -336,10 +338,10 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideLeft.Control = SelectAllMasterFilesBtn AnchorSideLeft.Control = SelectAllMasterFilesBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Control = NoErrLabel AnchorSideBottom.Control = NoErrLabel
Left = 167 Left = 136
Height = 25 Height = 25
Top = 426 Top = 428
Width = 110 Width = 93
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 5 BorderSpacing.Left = 5
@ -352,10 +354,10 @@ object PoCheckerForm: TPoCheckerForm
AnchorSideLeft.Control = ClearMasterFilesBtn AnchorSideLeft.Control = ClearMasterFilesBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Control = NoErrLabel AnchorSideBottom.Control = NoErrLabel
Left = 66 Left = 50
Height = 25 Height = 25
Top = 426 Top = 428
Width = 96 Width = 81
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 5 BorderSpacing.Left = 5
@ -363,15 +365,26 @@ object PoCheckerForm: TPoCheckerForm
OnClick = SelectAllMasterFilesBtnClick OnClick = SelectAllMasterFilesBtnClick
TabOrder = 11 TabOrder = 11
end end
object FindTroublesomeFilesBtn: TButton
Left = 514
Height = 25
Top = 428
Width = 121
Anchors = [akRight, akBottom]
AutoSize = True
Caption = 'Find troublesome files'
OnClick = FindTroublesomeFilesBtnClick
TabOrder = 14
end
object OpenDialog: TOpenDialog object OpenDialog: TOpenDialog
Filter = 'po-files (*.po)|*.po|all files|*' Filter = 'po-files (*.po)|*.po|all files|*'
Options = [ofFileMustExist, ofEnableSizing, ofViewDetail] Options = [ofFileMustExist, ofEnableSizing, ofViewDetail]
left = 480 left = 245
top = 432 top = 435
end end
object SelectDirectoryDialog: TSelectDirectoryDialog object SelectDirectoryDialog: TSelectDirectoryDialog
Options = [ofEnableSizing] Options = [ofEnableSizing]
left = 584 left = 355
top = 432 top = 435
end end
end end

View File

@ -38,6 +38,7 @@ type
{ TPoCheckerForm } { TPoCheckerForm }
TPoCheckerForm = class(TForm) TPoCheckerForm = class(TForm)
FindTroublesomeFilesBtn: TButton;
SelectAllMasterFilesBtn: TButton; SelectAllMasterFilesBtn: TButton;
SelectDirectoryDialog: TSelectDirectoryDialog; SelectDirectoryDialog: TSelectDirectoryDialog;
UnselectAllMasterFilesBtn: TButton; UnselectAllMasterFilesBtn: TButton;
@ -53,6 +54,7 @@ type
procedure MasterPoListBoxDrawItem(Control: TWinControl; Index: Integer; procedure MasterPoListBoxDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState); ARect: TRect; State: TOwnerDrawState);
procedure MasterPoListBoxSelectionChange(Sender: TObject; User: boolean); procedure MasterPoListBoxSelectionChange(Sender: TObject; User: boolean);
procedure FindTroublesomeFilesBtnClick(Sender: TObject);
procedure ScanDirBtnClick(Sender: TObject); procedure ScanDirBtnClick(Sender: TObject);
procedure SelectAllMasterFilesBtnClick(Sender: TObject); procedure SelectAllMasterFilesBtnClick(Sender: TObject);
procedure UnselectAllMasterFilesBtnClick(Sender: TObject); procedure UnselectAllMasterFilesBtnClick(Sender: TObject);
@ -299,6 +301,63 @@ begin
SelectAllMasterFilesBtn.Enabled := (MasterPoListBox.Items.Count > 0); SelectAllMasterFilesBtn.Enabled := (MasterPoListBox.Items.Count > 0);
end; end;
procedure TPoCheckerForm.FindTroublesomeFilesBtnClick(Sender: TObject);
var
SL,FL,OL:TStringList;
S, Mn: String;
I: Integer;
Cur: TCursor;
begin
Cur := Screen.Cursor;
Screen.Cursor := crHourGlass;
try
StatusBar.SimpleText := sScanningInProgress;
FL := TStringList.Create;
OL := TStringList.Create;
SL := FindAllFiles(SelectDirectoryDialog.FileName, '*.po',True);
for I := 0 to SL.Count - 1 do // we must check master .po files in a separate round first
begin
S := SL[I];
if IsMasterPOName(S) and (MasterPoListBox.Items.IndexOf(S) = -1)
then
begin
AddToMasterPoList(S);
FL.Add(S);
end;
end;
for I := 0 to SL.Count - 1 do
begin
S := SL[I];
if not IsMasterPOName(S)
then
begin
Mn:=ExtractMasterNameFromChildName(S);
if (Mn <> '') and (MasterPoListBox.Items.IndexOf(Mn) = -1)
then
OL.Add(S);
end;
end;
if(OL.Count = 0) and (FL.Count = 0)
then
S := sNoTroublesomePoFilesFound
else
begin
S:='';
if (FL.Count > 0) then S := Format(sTheFollowingMasterPoFileSAddedToTheList, [IntToStr(FL.Count)]) + LineEnding + FL.Text;
if S <> '' then S := S + LineEnding + LineEnding;
if (OL.Count > 0) then S := S + Format(sTheFollowingOrphanedPoFileSFound, [IntToStr(OL.Count)]) + LineEnding + OL.Text;
end;
MemoDlg(sTroublesomeFiles, S);
UpdateGUI(MasterPoListBox.SelCount > 0);
finally
StatusBar.SimpleText := '';
FL.Free;
OL.Free;
SL.Free;
end;
Screen.Cursor := Cur;
end;
procedure TPoCheckerForm.ScanDirBtnClick(Sender: TObject); procedure TPoCheckerForm.ScanDirBtnClick(Sender: TObject);
begin begin
if SelectDirectoryDialog.Execute then if SelectDirectoryDialog.Execute then
@ -604,6 +663,7 @@ begin
end; end;
ClearMasterFilesBtn.Enabled := (MasterPoListBox.Items.Count > 0); ClearMasterFilesBtn.Enabled := (MasterPoListBox.Items.Count > 0);
SelectAllMasterFilesBtn.Enabled := (MasterPoListBox.Items.Count > 0); SelectAllMasterFilesBtn.Enabled := (MasterPoListBox.Items.Count > 0);
FindTroublesomeFilesBtn.Enabled := (SelectDirectoryDialog.FileName <> '');
end; end;
function TPoCheckerForm.GetSelectedMasterFiles: TStringList; function TPoCheckerForm.GetSelectedMasterFiles: TStringList;
@ -928,6 +988,7 @@ begin
SelectAllTestsBtn.Caption := sSelectAllTests; SelectAllTestsBtn.Caption := sSelectAllTests;
SelectBasicTestsBtn.Caption := sSelectBasicTests; SelectBasicTestsBtn.Caption := sSelectBasicTests;
UnselectAllTestsBtn.Caption := sUnselectAllTests; UnselectAllTestsBtn.Caption := sUnselectAllTests;
FindTroublesomeFilesBtn.Caption:= sFindTroublesomeFiles;
end; end;