PoChecker: add option to check translation statistics.

git-svn-id: trunk@43451 -
This commit is contained in:
bart 2013-11-17 16:57:47 +00:00
parent 5ab9829c76
commit 19e8936d8e
4 changed files with 68 additions and 4 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
@ -61,7 +61,7 @@
<Unit3>
<Filename Value="..\simplepofiles.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="simplepofiles"/>
<UnitName Value="SimplePoFiles"/>
</Unit3>
<Unit4>
<Filename Value="..\pocheckerconsts.pas"/>

View File

@ -34,6 +34,7 @@ resourcestring
sOriginal = 'Original';
sTranslation = 'Translation';
sErrorsByTest = 'Errors / warnings reported by %s for:';
sTranslationStatistics = 'Translation statistics for:';
sCheckNumberOfItems = 'Check number of items';
sCheckForIncompatibleFormatArguments = 'Check for incompatible format '
+'arguments';
@ -42,6 +43,7 @@ resourcestring
+'untranslated strings';
sCheckForDuplicateUntranslatedValues = 'Check for duplicate untranslated '
+'values';
sCheckStatistics = 'Check percentage of (un)translated and fuzzy strings';
sFindAllTranslatedPoFiles = 'Find all translated po-files';
sIncompatibleFormatArgs = '[Line: %d] Incompatible and/or invalid format() arguments for:' ;
@ -56,7 +58,11 @@ resourcestring
sNrOfItemsMismatchD = '%s: %d items';
sDuplicateOriginals = 'The (untranslated) value "%s" is used for more than 1 entry:';
sDuplicateLineNrWithValue = '[Line %d] %s';
sPercTranslated = 'Translated strings: %2.0f%%.';
sPercUntranslated = 'Untranslated strings: %2.0f%%.';
sPercFuzzy = 'Fuzzy strings: %2.0f%%.';
implementation
end.

View File

@ -156,7 +156,7 @@ var
begin
cb := Sender as TCheckBox;
// Set / reset "basic" CheckListBox items.
for i := 0 to TestListBox.Count - 2 do
for i := 0 to TestListBox.Count - 3 do
TestListBox.Checked[i] := cb.Checked;
end;
@ -187,6 +187,7 @@ begin
ptoCheckMissingIdentifiers: TestListBox.Items.Add(sCheckMissingIdentifiers);
ptoCheckMismatchedOriginals: TestListBox.Items.Add(sCheckForMismatchesInUntranslatedStrings);
ptoCheckDuplicateOriginals: TestListBox.Items.Add(sCheckForDuplicateUntranslatedValues);
ptoCheckStatistics: TestListBox.Items.Add(sCheckStatistics);
else
TestListBox.Items.Add(PoTestOptionNames[Opt]);
end;

View File

@ -14,7 +14,7 @@ uses
Type
TPoTestOption = (ptoCheckNrOfItems, ptoCheckFormatArgs, ptoCheckMissingIdentifiers,
ptoCheckMismatchedOriginals, ptoCheckDuplicateOriginals,
ptoCheckMismatchedOriginals, ptoCheckDuplicateOriginals, ptoCheckStatistics,
ptoFindAllChilds);
TPoTestOptions = Set of TPoTestOption;
@ -28,6 +28,7 @@ const
'Check missing identifiers',
'Check for mismatches in untranslated strings',
'Check for duplicate untranslated values',
'Check percentage of (un)translated and fuzzy strings',
'Find all translated po-files'
);
@ -64,6 +65,7 @@ Type
procedure CheckMissingIdentifiers(out ErrorCount: Integer; ErrorLog: TStrings);
procedure CheckMismatchedOriginals(out ErrorCount: Integer; ErrorLog: TStrings);
procedure CheckDuplicateOriginals(out WarningCount: Integer; ErrorLog: TStrings);
procedure CheckStatistics(out WarningCount: Integer; ErrorLog: TStrings);
public
procedure RunTests(const Options: TPoTestOptions; out ErrorCount, WarningCount: Integer; ErrorLog: TStrings);
@ -563,6 +565,56 @@ begin
//debugln('TPoFamily.CheckDuplicateOriginals: ',Dbgs(WarningCount),' Errors');
end;
procedure TPoFamily.CheckStatistics(out WarningCount: Integer; ErrorLog: TStrings);
var
i: Integer;
CPoItem: TPOFileItem;
NrTranslated, NrUntranslated, NrFuzzy, NrTotal: Integer;
begin
//debugln('TPoFamily.CheckFormatArgs');
DoTestStart(sCheckStatistics, ShortChildName);
NrTranslated := 0;
NrUntranslated := 0;
NrFuzzy := 0;
//for i := 0 to FMaster.Count - 1 do
for i := 0 to FChild.Count - 1 do
begin
//debugln(' i = ',DbgS(i));
//MPoItem := FMaster.PoItems[i];
CPoItem := FChild.PoItems[i];
//CPoItem := FChild.FindPoItem(MPoItem.Identifier);
if Assigned(CPoItem) then
begin
if (Length(CPoItem.Translation) > 0) then
begin
if (Pos('fuzzy', CPoItem.Flags) <> 0) then
Inc(NrFuzzy)
else
Inc(NrTranslated);
end
else
begin
Inc(NrUntranslated)
end;
end;
end;
NrTotal := NrTranslated + NrUntranslated + NrFuzzy;
if (NrTotal > 0) then
begin
WarningCount := 1; //else it will not show up...
ErrorLog.Add(Divider);
ErrorLog.Add(sTranslationStatistics);
ErrorLog.Add(ShortChildName);
ErrorLog.Add(Format(sPercTranslated,[100.0*(NrTranslated/NrTotal)]));
ErrorLog.Add(Format(sPercUntranslated,[100.0*(NrUntranslated/NrTotal)]));
ErrorLog.Add(Format(sPercFuzzy,[100.0*(NrFuzzy/NrTotal)]));
ErrorLog.Add('');
ErrorLog.Add('');
end;
DoTestEnd(PoTestOptionNames[ptoCheckFormatArgs], WarningCount);
//debugln('TPoFamily.CheckIncompatibleFormatArgs: ',Dbgs(ErrorCount),' Errors');
end;
{
procedure TPoFamily.RunTests(const Options: TPoTestOptions; out
Pre conditions:
@ -691,6 +743,11 @@ begin
ErrorCount := CurrErrCnt + ErrorCount;
end;
if (ptoCheckStatistics in Options) then
begin
CheckStatistics(CurrErrCnt, ErrorLog);
ErrorCount := CurrErrCnt + ErrorCount;
end;
{
if (pto in Options) then
begin