lazarus/ide/frames/project_i18n_options.pas
maxim 45daca322f IDE: Add ability to exclude components from i18n by identifier or original text:
1) Added methods to remove entries from TPOFile by identifier and by original text.
2) Implemented storage of excluded identifiers and originals via TProject.
3) Updated translation routines to pass over project's excluded identifiers and originals when updating PO files.
4) Editing of excluded identifiers and originals in i18n project options.
5) Added option to "Force update PO files on next compile" in i18n project options (auto reset, non-persistent). To force update PO files after changing excluded identifiers and originals.

Patch by Denis Kozlov, bug #29627.

git-svn-id: trunk@51589 -
2016-02-10 22:46:00 +00:00

159 lines
5.2 KiB
ObjectPascal

unit project_i18n_options;
{$mode objfpc}{$H+}
interface
uses
StdCtrls, EditBtn, ExtCtrls, LazFileUtils, Project, IDEOptionsIntf,
LazarusIDEStrConsts, IDEDialogs, Classes, Graphics;
type
{ TProjectI18NOptionsFrame }
TProjectI18NOptionsFrame = class(TAbstractIDEOptionsEditor)
ForceUpdatePoFilesCheckBox: TCheckBox;
EnableI18NCheckBox: TCheckBox;
ExcludedGroupBox: TGroupBox;
I18NGroupBox: TGroupBox;
ExcludedIdentifiersMemo: TMemo;
ExcludedOriginalsMemo: TMemo;
ExcludedIdentifiersLabel: TLabel;
ExcludedIdentifiersPanel: TPanel;
ExcludedOriginalsPanel: TPanel;
ExcludedOriginalsLabel: TLabel;
PoForFormsCheckBox: TCheckBox;
POOutDirEdit: TEditButton;
PoOutDirLabel: TLabel;
procedure EnableI18NCheckBoxChange(Sender: TObject);
procedure ExcludedIdentifiersMemoChange(Sender: TObject);
procedure ExcludedOriginalsMemoChange(Sender: TObject);
procedure POOutDirButtonClick(Sender: TObject);
private
FProject: TProject;
FExcludedStringsChanged: Boolean;
procedure Enablei18nInfo(Usei18n: boolean);
public
function GetTitle: string; override;
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
implementation
{$R *.lfm}
{ TProjectI18NOptionsFrame }
procedure TProjectI18NOptionsFrame.EnableI18NCheckBoxChange(Sender: TObject);
begin
Enablei18nInfo(EnableI18NCheckBox.Checked);
end;
procedure TProjectI18NOptionsFrame.POOutDirButtonClick(Sender: TObject);
var
NewDirectory: string;
begin
NewDirectory := LazSelectDirectory(lisPOChoosePoFileDirectory,
FProject.ProjectDirectory);
if NewDirectory = '' then Exit;
if not FProject.IsVirtual then
NewDirectory:=CreateRelativePath(NewDirectory,FProject.ProjectDirectory);
POOutDirEdit.Text := NewDirectory;
end;
procedure TProjectI18NOptionsFrame.ExcludedIdentifiersMemoChange(Sender: TObject);
begin
FExcludedStringsChanged := True;
ExcludedIdentifiersLabel.Font.Style := [fsBold];
ForceUpdatePoFilesCheckBox.Font.Style := [fsBold];
end;
procedure TProjectI18NOptionsFrame.ExcludedOriginalsMemoChange(Sender: TObject);
begin
FExcludedStringsChanged := True;
ExcludedOriginalsLabel.Font.Style := [fsBold];
ForceUpdatePoFilesCheckBox.Font.Style := [fsBold];
end;
procedure TProjectI18NOptionsFrame.Enablei18nInfo(Usei18n: boolean);
begin
I18NGroupBox.Enabled := Usei18n;
ExcludedGroupBox.Enabled := Usei18n;
ForceUpdatePoFilesCheckBox.Enabled := Usei18n;
end;
function TProjectI18NOptionsFrame.GetTitle: string;
begin
Result := dlgPOI18n;
end;
procedure TProjectI18NOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
EnableI18NCheckBox.Caption := rsEnableI18n;
EnableI18NCheckBox.Hint:=lisEnableInternationalizationAndTranslationSupport;
I18NGroupBox.Caption := rsI18nOptions;
PoOutDirLabel.Caption := rsPOOutputDirectory;
POOutDirEdit.Hint:=lisDirectoryWhereTheIDEPutsThePoFiles;
PoForFormsCheckBox.Caption:=lisCreateUpdatePoFileWhenSavingALfmFile;
PoForFormsCheckBox.Hint:=
lisYouCanDisableThisForIndividualFormsViaThePopupMenu;
ExcludedGroupBox.Caption := rsI18nExcluded;
ExcludedIdentifiersLabel.Caption := rsI18nIdentifiers;
ExcludedOriginalsLabel.Caption := rsI18nOriginals;
ForceUpdatePoFilesCheckBox.Caption := rsI18nForceUpdatePoFilesOnNextCompile;
end;
procedure TProjectI18NOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
begin
FProject := (AOptions as TProjectIDEOptions).Project;
with FProject do
begin
POOutDirEdit.Text := POOutputDirectory;
EnableI18NCheckBox.Checked := Enablei18n;
PoForFormsCheckBox.Checked:=EnableI18NForLFM;
ExcludedIdentifiersMemo.Lines.Clear;
ExcludedIdentifiersMemo.Lines.AddStrings(I18NExcludedIdentifiers);
ExcludedOriginalsMemo.Lines.Clear;
ExcludedOriginalsMemo.Lines.AddStrings(I18NExcludedOriginals);
ForceUpdatePoFilesCheckBox.Checked := ForceUpdatePoFiles;
Enablei18nInfo(Enablei18n);
end;
FExcludedStringsChanged := False;
ExcludedIdentifiersLabel.ParentFont := True;
ExcludedOriginalsLabel.ParentFont := True;
ForceUpdatePoFilesCheckBox.ParentFont := True;
POOutDirEdit.Button.LoadGlyphFromResourceName(HInstance, ResBtnSelDir); //DirectoryEdit
end;
procedure TProjectI18NOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
begin
with (AOptions as TProjectIDEOptions).Project do
begin
POOutputDirectory := POOutDirEdit.Text;
EnableI18N := EnableI18NCheckBox.Checked;
EnableI18NForLFM := PoForFormsCheckBox.Checked;
I18NExcludedIdentifiers.Clear;
I18NExcludedIdentifiers.AddStrings(ExcludedIdentifiersMemo.Lines);
I18NExcludedOriginals.Clear;
I18NExcludedOriginals.AddStrings(ExcludedOriginalsMemo.Lines);
ForceUpdatePoFiles := ForceUpdatePoFilesCheckBox.Checked;
if FExcludedStringsChanged then
Modified := True;
end;
end;
class function TProjectI18NOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result := TProjectIDEOptions;
end;
initialization
RegisterIDEOptionsEditor(GroupProject, TProjectI18NOptionsFrame, ProjectOptionsI18N);
end.