POChecker: Removed lots of duplicate translation initialization code, which was used for standalone build. Now using LCLTranslator unit means for this.

git-svn-id: trunk@61542 -
This commit is contained in:
maxim 2019-07-05 23:12:15 +00:00
parent df6ff313ed
commit 631fcf53e1
2 changed files with 10 additions and 122 deletions

View File

@ -1,23 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<Version Value="9"/> <Version Value="12"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<General> <General>
<Flags> <Flags>
<SaveOnlyProjectUnits Value="True"/> <SaveOnlyProjectUnits Value="True"/>
<CompatibilityMode Value="True"/>
</Flags> </Flags>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<ResourceType Value="res"/> <ResourceType Value="res"/>
<UseXPManifest Value="True"/> <UseXPManifest Value="True"/>
</General> </General>
<i18n> <i18n>
<EnableI18N LFM="False"/> <EnableI18N LFM="False"/>
</i18n> </i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="2"> <BuildModes Count="2">
<Item1 Name="Release" Default="True"/> <Item1 Name="Release" Default="True"/>
<Item2 Name="Debug"> <Item2 Name="Debug">
@ -53,13 +50,12 @@
</BuildModes> </BuildModes>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
</PublishOptions> </PublishOptions>
<RunParams> <RunParams>
<local> <FormatVersion Value="2"/>
<FormatVersion Value="1"/> <Modes Count="1">
</local> <Mode0 Name="default"/>
</Modes>
</RunParams> </RunParams>
<RequiredPackages Count="2"> <RequiredPackages Count="2">
<Item1> <Item1>

View File

@ -26,9 +26,9 @@ interface
uses uses
Classes, SysUtils, FileUtil, LazFileUtils, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, LazFileUtils, Forms, Controls, Graphics, Dialogs,
StdCtrls, CheckLst, Buttons, ExtCtrls, ComCtrls, Types, StdCtrls, CheckLst, Buttons, ExtCtrls, ComCtrls, Types,
LCLType, LazUTF8, Translations, LCLType, LazUTF8, LCLTranslator,
{$IFnDEF POCHECKERSTANDALONE} {$IFnDEF POCHECKERSTANDALONE}
{IDEIntf,} MenuIntf, MenuIntf,
{$ENDIF} {$ENDIF}
PoFamilies, ResultDlg, pocheckerconsts, PoCheckerSettings, PoFamilies, ResultDlg, pocheckerconsts, PoCheckerSettings,
PoFamilyLists, PoCheckerMemoDlg; PoFamilyLists, PoCheckerMemoDlg;
@ -85,11 +85,6 @@ type
function LangFilterIndexToLangID(Index: Integer): TLangID; function LangFilterIndexToLangID(Index: Integer): TLangID;
function LangIdToLangFilterIndex(LangID: TLangID): Integer; function LangIdToLangFilterIndex(LangID: TLangID): Integer;
procedure PopulateLangFilter; procedure PopulateLangFilter;
{$IFDEF POCHECKERSTANDALONE}
procedure GetTranslations;
function GetTranslationsSearchPath: String;
procedure FindTranslationFiles(const SearchPath, Lang: String; out PoCheckPo, LclPo: String);
{$ENDIF}
procedure ApplyTranslations; procedure ApplyTranslations;
published published
UnselectAllTestsBtn: TButton; UnselectAllTestsBtn: TButton;
@ -129,7 +124,8 @@ begin
//debugln('TPoCheckerForm.FormCreate A:'); //debugln('TPoCheckerForm.FormCreate A:');
{$IFDEF POCHECKERSTANDALONE} {$IFDEF POCHECKERSTANDALONE}
//Initializing translation //Initializing translation
GetTranslations; SetDefaultLang('', '..' + PathDelim + 'languages', 'pocheckerconsts');
TranslateLCLResourceStrings('', SetDirSeparators('../../../lcl/languages/'));
{$ENDIF} {$ENDIF}
ApplyTranslations; ApplyTranslations;
FillTestListBox; FillTestListBox;
@ -771,99 +767,6 @@ begin
end; end;
end; end;
{$IFDEF POCHECKERSTANDALONE}
function TPoCheckerForm.GetTranslationsSearchPath: String;
var
EnvVar, CfgLocal, CfgGlobal: String;
{$if defined(windows) and not defined(wince)}
AppPath: String;
{$ENDIF}
begin
Result := FPoCheckerSettings.LangPath;
EnvVar := GetEnvironmentVariableUtf8('pochecker-langpath');
if (EnvVar <> '') then
Result := Result + PathSeparator + EnvVar;
Result := Result + PathSeparator + '.';
//Make some educated guesses
//default Lazarus setup, launching the app from project output dir
Result := Result + PathSeparator + '..' + PathDelim + 'languages';
Result := Result + PathSeparator + SetDirSeparators('../../../lcl/languages');
//or from where .lpi resides
Result := Result + PathSeparator + '.' + PathDelim + 'languages';
Result := Result + PathSeparator + SetDirSeparators('../../lcl/languages');
//Look in standard config dirs
CfgLocal := AppendPathDelim(GetLocalConfigPath);
CfgGlobal := AppendPathDelim(GetGlobalConfigPath);
Result := Result + PathSeparator + CfgLocal + PathSeparator + CfgLocal + 'languages';
Result := Result + PathSeparator + CfgGlobal + PathSeparator + CfgGlobal + 'languages';
{$if defined(windows) and not defined(wince)}
AppPath := ExtractFilePath(ParamStr(0));
Result := Result + PathSeparator + AppPath + PathSeparator + AppPath + 'languages';
{$endif}
end;
procedure TPoCheckerForm.FindTranslationFiles(const SearchPath, Lang: String; out PoCheckPo, LclPo: String);
var
SL: TStringList;
i: Integer;
LclPoFnOnly, PoCheckPoFnOnly, Path: String;
begin
PoCheckPo := '';
LclPo := '';
PoCheckPoFnOnly := Format('pocheckerconsts.%s.po',[Lang]);
LclPoFnOnly := Format('lclstrconsts.%s.po',[Lang]);
//debugln('PoCheckPoFnOnly = "',PoCheckPoFnOnly,'"');
//debugln('LclPoFnOnly" = ',LclPoFnOnly,'"');
SL := TStringList.Create;
try
SL.StrictDelimiter := True;
SL.Delimiter := PathSeparator;
SL.DelimitedText := SearchPath;
for i := 0 to SL.Count - 1 do
begin
Path := SL.Strings[i];
if (Path <> '') then
begin
//debugln('Path = ',ExpandFileNameUtf8(Path));
if (Path <> '') then
Path := AppendPathDelim(Path);
if (LclPo = '') and FileExistsUtf8(Path + PoCheckPoFnOnly) then
PoCheckPo := Path + PoCheckPoFnOnly;
if (LclPo = '') and FileExistsUtf8(Path + LclPoFnOnly) then
LclPo := Path + LclPoFnOnly;
end;
if (LclPo <> '') and (LclPo <> '') then
Break;
end;
finally
SL.Free;
end;
end;
procedure TPoCheckerForm.GetTranslations;
var
Lang, T, SearchPath, PoCheckerPo, LclPo: string;
begin
Lang := GetEnvironmentVariableUTF8('LANG');
T := '';
if Lang = '' then
LazGetLanguageIDs(Lang, T);
if Lang <> '' then
begin
//debugln('TPoCheckerForm.GetTranslations: Lang = ',Lang);
if not ((Lang = 'af_ZA') or (Lang = 'pt_BR') or (Lang = 'zh_CN')) then
Lang := copy(Lang, 1, 2);
SearchPath := GetTranslationsSearchPath;
FindTranslationFiles(SearchPath, Lang, PoCheckerPo, LclPo);
//debugln('PoCheckerPo = "',PoCheckerPo,'"');
//debugln('LclPo = "',LclPo,'"');
Translations.TranslateUnitResourceStrings('PoCheckerConsts', PoCheckerPo);
Translations.TranslateUnitResourceStrings('LCLStrConsts', LclPo);
end;
end;
{$ENDIF}
procedure TPoCheckerForm.ApplyTranslations; procedure TPoCheckerForm.ApplyTranslations;
begin begin
LocalizePoTestTypeNames; LocalizePoTestTypeNames;
@ -880,22 +783,11 @@ begin
UnselectAllTestsBtn.Caption := sUnselectAllTests; UnselectAllTestsBtn.Caption := sUnselectAllTests;
end; end;
function SameItem(Item1, Item2: TPoFileItem): boolean;
begin
Result := (Item1.IdentifierLow = Item2.IdentifierLow) and
(Item1.Original = Item2.Original) and (Item1.Context = Item2.Context) and
(Item1.Flags = Item2.Flags) and (Item1.PreviousID = Item2.PreviousID) and
(Item1.Translation = Item2.Translation);
end;
procedure IDEMenuClicked(Sender: TObject); procedure IDEMenuClicked(Sender: TObject);
begin begin
ShowPoCheckerForm; ShowPoCheckerForm;
end; end;
procedure Register; procedure Register;
begin begin
{$IFNDEF POCHECKERSTANDALONE} {$IFNDEF POCHECKERSTANDALONE}