mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 13:56:05 +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 = class
|
||||
private
|
||||
FInitialFuzzyState: boolean;
|
||||
public
|
||||
Tag: Integer;
|
||||
LineNr: Integer; // required by pochecker
|
||||
@ -101,13 +103,13 @@ type
|
||||
// Can accept the comma separated list of flags
|
||||
// Returns true if the Flags property has been modified
|
||||
function ModifyFlag(const AFlags: string; Check: boolean): boolean;
|
||||
property InitialFuzzyState: boolean read FInitialFuzzyState;
|
||||
end;
|
||||
|
||||
{ TPOFile }
|
||||
|
||||
TPOFile = class
|
||||
private
|
||||
FAllowChangeFuzzyFlag: boolean;
|
||||
FStatisticsUpdated: boolean;
|
||||
FStatistics: TTranslationStatistics;
|
||||
function GetStatistics: TTranslationStatistics;
|
||||
@ -131,8 +133,8 @@ type
|
||||
procedure ReadPOText(AStream: TStream);
|
||||
public
|
||||
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(AStream: TStream; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true);
|
||||
constructor Create(const AFilename: String; Full: boolean=false);
|
||||
constructor Create(AStream: TStream; Full: boolean=false);
|
||||
destructor Destroy; override;
|
||||
procedure ReadPOText(const Txt: string);
|
||||
function Translate(const Identifier, OriginalValue: String): String;
|
||||
@ -718,21 +720,19 @@ constructor TPOFile.Create(Full:Boolean=True);
|
||||
begin
|
||||
inherited Create;
|
||||
FAllEntries:=Full;
|
||||
// changing 'fuzzy' flag is allowed by default
|
||||
FAllowChangeFuzzyFlag:=true;
|
||||
FItems:=TFPList.Create;
|
||||
FIdentifierLowToItem:=TStringToPointerTree.Create(true);
|
||||
FOriginalToItem:=TStringHashList.Create(true);
|
||||
end;
|
||||
|
||||
constructor TPOFile.Create(const AFilename: String; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true);
|
||||
constructor TPOFile.Create(const AFilename: String; Full: boolean=false);
|
||||
var
|
||||
f: TStream;
|
||||
begin
|
||||
FPoName := AFilename;
|
||||
f := TFileStreamUTF8.Create(AFilename, fmOpenRead or fmShareDenyNone);
|
||||
try
|
||||
Create(f, Full, AllowChangeFuzzyFlag);
|
||||
Create(f, Full);
|
||||
if FHeader=nil then
|
||||
CreateHeader;
|
||||
finally
|
||||
@ -740,14 +740,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TPOFile.Create(AStream: TStream; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true);
|
||||
constructor TPOFile.Create(AStream: TStream; Full: boolean=false);
|
||||
begin
|
||||
Create;
|
||||
|
||||
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);
|
||||
|
||||
@ -1534,7 +1531,7 @@ begin
|
||||
end;
|
||||
|
||||
//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
|
||||
begin
|
||||
Item.PreviousID := '';
|
||||
@ -1563,11 +1560,8 @@ procedure TPOFile.FillItem(var CurrentItem: TPOFileItem; Identifier, Original,
|
||||
begin
|
||||
if pos(sFuzzyFlag, Item.Flags) = 0 then
|
||||
begin
|
||||
if FAllowChangeFuzzyFlag = true then
|
||||
begin
|
||||
Item.ModifyFlag(sFuzzyFlag, true);
|
||||
FModified := true;
|
||||
end;
|
||||
Item.ModifyFlag(sFuzzyFlag, true);
|
||||
FModified := true;
|
||||
end;
|
||||
end;
|
||||
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.
|
||||
TmpFlags := StringReplace(Flags, '"', '', [rfReplaceAll]);
|
||||
CurrentItem.ModifyFlag(lowercase(TmpFlags), true);
|
||||
CurrentItem.FInitialFuzzyState := pos(sFuzzyFlag, CurrentItem.Flags) <> 0;
|
||||
CurrentItem.PreviousID := PreviousID;
|
||||
CurrentItem.LineNr := LineNr;
|
||||
FItems.Add(CurrentItem);
|
||||
@ -1717,6 +1712,7 @@ end;
|
||||
constructor TPOFileItem.Create(const TheIdentifierLow, TheOriginal,
|
||||
TheTranslated: string);
|
||||
begin
|
||||
FInitialFuzzyState:=false;
|
||||
Duplicate:=false;
|
||||
IdentifierLow:=TheIdentifierLow;
|
||||
Original:=TheOriginal;
|
||||
|
@ -323,7 +323,7 @@ begin
|
||||
FMaster.Free;
|
||||
FMaster := nil;
|
||||
FMasterName := '';
|
||||
if (AValue <> '') then FMaster := TPOFile.Create(AValue, True, False);
|
||||
if (AValue <> '') then FMaster := TPOFile.Create(AValue, True);
|
||||
FMasterName := AValue;
|
||||
end;
|
||||
|
||||
@ -354,7 +354,7 @@ begin
|
||||
FChild.Free;
|
||||
FChild := nil;
|
||||
FChildName := '';
|
||||
if (AValue <> '') then FChild := TPOFile.Create(AValue, True, False);
|
||||
if (AValue <> '') then FChild := TPOFile.Create(AValue, True);
|
||||
FChildName := AValue;
|
||||
end;
|
||||
|
||||
@ -362,13 +362,13 @@ constructor TPoFamily.Create(const AMasterName, AChildName: String);
|
||||
begin
|
||||
if (AMasterName <> '') then
|
||||
begin
|
||||
FMaster := TPOFile.Create(AMasterName, True, False);
|
||||
FMaster := TPOFile.Create(AMasterName, True);
|
||||
FMasterName := AMasterName;
|
||||
//debugln('TPoFamily.Create: created ',FMasterName);
|
||||
end;
|
||||
if (AChildName <> '') then
|
||||
begin
|
||||
FChild := TPOFile.Create(AChildName, True, False);
|
||||
FChild := TPOFile.Create(AChildName, True);
|
||||
FChildName := AChildName;
|
||||
//debugln('TPoFamily.Create: created ',FChildName);
|
||||
end;
|
||||
@ -412,7 +412,6 @@ procedure TPoFamily.CheckFormatArgs(out ErrorCount, NonFuzzyErrorCount: Integer
|
||||
var
|
||||
i: Integer;
|
||||
CPoItem: TPOFileItem;
|
||||
IsFuzzy: Boolean;
|
||||
IsBadFormat: Boolean;
|
||||
begin
|
||||
//debugln('TPoFamily.CheckFormatArgs');
|
||||
@ -421,15 +420,10 @@ begin
|
||||
NonFuzzyErrorCount := NoError;
|
||||
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.IdentifierLow);
|
||||
if Assigned(CPoItem) then
|
||||
begin
|
||||
IsFuzzy := (Pos(sFuzzyFlag, 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
|
||||
begin
|
||||
if (ErrorCount = 0) then
|
||||
@ -441,13 +435,14 @@ begin
|
||||
ErrorLog.Add('');
|
||||
end;
|
||||
Inc(ErrorCount);
|
||||
if not IsFuzzy then
|
||||
if CPoItem.InitialFuzzyState = false then
|
||||
Inc(NonFuzzyErrorCount);
|
||||
ErrorLog.Add(Format(sIncompatibleFormatArgs,[CPoItem.LineNr]));
|
||||
ErrorLog.Add(Format(sFormatArgsID,[sCommentIdentifier, CPoItem.IdentifierLow]));
|
||||
ErrorLog.Add(Format(sFormatArgsValues,[sMsgID,CPoItem.Original,sOriginal]));
|
||||
ErrorLog.Add(Format(sFormatArgsValues,[sMsgStr,CPoItem.Translation,sTranslation]));
|
||||
if IsFuzzy then ErrorLog.Add(sNoteTranslationIsFuzzy);
|
||||
if CPoItem.InitialFuzzyState = true then
|
||||
ErrorLog.Add(sNoteTranslationIsFuzzy);
|
||||
ErrorLog.Add('');
|
||||
end;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user