LCLTranslator, Translations units: when translating an item, return original value if translation is empty. Idea by Sergey Bulba. Also improved finding master .po file in LCLTranslator. Fixes bug .

git-svn-id: trunk@58976 -
This commit is contained in:
maxim 2018-09-13 22:03:54 +00:00
parent f492b74d0e
commit db62862efe
2 changed files with 22 additions and 15 deletions
components/lazutils
lcl

View File

@ -1050,9 +1050,12 @@ begin
//Load translation only if it is not flagged as badformat.
//This allows to avoid even more crashes related
//to formatting arguments mismatches.
and (pos(sBadFormatFlag, Item.Flags)=0)
then begin
Result:=Item.Translation;
and (pos(sBadFormatFlag, Item.Flags)=0) then
begin
if Item.Translation<>'' then
Result:=Item.Translation
else
Result:=Item.Original;
if Result='' then
Raise Exception.Create('TPOFile.Translate Inconsistency');
end else

View File

@ -105,10 +105,11 @@ var
begin
DefaultLang := LangID;
AppDir := ExtractFilePath(ParamStrUTF8(0));
LCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
if LangID <> '' then
begin
AppDir := ExtractFilePath(ParamStrUTF8(0));
LCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
FullLCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
if Dir<>'' then
@ -243,6 +244,18 @@ var
exit;
end;
Result := AppDir + LCFileName;
if FileExistsUTF8(Result) then
exit;
Result := AppDir + 'locale' + DirectorySeparator + LCFileName;
if FileExistsUTF8(Result) then
exit;
Result := AppDir + 'languages' + DirectorySeparator + LCFileName;
if FileExistsUTF8(Result) then
exit;
Result := '';
DefaultLang := '';
end;
@ -264,15 +277,6 @@ begin
LazGetLanguageIDs(Lang, T);
Result := GetLocaleFileName(Lang, LCExt, Dir);
if Result <> '' then
exit;
Result := ChangeFileExt(ParamStrUTF8(0), LCExt);
if FileExistsUTF8(Result) then
exit;
Result := '';
DefaultLang := '';
end;
function GetIdentifierPath(Sender: TObject;
@ -459,7 +463,7 @@ constructor TPOTranslator.Create(POFileName: string);
begin
inherited Create;
// TPOFile expects AFileName in UTF-8 encoding, no conversion required
FPOFile := TPOFile.Create(POFileName);
FPOFile := TPOFile.Create(POFileName, true);
end;
constructor TPOTranslator.Create(aPOFile: TPOFile);