Skip to content

Commit

Permalink
work on #279 #245
Browse files Browse the repository at this point in the history
  • Loading branch information
URUWorks committed Mar 10, 2024
1 parent b01a567 commit 1746873
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 34 deletions.
4 changes: 2 additions & 2 deletions TeroSubtitler/src/formTBX.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object frmTBX: TfrmTBX
OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '2.2.6.0'
LCLVersion = '3.2.0.0'
object VST: TLazVirtualStringTree
AnchorSideRight.Control = btnClose
AnchorSideBottom.Control = btnClose
Expand Down Expand Up @@ -54,7 +54,7 @@ object frmTBX: TfrmTBX
BorderSpacing.Bottom = 8
Cancel = True
Caption = 'Close'
OnClick = btnCloseClick
TabOrder = 1
OnClick = btnCloseClick
end
end
3 changes: 2 additions & 1 deletion TeroSubtitler/src/formTBX.pas
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TfrmTBX = class(TForm)
implementation

uses
procTypes, procVST, procWorkspace, procColorTheme, procConfig;
procTypes, procVST, procWorkspace, procColorTheme, procConfig, formMain;

{$R *.lfm}

Expand Down Expand Up @@ -91,6 +91,7 @@ procedure TfrmTBX.FormShow(Sender: TObject);
begin
LoadFormSettings(Self);
CheckColorTheme(Self);
CheckForTerminology(VSTFocusedNode(frmMain.VST));
end;

// -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion TeroSubtitler/src/formTBXSettings.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object frmTBXSettings: TfrmTBXSettings
OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '3.0.0.3'
LCLVersion = '3.2.0.0'
object edtOpenFile: TEdit
AnchorSideRight.Control = btnOpenFile
Left = 160
Expand Down
51 changes: 42 additions & 9 deletions TeroSubtitler/src/formTBXSettings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TfrmTBXSettings = class(TForm)
implementation

uses
procWorkspace, UWSystem.Globalization, procTypes;
procWorkspace, UWSystem.Globalization, procTypes, procConfig, procForms;

{$R *.lfm}

Expand All @@ -73,9 +73,17 @@ procedure TfrmTBXSettings.FormCreate(Sender: TObject);
FillCultureTStrings(cboSourceLang.Items);
cboTransLang.Items.Assign(cboSourceLang.Items);

//TODO: Localize = Maybe nothing to do
cboSourceLang.ItemIndex := 49; // eng
cboTransLang.ItemIndex := 120; // spa
edtOpenFile.Text := TBX.FileName;

if TBX.Langs^.SrcLang <> '' then
cboSourceLang.ItemIndex := GetCultureIndex(TBX.Langs^.SrcLang)
else
cboSourceLang.ItemIndex := 49; // eng

if TBX.Langs^.DstLang <> '' then
cboTransLang.ItemIndex := GetCultureIndex(TBX.Langs^.DstLang)
else
cboTransLang.ItemIndex := 120; // spa
end;

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -110,9 +118,17 @@ procedure TfrmTBXSettings.btnOpenFileClick(Sender: TObject);
OD := TOpenDialog.Create(NIL);
try
OD.Title := lngOpenFile;
OD.Filter := lngAllSupportedFiles + '(*.tbx)|*.tbx';
OD.Filter := lngAllSupportedFiles + ' (*.tbx)|*.tbx';
OD.Options := [ofCreatePrompt, ofOverwritePrompt];

if edtOpenFile.Text <> '' then
begin
OD.FileName := ExtractFileName(edtOpenFile.Text);
OD.InitialDir := ExtractFileDir(edtOpenFile.Text);
end
else
OD.InitialDir := TerminologyFolder;

if OD.Execute then
begin
if not FileExists(OD.FileName) and (ExtractFileExt(OD.FileName) = '') then
Expand All @@ -128,12 +144,29 @@ procedure TfrmTBXSettings.btnOpenFileClick(Sender: TObject);
// -----------------------------------------------------------------------------

procedure TfrmTBXSettings.btnApplyClick(Sender: TObject);
var
s: String;
begin
TBX.Header^.lang := GetCultureName(cboSourceLang.ItemIndex);
TBX.Langs^.SrcLang := GetCultureShortName(cboSourceLang.ItemIndex);
TBX.Langs^.DstLang := GetCultureShortName(cboTransLang.ItemIndex);
TBX.LoadFromFile(edtOpenFile.Text);
Close;
TBX.Langs^.SrcLang := GetCultureName(cboSourceLang.ItemIndex);
TBX.Langs^.DstLang := GetCultureName(cboTransLang.ItemIndex);
//TBX.Langs^.SrcLang := GetCultureShortName(cboSourceLang.ItemIndex);
//TBX.Langs^.DstLang := GetCultureShortName(cboTransLang.ItemIndex);

if edtOpenFile.Text <> '' then
begin
s := edtOpenFile.Text;

if not FileExists(s) and (ExtractFileDir(s) = '') then
s := ConcatPaths([TerminologyFolder, ChangeFileExt(s, '.tbx')]);

TBX.LoadFromFile(s);

ShowTBX;
Close;
end
else
edtOpenFile.SetFocus;
end;

// -----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions TeroSubtitler/src/formTranslationMemory.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object frmTranslationMemory: TfrmTranslationMemory
OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '2.2.6.0'
LCLVersion = '3.2.0.0'
object VST: TLazVirtualStringTree
AnchorSideRight.Control = btnClose
AnchorSideBottom.Control = Owner
Expand Down Expand Up @@ -50,8 +50,8 @@ object frmTranslationMemory: TfrmTranslationMemory
Anchors = [akTop, akRight]
Caption = 'Copy'
Default = True
OnClick = btnCopyClick
TabOrder = 1
OnClick = btnCopyClick
end
object btnValidate: TButton
AnchorSideTop.Control = btnCopy
Expand All @@ -63,8 +63,8 @@ object frmTranslationMemory: TfrmTranslationMemory
Anchors = [akTop, akRight]
BorderSpacing.Top = 5
Caption = 'Validate'
OnClick = btnValidateClick
TabOrder = 2
OnClick = btnValidateClick
end
object btnClose: TButton
AnchorSideRight.Control = Owner
Expand All @@ -80,8 +80,8 @@ object frmTranslationMemory: TfrmTranslationMemory
BorderSpacing.Bottom = 8
Cancel = True
Caption = 'Close'
OnClick = btnCloseClick
TabOrder = 4
OnClick = btnCloseClick
end
object btnUse: TButton
AnchorSideTop.Control = btnValidate
Expand All @@ -93,7 +93,7 @@ object frmTranslationMemory: TfrmTranslationMemory
Anchors = [akTop, akRight]
BorderSpacing.Top = 5
Caption = 'Use'
OnClick = btnUseClick
TabOrder = 3
OnClick = btnUseClick
end
end
3 changes: 3 additions & 0 deletions TeroSubtitler/src/formTranslationMemory.pas
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ procedure TfrmTranslationMemory.btnUseClick(Sender: TObject);
begin
if Assigned(VST.FocusedNode) then
with VST.FocusedNode^ do
begin
Subtitles.ItemPointer[VSTFocusedNode(frmMain.VST)]^.Data := TMX.IndexFromMap(Index)+1;
frmMain.mmoTranslation.Text := GetItemAtIndex(Index);
end;
end;

// -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion TeroSubtitler/src/formTranslationMemorySettings.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object frmTranslationMemorySettings: TfrmTranslationMemorySettings
OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '3.0.0.3'
LCLVersion = '3.2.0.0'
object edtOpenFile: TEdit
AnchorSideRight.Control = btnOpenFile
Left = 160
Expand Down
59 changes: 50 additions & 9 deletions TeroSubtitler/src/formTranslationMemorySettings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
interface

uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LCLTranslator, procLocalize;
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
LCLTranslator, procLocalize;

type

Expand Down Expand Up @@ -58,7 +59,8 @@ TfrmTranslationMemorySettings = class(TForm)
implementation

uses
procWorkspace, UWSystem.Globalization, procTypes;
procWorkspace, UWSystem.Globalization, procTypes, procConfig, procForms,
UWSubtitleAPI.TMX, formMain;

{$R *.lfm}

Expand All @@ -73,9 +75,17 @@ procedure TfrmTranslationMemorySettings.FormCreate(Sender: TObject);
FillCultureTStrings(cboSourceLang.Items);
cboTransLang.Items.Assign(cboSourceLang.Items);

//TODO: Localize = Maybe nothing to do
cboSourceLang.ItemIndex := 49; // eng
cboTransLang.ItemIndex := 120; // spa
edtOpenFile.Text := TMX.FileName;

if TMX.Langs^.SrcLang <> '' then
cboSourceLang.ItemIndex := GetCultureIndex(TMX.Langs^.SrcLang)
else
cboSourceLang.ItemIndex := 49; // eng

if TMX.Langs^.DstLang <> '' then
cboTransLang.ItemIndex := GetCultureIndex(TMX.Langs^.DstLang)
else
cboTransLang.ItemIndex := 120; // spa
end;

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -110,9 +120,17 @@ procedure TfrmTranslationMemorySettings.btnOpenFileClick(Sender: TObject);
OD := TOpenDialog.Create(NIL);
try
OD.Title := lngOpenFile;
OD.Filter := lngAllSupportedFiles + '(*.tmx)|*.tmx';
OD.Filter := lngAllSupportedFiles + ' (*.tmx)|*.tmx';
OD.Options := [ofCreatePrompt, ofOverwritePrompt];

if edtOpenFile.Text <> '' then
begin
OD.FileName := ExtractFileName(edtOpenFile.Text);
OD.InitialDir := ExtractFileDir(edtOpenFile.Text);
end
else
OD.InitialDir := TranslationMemoryFolder;

if OD.Execute then
begin
if not FileExists(OD.FileName) and (ExtractFileExt(OD.FileName) = '') then
Expand All @@ -128,13 +146,36 @@ procedure TfrmTranslationMemorySettings.btnOpenFileClick(Sender: TObject);
// -----------------------------------------------------------------------------

procedure TfrmTranslationMemorySettings.btnApplyClick(Sender: TObject);
var
s : String;
hdr : TUWTMXHeader;
begin
TMX.Langs^.SrcLang := GetCultureName(cboSourceLang.ItemIndex);
TMX.Langs^.DstLang := GetCultureName(cboTransLang.ItemIndex);
TMX.LoadFromFile(edtOpenFile.Text);

//ShowTranslationMemory;
Close;
if edtOpenFile.Text <> '' then
begin
s := edtOpenFile.Text;

if not FileExists(s) and (ExtractFileDir(s) = '') then
s := ConcatPaths([TranslationMemoryFolder, ChangeFileExt(s, '.tmx')]);

TMX.LoadFromFile(s);

hdr := TMX.Header;
hdr.creationtool := ProgramName;
TMX.Header := hdr;

ShowTranslationMemory;
if not Workspace.TranslatorMode then
frmMain.actTranslatorMode.Execute
else
frmMain.VST.Invalidate;

Close;
end
else
edtOpenFile.SetFocus;
end;

// -----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions TeroSubtitler/src/procFiles.pas
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ function CloseSubtitle(const AKeepVideoOpen: Boolean): Boolean;
if not AKeepVideoOpen then
actCloseVideo.Execute;

CloseTranslationMemory;
CloseTerminology;

SubtitleInfo.Text.FileName := '';
SubtitleInfo.Translation.FileName := '';
SubtitleChangedReset;
Expand Down
18 changes: 18 additions & 0 deletions TeroSubtitler/src/procWorkspace.pas
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ procedure UpdateVideoLengthString;
procedure GetTranslationMemoryAtIndex(const Index: Integer);
procedure CheckForTranslationMemory(const AIndex: Integer);
procedure CheckForTerminology(const AIndex: Integer);
procedure CloseTranslationMemory;
procedure CloseTerminology;

procedure RefreshAppTitle;

Expand Down Expand Up @@ -1314,6 +1316,22 @@ procedure CheckForTerminology(const AIndex: Integer);

// -----------------------------------------------------------------------------

procedure CloseTranslationMemory;
begin
if (frmTranslationMemory <> NIL) then frmTranslationMemory.Close;
TMX.Close;
end;

// -----------------------------------------------------------------------------

procedure CloseTerminology;
begin
if (frmTBX <> NIL) then frmTBX.Close;
TBX.Close;
end;

// -----------------------------------------------------------------------------

procedure RefreshAppTitle;
var
s: String;
Expand Down
16 changes: 12 additions & 4 deletions TeroSubtitler/subtitleapi/UWSubtitleAPI.TBX.pas
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ TUWTBX = class
destructor Destroy; override;
procedure Clear;
procedure Close;
procedure Save;
procedure LoadFromFile(const AFileName: String);
function SaveToFile(const AFileName: String): Boolean;
function AddItem(const Original, Translated, Notes: String; const AllowDuplicate: Boolean = False): Integer;
Expand Down Expand Up @@ -116,8 +117,9 @@ function ListCompare(const Item1, Item2: PUWTBXItem): Integer;
constructor TUWTBX.Create(const AFileName: String; ASrcLang: String = ''; ADstLang: String = '');
begin
FillByte(FHeader, SizeOf(TUWTBXHeader), 0);
if ASrcLang.IsEmpty then ASrcLang := 'en';
if ADstLang.IsEmpty then ADstLang := 'es';
if ASrcLang.IsEmpty then ASrcLang := 'en-US'; //'en';
if ADstLang.IsEmpty then ADstLang := 'es-ES'; //'es';

FLangs.SrcLang := ASrcLang;
FLangs.DstLang := ADstLang;

Expand Down Expand Up @@ -163,11 +165,17 @@ procedure TUWTBX.Clear;
// -----------------------------------------------------------------------------

procedure TUWTBX.Close;
begin
Save;
Clear;
end;

// -----------------------------------------------------------------------------

procedure TUWTBX.Save;
begin
if FChanged then
SaveToFile(FFileName);

Clear;
end;

// -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 1746873

Please sign in to comment.