From 62223144ab1d8a437c3e2e9d0354908c14bb8363 Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 21 Feb 2018 23:35:04 +0000 Subject: [PATCH] LazUtils, translations.pas unit: avoid the need to double-regenerate PO files in order to set context correctly when items are changed in the following manner: "a" -> "c" "b" -> "c" Copying fuzzy translations has been disabled because it practically does not help translators and can create potential confusion (some items (like in case above) will appear to have false history, and suggested translation is incorrect anyway). Instead now we guarantee to suggest non-fuzzy translation if it exists. TPOFile.OriginalList property is removed: it was meant for PoChecker and is not needed by it anymore, its underlying field contents have been changed in order to allow aforementioned changes and most likely will be changed again in near future. git-svn-id: trunk@57346 - --- components/lazutils/translations.pas | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/components/lazutils/translations.pas b/components/lazutils/translations.pas index ec39c890fc..822b1ba2af 100644 --- a/components/lazutils/translations.pas +++ b/components/lazutils/translations.pas @@ -194,7 +194,6 @@ type property NrErrors: Integer read FNrErrors; function FindPoItem(const Identifier: String): TPoFileItem; function OriginalToItem(const Data: String): TPoFileItem; - property OriginalList: TStringHashList read FOriginalToItem; property PoItems[Index: Integer]: TPoFileItem read GetPoItem; property Count: Integer read GetCount; property Header: TPOFileItem read FHeader; @@ -1706,15 +1705,13 @@ begin FoundItem.Duplicate := true; CurrentItem.Duplicate := true; // if old item is already translated and current item not, use translation - if (CurrentItem.Translation='') and (FoundItem.Translation<>'') then + // note, that we do not copy fuzzy translations in order not to potentially mislead translators + if (CurrentItem.Translation='') and (FoundItem.Translation<>'') and (pos(sFuzzyFlag, FoundItem.Flags) = 0) then begin CurrentItem.Translation := FoundItem.Translation; if CurrentItem.Flags='' then CurrentItem.Flags := FoundItem.Flags; CurrentItem.ModifyFlag(sFuzzyFlag, true); - // if old item is fuzzy, copy PreviousID too - if pos(sFuzzyFlag, FoundItem.Flags)<>0 then - CurrentItem.PreviousID := FoundItem.PreviousID; FModified := True; end; end; @@ -1733,10 +1730,20 @@ begin P := Pos('.', Identifier); if P>0 then FIdentLowVarToItem.Add(copy(CurrentItem.IdentifierLow, P+1, Length(CurrentItem.IdentifierLow)), CurrentItem); - - if Original <> '' then - FOriginalToItem.Add(Original,CurrentItem); end; + + if Original <> '' then + begin + if (FoundItem = nil) or ((FoundItem.Translation = '') and (CurrentItem.Translation <> '')) or + ((FoundItem.Translation <> '') and (CurrentItem.Translation <> '') and + (pos(sFuzzyFlag, FoundItem.Flags) <> 0) and (pos(sFuzzyFlag, CurrentItem.Flags) = 0)) then + begin + if FoundItem <> nil then + FOriginalToItem.Remove(Original); + FOriginalToItem.Add(Original,CurrentItem); + end; + end; + end; procedure TPOFile.UpdateTranslation(BasePOFile: TPOFile);