LCLTranslator: small refactor, ensured setting SetDefaultLang and TranslateLCLResourceStrings results to empty values on exceptions

git-svn-id: trunk@61615 -
This commit is contained in:
maxim 2019-07-22 22:14:25 +00:00
parent 00e57d2560
commit 5e5045ebd1

View File

@ -529,6 +529,7 @@ var
LCLPath: string;
begin
Result:='';
try
LCLPath:=FindLocaleFileName('.po', Lang, ExtractFilePath(Dir), 'lclstrconsts', Result);
if LCLPath<>'' then
Translations.TranslateUnitResourceStrings('LCLStrConsts', LCLPath)
@ -538,6 +539,9 @@ begin
if LCLPath<>'' then
GetText.TranslateResourceStrings(UTF8ToSys(LCLPath));
end;
except
Result:='';
end;
end;
function SetDefaultLang(Lang: string; Dir: string = ''; LocaleFileName: string = ''; ForceUpdate: boolean = true): string;
@ -563,24 +567,20 @@ begin
begin
Translations.TranslateResourceStrings(lcfn);
LocalTranslator := TPOTranslator.Create(lcfn);
end;
except
lcfn := '';
end;
if lcfn='' then
end
else
begin
// try now with MO translation resources
try
lcfn := FindLocaleFileName('.mo', Lang, Dir, LocaleFileName, Result);
if lcfn <> '' then
begin
GetText.TranslateResourceStrings(UTF8ToSys(lcfn));
LocalTranslator := TDefaultTranslator.Create(lcfn);
end;
except
lcfn := '';
end;
except
Result := '';
lcfn := '';
end;
DefaultLang := Result;