mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 15:40:40 +02:00
LazUtils (Translations unit), POChecker: Store item's fuzzy flag state as read from file in a separate property. Use it where appropriate. This allows to simplify TPOFile constructors and makes code more clear.
git-svn-id: trunk@61299 -
This commit is contained in:
parent
e80efec72a
commit
b04174617e
@ -86,6 +86,8 @@ type
|
|||||||
{ TPOFileItem }
|
{ TPOFileItem }
|
||||||
|
|
||||||
TPOFileItem = class
|
TPOFileItem = class
|
||||||
|
private
|
||||||
|
FInitialFuzzyState: boolean;
|
||||||
public
|
public
|
||||||
Tag: Integer;
|
Tag: Integer;
|
||||||
LineNr: Integer; // required by pochecker
|
LineNr: Integer; // required by pochecker
|
||||||
@ -101,13 +103,13 @@ type
|
|||||||
// Can accept the comma separated list of flags
|
// Can accept the comma separated list of flags
|
||||||
// Returns true if the Flags property has been modified
|
// Returns true if the Flags property has been modified
|
||||||
function ModifyFlag(const AFlags: string; Check: boolean): boolean;
|
function ModifyFlag(const AFlags: string; Check: boolean): boolean;
|
||||||
|
property InitialFuzzyState: boolean read FInitialFuzzyState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TPOFile }
|
{ TPOFile }
|
||||||
|
|
||||||
TPOFile = class
|
TPOFile = class
|
||||||
private
|
private
|
||||||
FAllowChangeFuzzyFlag: boolean;
|
|
||||||
FStatisticsUpdated: boolean;
|
FStatisticsUpdated: boolean;
|
||||||
FStatistics: TTranslationStatistics;
|
FStatistics: TTranslationStatistics;
|
||||||
function GetStatistics: TTranslationStatistics;
|
function GetStatistics: TTranslationStatistics;
|
||||||
@ -131,8 +133,8 @@ type
|
|||||||
procedure ReadPOText(AStream: TStream);
|
procedure ReadPOText(AStream: TStream);
|
||||||
public
|
public
|
||||||
constructor Create(Full:Boolean=True); //when loading from internal resource Full needs to be False
|
constructor Create(Full:Boolean=True); //when loading from internal resource Full needs to be False
|
||||||
constructor Create(const AFilename: String; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true);
|
constructor Create(const AFilename: String; Full: boolean=false);
|
||||||
constructor Create(AStream: TStream; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true);
|
constructor Create(AStream: TStream; Full: boolean=false);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure ReadPOText(const Txt: string);
|
procedure ReadPOText(const Txt: string);
|
||||||
function Translate(const Identifier, OriginalValue: String): String;
|
function Translate(const Identifier, OriginalValue: String): String;
|
||||||
@ -718,21 +720,19 @@ constructor TPOFile.Create(Full:Boolean=True);
|
|||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FAllEntries:=Full;
|
FAllEntries:=Full;
|
||||||
// changing 'fuzzy' flag is allowed by default
|
|
||||||
FAllowChangeFuzzyFlag:=true;
|
|
||||||
FItems:=TFPList.Create;
|
FItems:=TFPList.Create;
|
||||||
FIdentifierLowToItem:=TStringToPointerTree.Create(true);
|
FIdentifierLowToItem:=TStringToPointerTree.Create(true);
|
||||||
FOriginalToItem:=TStringHashList.Create(true);
|
FOriginalToItem:=TStringHashList.Create(true);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TPOFile.Create(const AFilename: String; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true);
|
constructor TPOFile.Create(const AFilename: String; Full: boolean=false);
|
||||||
var
|
var
|
||||||
f: TStream;
|
f: TStream;
|
||||||
begin
|
begin
|
||||||
FPoName := AFilename;
|
FPoName := AFilename;
|
||||||
f := TFileStreamUTF8.Create(AFilename, fmOpenRead or fmShareDenyNone);
|
f := TFileStreamUTF8.Create(AFilename, fmOpenRead or fmShareDenyNone);
|
||||||
try
|
try
|
||||||
Create(f, Full, AllowChangeFuzzyFlag);
|
Create(f, Full);
|
||||||
if FHeader=nil then
|
if FHeader=nil then
|
||||||
CreateHeader;
|
CreateHeader;
|
||||||
finally
|
finally
|
||||||
@ -740,14 +740,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TPOFile.Create(AStream: TStream; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true);
|
constructor TPOFile.Create(AStream: TStream; Full: boolean=false);
|
||||||
begin
|
begin
|
||||||
Create;
|
Create;
|
||||||
|
|
||||||
FAllEntries := Full;
|
FAllEntries := Full;
|
||||||
//AllowChangeFuzzyFlag allows not to change fuzzy flag for items with bad format arguments,
|
|
||||||
//so there can be arguments with only badformat flag set. This is needed for POChecker.
|
|
||||||
FAllowChangeFuzzyFlag := AllowChangeFuzzyFlag;
|
|
||||||
|
|
||||||
ReadPOText(AStream);
|
ReadPOText(AStream);
|
||||||
|
|
||||||
@ -1534,7 +1531,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
//cleanup unneeded PreviousIDs in all files (base and translations)
|
//cleanup unneeded PreviousIDs in all files (base and translations)
|
||||||
if (Item.Translation = '') or (pos(sFuzzyFlag, Item.Flags) = 0) then
|
if (Item.Translation = '') or (Item.InitialFuzzyState = false) then
|
||||||
if Item.PreviousID <> '' then
|
if Item.PreviousID <> '' then
|
||||||
begin
|
begin
|
||||||
Item.PreviousID := '';
|
Item.PreviousID := '';
|
||||||
@ -1563,11 +1560,8 @@ procedure TPOFile.FillItem(var CurrentItem: TPOFileItem; Identifier, Original,
|
|||||||
begin
|
begin
|
||||||
if pos(sFuzzyFlag, Item.Flags) = 0 then
|
if pos(sFuzzyFlag, Item.Flags) = 0 then
|
||||||
begin
|
begin
|
||||||
if FAllowChangeFuzzyFlag = true then
|
Item.ModifyFlag(sFuzzyFlag, true);
|
||||||
begin
|
FModified := true;
|
||||||
Item.ModifyFlag(sFuzzyFlag, true);
|
|
||||||
FModified := true;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
HasBadFormatFlag := pos(sBadFormatFlag, Item.Flags) <> 0;
|
HasBadFormatFlag := pos(sBadFormatFlag, Item.Flags) <> 0;
|
||||||
@ -1622,6 +1616,7 @@ begin
|
|||||||
//These characters are not meant to be present in flags anyway according to examples in gettext documentation.
|
//These characters are not meant to be present in flags anyway according to examples in gettext documentation.
|
||||||
TmpFlags := StringReplace(Flags, '"', '', [rfReplaceAll]);
|
TmpFlags := StringReplace(Flags, '"', '', [rfReplaceAll]);
|
||||||
CurrentItem.ModifyFlag(lowercase(TmpFlags), true);
|
CurrentItem.ModifyFlag(lowercase(TmpFlags), true);
|
||||||
|
CurrentItem.FInitialFuzzyState := pos(sFuzzyFlag, CurrentItem.Flags) <> 0;
|
||||||
CurrentItem.PreviousID := PreviousID;
|
CurrentItem.PreviousID := PreviousID;
|
||||||
CurrentItem.LineNr := LineNr;
|
CurrentItem.LineNr := LineNr;
|
||||||
FItems.Add(CurrentItem);
|
FItems.Add(CurrentItem);
|
||||||
@ -1717,6 +1712,7 @@ end;
|
|||||||
constructor TPOFileItem.Create(const TheIdentifierLow, TheOriginal,
|
constructor TPOFileItem.Create(const TheIdentifierLow, TheOriginal,
|
||||||
TheTranslated: string);
|
TheTranslated: string);
|
||||||
begin
|
begin
|
||||||
|
FInitialFuzzyState:=false;
|
||||||
Duplicate:=false;
|
Duplicate:=false;
|
||||||
IdentifierLow:=TheIdentifierLow;
|
IdentifierLow:=TheIdentifierLow;
|
||||||
Original:=TheOriginal;
|
Original:=TheOriginal;
|
||||||
|
@ -323,7 +323,7 @@ begin
|
|||||||
FMaster.Free;
|
FMaster.Free;
|
||||||
FMaster := nil;
|
FMaster := nil;
|
||||||
FMasterName := '';
|
FMasterName := '';
|
||||||
if (AValue <> '') then FMaster := TPOFile.Create(AValue, True, False);
|
if (AValue <> '') then FMaster := TPOFile.Create(AValue, True);
|
||||||
FMasterName := AValue;
|
FMasterName := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -354,7 +354,7 @@ begin
|
|||||||
FChild.Free;
|
FChild.Free;
|
||||||
FChild := nil;
|
FChild := nil;
|
||||||
FChildName := '';
|
FChildName := '';
|
||||||
if (AValue <> '') then FChild := TPOFile.Create(AValue, True, False);
|
if (AValue <> '') then FChild := TPOFile.Create(AValue, True);
|
||||||
FChildName := AValue;
|
FChildName := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -362,13 +362,13 @@ constructor TPoFamily.Create(const AMasterName, AChildName: String);
|
|||||||
begin
|
begin
|
||||||
if (AMasterName <> '') then
|
if (AMasterName <> '') then
|
||||||
begin
|
begin
|
||||||
FMaster := TPOFile.Create(AMasterName, True, False);
|
FMaster := TPOFile.Create(AMasterName, True);
|
||||||
FMasterName := AMasterName;
|
FMasterName := AMasterName;
|
||||||
//debugln('TPoFamily.Create: created ',FMasterName);
|
//debugln('TPoFamily.Create: created ',FMasterName);
|
||||||
end;
|
end;
|
||||||
if (AChildName <> '') then
|
if (AChildName <> '') then
|
||||||
begin
|
begin
|
||||||
FChild := TPOFile.Create(AChildName, True, False);
|
FChild := TPOFile.Create(AChildName, True);
|
||||||
FChildName := AChildName;
|
FChildName := AChildName;
|
||||||
//debugln('TPoFamily.Create: created ',FChildName);
|
//debugln('TPoFamily.Create: created ',FChildName);
|
||||||
end;
|
end;
|
||||||
@ -412,7 +412,6 @@ procedure TPoFamily.CheckFormatArgs(out ErrorCount, NonFuzzyErrorCount: Integer
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
CPoItem: TPOFileItem;
|
CPoItem: TPOFileItem;
|
||||||
IsFuzzy: Boolean;
|
|
||||||
IsBadFormat: Boolean;
|
IsBadFormat: Boolean;
|
||||||
begin
|
begin
|
||||||
//debugln('TPoFamily.CheckFormatArgs');
|
//debugln('TPoFamily.CheckFormatArgs');
|
||||||
@ -421,15 +420,10 @@ begin
|
|||||||
NonFuzzyErrorCount := NoError;
|
NonFuzzyErrorCount := NoError;
|
||||||
for i := 0 to FChild.Count - 1 do
|
for i := 0 to FChild.Count - 1 do
|
||||||
begin
|
begin
|
||||||
//debugln(' i = ',DbgS(i));
|
|
||||||
//MPoItem := FMaster.PoItems[i];
|
|
||||||
CPoItem := FChild.PoItems[i];
|
CPoItem := FChild.PoItems[i];
|
||||||
//CPoItem := FChild.FindPoItem(MPoItem.IdentifierLow);
|
|
||||||
if Assigned(CPoItem) then
|
if Assigned(CPoItem) then
|
||||||
begin
|
begin
|
||||||
IsFuzzy := (Pos(sFuzzyFlag, CPoItem.Flags) > 0);
|
|
||||||
IsBadFormat := (Pos(sBadFormatFlag, CPoItem.Flags) > 0);
|
IsBadFormat := (Pos(sBadFormatFlag, CPoItem.Flags) > 0);
|
||||||
//if (IgnoreFuzzyStrings and IsFuzzy) then debugln('Skipping fuzzy translation: ',CPoItem.Translation);
|
|
||||||
if (Length(CPoItem.Translation) > 0) and IsBadFormat then
|
if (Length(CPoItem.Translation) > 0) and IsBadFormat then
|
||||||
begin
|
begin
|
||||||
if (ErrorCount = 0) then
|
if (ErrorCount = 0) then
|
||||||
@ -441,13 +435,14 @@ begin
|
|||||||
ErrorLog.Add('');
|
ErrorLog.Add('');
|
||||||
end;
|
end;
|
||||||
Inc(ErrorCount);
|
Inc(ErrorCount);
|
||||||
if not IsFuzzy then
|
if CPoItem.InitialFuzzyState = false then
|
||||||
Inc(NonFuzzyErrorCount);
|
Inc(NonFuzzyErrorCount);
|
||||||
ErrorLog.Add(Format(sIncompatibleFormatArgs,[CPoItem.LineNr]));
|
ErrorLog.Add(Format(sIncompatibleFormatArgs,[CPoItem.LineNr]));
|
||||||
ErrorLog.Add(Format(sFormatArgsID,[sCommentIdentifier, CPoItem.IdentifierLow]));
|
ErrorLog.Add(Format(sFormatArgsID,[sCommentIdentifier, CPoItem.IdentifierLow]));
|
||||||
ErrorLog.Add(Format(sFormatArgsValues,[sMsgID,CPoItem.Original,sOriginal]));
|
ErrorLog.Add(Format(sFormatArgsValues,[sMsgID,CPoItem.Original,sOriginal]));
|
||||||
ErrorLog.Add(Format(sFormatArgsValues,[sMsgStr,CPoItem.Translation,sTranslation]));
|
ErrorLog.Add(Format(sFormatArgsValues,[sMsgStr,CPoItem.Translation,sTranslation]));
|
||||||
if IsFuzzy then ErrorLog.Add(sNoteTranslationIsFuzzy);
|
if CPoItem.InitialFuzzyState = true then
|
||||||
|
ErrorLog.Add(sNoteTranslationIsFuzzy);
|
||||||
ErrorLog.Add('');
|
ErrorLog.Add('');
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user