diff --git a/components/pochecker/pofamilies.pp b/components/pochecker/pofamilies.pp index a73e877ccd..c783af4cad 100644 --- a/components/pochecker/pofamilies.pp +++ b/components/pochecker/pofamilies.pp @@ -448,7 +448,7 @@ begin FMaster.Free; FMaster := nil; FMasterName := ''; - if (AValue <> '') then FMaster := TPOFile.Create(AValue, True); + if (AValue <> '') then FMaster := TPOFile.Create(AValue, True, False); FMasterName := AValue; end; @@ -479,7 +479,7 @@ begin FChild.Free; FChild := nil; FChildName := ''; - if (AValue <> '') then FChild := TPOFile.Create(AValue, True); + if (AValue <> '') then FChild := TPOFile.Create(AValue, True, False); FChildName := AValue; end; @@ -497,13 +497,13 @@ constructor TPoFamily.Create(const AMasterName, AChildName: String); begin if (AMasterName <> '') then begin - FMaster := TPOFile.Create(AMasterName, True); + FMaster := TPOFile.Create(AMasterName, True, False); FMasterName := AMasterName; //debugln('TPoFamily.Create: created ',FMasterName); end; if (AChildName <> '') then begin - FChild := TPOFile.Create(AChildName, True); + FChild := TPOFile.Create(AChildName, True, False); FChildName := AChildName; //debugln('TPoFamily.Create: created ',FChildName); end; diff --git a/lcl/translations.pas b/lcl/translations.pas index a953e7c63e..1bf8ca59e3 100644 --- a/lcl/translations.pas +++ b/lcl/translations.pas @@ -148,8 +148,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); - constructor Create(AStream: TStream; Full:boolean=false); + constructor Create(const AFilename: String; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true); + constructor Create(AStream: TStream; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true); destructor Destroy; override; procedure ReadPOText(const Txt: string); procedure Add(const Identifier, OriginalValue, TranslatedValue, Comments, @@ -174,9 +174,8 @@ type property Items: TFPList read FItems; // used by pochecker /pohelper public - procedure CheckFormatArguments; - procedure CleanUp; { removes previous ID from non-fuzzy entries - and badformat flags if appropriate } + procedure CheckFormatArguments(AllowChangeFuzzyFlag: boolean=true); + procedure CleanUp; // removes previous ID from non-fuzzy entries property PoName: String read FPoName; property PoRename: String write FPoName; property NrTranslated: Integer read FNrTranslated; @@ -701,14 +700,14 @@ begin FOriginalToItem:=TStringHashList.Create(true); end; -constructor TPOFile.Create(const AFilename: String; Full:boolean=False); +constructor TPOFile.Create(const AFilename: String; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true); var f: TStream; begin FPoName := AFilename; f := TFileStreamUTF8.Create(AFilename, fmOpenRead or fmShareDenyNone); try - Create(f, Full); + Create(f, Full, AllowChangeFuzzyFlag); if FHeader=nil then CreateHeader; finally @@ -716,7 +715,7 @@ begin end; end; -constructor TPOFile.Create(AStream: TStream; Full:boolean=false); +constructor TPOFile.Create(AStream: TStream; Full: boolean=false; AllowChangeFuzzyFlag: boolean=true); begin Create; @@ -725,8 +724,11 @@ begin ReadPOText(AStream); {$IFDEF CHECK_FORMAT} - CheckFormatArguments; // Verify that translation will not generate crashes - CleanUp; // Remove leftover badformat flags and keep only real ones + //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. + CheckFormatArguments(AllowChangeFuzzyFlag); // Verify that translation will not generate crashes + if AllowChangeFuzzyFlag then + CleanUp; // Removes previous ID from non-fuzzy entries (not needed for POChecker) {$ENDIF} end; @@ -1617,7 +1619,7 @@ begin end; end; -procedure TPOFile.CheckFormatArguments; +procedure TPOFile.CheckFormatArguments(AllowChangeFuzzyFlag: boolean=true); var I: Integer; aPoItem: TPOFileItem; @@ -1633,7 +1635,7 @@ begin if (pos('%',aPoItem.Original) <> 0) or (pos('%',aPoItem.Translation) <> 0) then begin if not CompareFormatArgs(aPoItem.Original,aPoItem.Translation) then begin inc(FNrErrors); - if not isFuzzy then begin + if (not isFuzzy) and AllowChangeFuzzyFlag then begin aPoItem.ModifyFlag(sFuzzyFlag,true); inc(FNrFuzzy); dec(FNrTranslated); @@ -1643,6 +1645,12 @@ begin aPoItem.ModifyFlag(sBadFormatFlag,true); FModified := true; end; + end + else begin //remove badformat flag (if present) from correct item + if isBadFormat then begin + aPoItem.ModifyFlag(sBadFormatFlag,False); + FModified := true; + end; end; end else begin // possibly an offending string has been removed @@ -1657,26 +1665,18 @@ end; procedure TPOFile.CleanUp; var - I: Integer; + i: Integer; aPoItem: TPOFileItem; isFuzzy: boolean; - isBadFormat: boolean; begin - for I := 0 to FItems.Count -1 do begin - aPoItem := TPOFileItem(FItems.Items[I]); - isFuzzy := pos(sFuzzyFlag,aPoItem.Flags) <> 0; - isBadFormat := pos(sBadFormatFlag,aPoItem.Flags) <> 0; - if not isFuzzy then begin + for i := 0 to FItems.Count -1 do begin + aPoItem := TPOFileItem(FItems.Items[i]); + isFuzzy := pos(sFuzzyFlag,aPoItem.Flags) <> 0; + if not isFuzzy then // remove PreviousID from non-fuzzy Items - if (aPoItem.PreviousID <> '') then begin + if aPoItem.PreviousID <> '' then begin aPoItem.PreviousID := ''; FModified := true; - end; - // remove badformat flag from non-fuzzy Items - if isBadFormat and FFormatChecked then begin - aPoItem.ModifyFlag(sBadFormatFlag,false); - FModified := true; - end; end; // is Context of some use ? {if aPoItem.Context = '' then begin