add generic translation form

This commit is contained in:
mikl 2020-12-07 20:44:19 +01:00
parent 73d15a9a23
commit a16265ded6
10 changed files with 2908 additions and 14 deletions

View File

@ -1775,7 +1775,7 @@ If you have edited this file with Subtitle Edit you might be able to find a back
</NetworkChat>
<NetworkJoin>
<Title>Join network session</Title>
<Information>Join existing session where multiple persons
<Information>Join existing session where multiple persons
can edit in same subtitle file (collaboration)</Information>
<Join>Join</Join>
</NetworkJoin>
@ -1786,7 +1786,7 @@ can edit in same subtitle file (collaboration)</Information>
<NetworkStart>
<Title>Start network session</Title>
<ConnectionTo>Connecting to {0}...</ConnectionTo>
<Information>Start new session where multiple persons
<Information>Start new session where multiple persons
can edit in same subtitle file (collaboration)</Information>
<Start>Start</Start>
</NetworkStart>
@ -2585,8 +2585,8 @@ Continue?</RestoreDefaultSettingsMsg>
<FindText>Find text</FindText>
<GoToSubPosition>Go to sub pos</GoToSubPosition>
<KeepChangesTitle>Keep changes?</KeepChangesTitle>
<KeepChangesMessage>Changes have been made to subtitle in 'Visual sync'.
<KeepChangesMessage>Changes have been made to subtitle in 'Visual sync'.
Keep changes?</KeepChangesMessage>
<SynchronizationDone>Sync done!</SynchronizationDone>
<StartSceneMustComeBeforeEndScene>Start scene must come before end scene!</StartSceneMustComeBeforeEndScene>

View File

@ -0,0 +1,28 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("libse")]
[assembly: AssemblyDescription("a43841ddb0befc1e0e97fb9b95ace99fa2641c87")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nikse")]
[assembly: AssemblyProduct("libse")]
[assembly: AssemblyCopyright("Copyright 2001-2020, Nikse")]
[assembly: AssemblyTrademark("Licensed under the GPL v3")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("eab3b9db-0f82-4843-982b-05a4c51888a2")]
[assembly: AssemblyVersion("3.5.17.136")]
// Make the internal types available in our testing assembly.
[assembly: InternalsVisibleTo("Test")]

1619
src/SubtitleEdit.csproj Normal file

File diff suppressed because it is too large Load Diff

73
src/SubtitleEdit.sln Normal file
View File

@ -0,0 +1,73 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29728.190
MinimumVisualStudioVersion = 14.0.23107.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubtitleEdit", "SubtitleEdit.csproj", "{511A5B59-1C35-4719-8536-23B19AF9B21A}"
ProjectSection(ProjectDependencies) = postProject
{DBD4656C-5F40-4067-A70B-C4460DE20F77} = {DBD4656C-5F40-4067-A70B-C4460DE20F77}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{7BE5B8E8-9469-4C7C-89D7-E8C884DEFC0E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateAssemblyInfo", "UpdateAssemblyInfo\UpdateAssemblyInfo.csproj", "{DBD4656C-5F40-4067-A70B-C4460DE20F77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateLanguageFiles", "UpdateLanguageFiles\UpdateLanguageFiles.csproj", "{36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateResourceScript", "UpdateResourceScript\UpdateResourceScript.csproj", "{2CB9698C-F0A8-42FF-8938-DE047292D5FE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibSE", "..\libse\LibSE.csproj", "{3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}"
ProjectSection(ProjectDependencies) = postProject
{DBD4656C-5F40-4067-A70B-C4460DE20F77} = {DBD4656C-5F40-4067-A70B-C4460DE20F77}
{36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76} = {36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Win32Resources", "Win32Resources\Win32Resources.vcxproj", "{905ACC84-B353-4313-BFE5-CCF460B959AF}"
ProjectSection(ProjectDependencies) = postProject
{511A5B59-1C35-4719-8536-23B19AF9B21A} = {511A5B59-1C35-4719-8536-23B19AF9B21A}
{2CB9698C-F0A8-42FF-8938-DE047292D5FE} = {2CB9698C-F0A8-42FF-8938-DE047292D5FE}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{511A5B59-1C35-4719-8536-23B19AF9B21A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{511A5B59-1C35-4719-8536-23B19AF9B21A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{511A5B59-1C35-4719-8536-23B19AF9B21A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{511A5B59-1C35-4719-8536-23B19AF9B21A}.Release|Any CPU.Build.0 = Release|Any CPU
{7BE5B8E8-9469-4C7C-89D7-E8C884DEFC0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BE5B8E8-9469-4C7C-89D7-E8C884DEFC0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BE5B8E8-9469-4C7C-89D7-E8C884DEFC0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BE5B8E8-9469-4C7C-89D7-E8C884DEFC0E}.Release|Any CPU.Build.0 = Release|Any CPU
{DBD4656C-5F40-4067-A70B-C4460DE20F77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DBD4656C-5F40-4067-A70B-C4460DE20F77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBD4656C-5F40-4067-A70B-C4460DE20F77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBD4656C-5F40-4067-A70B-C4460DE20F77}.Release|Any CPU.Build.0 = Release|Any CPU
{36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}.Release|Any CPU.Build.0 = Release|Any CPU
{2CB9698C-F0A8-42FF-8938-DE047292D5FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CB9698C-F0A8-42FF-8938-DE047292D5FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CB9698C-F0A8-42FF-8938-DE047292D5FE}.Release|Any CPU.Build.0 = Release|Any CPU
{3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}.Release|Any CPU.Build.0 = Release|Any CPU
{905ACC84-B353-4313-BFE5-CCF460B959AF}.Debug|Any CPU.ActiveCfg = Debug|Win32
{905ACC84-B353-4313-BFE5-CCF460B959AF}.Release|Any CPU.ActiveCfg = Release|Win32
{905ACC84-B353-4313-BFE5-CCF460B959AF}.Release|Any CPU.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E12BDE22-B6A4-4AB6-AF96-F3C0F89C15EC}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = SubtitleEdit.vsmdi
EndGlobalSection
EndGlobal

251
src/ui/Forms/GenericTranslate.Designer.cs generated Normal file
View File

@ -0,0 +1,251 @@
using Nikse.SubtitleEdit.Controls;
namespace Nikse.SubtitleEdit.Forms
{
sealed partial class GenericTranslate
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBoxFrom = new System.Windows.Forms.ComboBox();
this.labelFrom = new System.Windows.Forms.Label();
this.labelTo = new System.Windows.Forms.Label();
this.comboBoxTo = new System.Windows.Forms.ComboBox();
this.buttonTranslate = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.linkLabelPoweredByGoogleTranslate = new System.Windows.Forms.LinkLabel();
this.labelPleaseWait = new System.Windows.Forms.Label();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.subtitleListViewTo = new Nikse.SubtitleEdit.Controls.SubtitleListView();
this.subtitleListViewFrom = new Nikse.SubtitleEdit.Controls.SubtitleListView();
this.labelApiKeyNotFound = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// comboBoxFrom
//
this.comboBoxFrom.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxFrom.FormattingEnabled = true;
this.comboBoxFrom.Location = new System.Drawing.Point(327, 34);
this.comboBoxFrom.Name = "comboBoxFrom";
this.comboBoxFrom.Size = new System.Drawing.Size(121, 21);
this.comboBoxFrom.TabIndex = 0;
//
// labelFrom
//
this.labelFrom.AutoSize = true;
this.labelFrom.Location = new System.Drawing.Point(285, 41);
this.labelFrom.Name = "labelFrom";
this.labelFrom.Size = new System.Drawing.Size(35, 13);
this.labelFrom.TabIndex = 1;
this.labelFrom.Text = "From:";
//
// labelTo
//
this.labelTo.AutoSize = true;
this.labelTo.Location = new System.Drawing.Point(468, 37);
this.labelTo.Name = "labelTo";
this.labelTo.Size = new System.Drawing.Size(23, 13);
this.labelTo.TabIndex = 4;
this.labelTo.Text = "To:";
//
// comboBoxTo
//
this.comboBoxTo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxTo.FormattingEnabled = true;
this.comboBoxTo.Location = new System.Drawing.Point(497, 34);
this.comboBoxTo.Name = "comboBoxTo";
this.comboBoxTo.Size = new System.Drawing.Size(121, 21);
this.comboBoxTo.TabIndex = 3;
//
// buttonTranslate
//
this.buttonTranslate.Location = new System.Drawing.Point(624, 34);
this.buttonTranslate.Name = "buttonTranslate";
this.buttonTranslate.Size = new System.Drawing.Size(75, 23);
this.buttonTranslate.TabIndex = 5;
this.buttonTranslate.Text = "Translate";
this.buttonTranslate.UseVisualStyleBackColor = true;
this.buttonTranslate.Click += new System.EventHandler(this.buttonTranslate_Click);
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.Location = new System.Drawing.Point(754, 529);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 6;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.ButtonOkClick);
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(835, 529);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// linkLabelPoweredByGoogleTranslate
//
this.linkLabelPoweredByGoogleTranslate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.linkLabelPoweredByGoogleTranslate.AutoSize = true;
this.linkLabelPoweredByGoogleTranslate.Location = new System.Drawing.Point(15, 529);
this.linkLabelPoweredByGoogleTranslate.Name = "linkLabelPoweredByGoogleTranslate";
this.linkLabelPoweredByGoogleTranslate.Size = new System.Drawing.Size(146, 13);
this.linkLabelPoweredByGoogleTranslate.TabIndex = 8;
this.linkLabelPoweredByGoogleTranslate.TabStop = true;
this.linkLabelPoweredByGoogleTranslate.Text = "Powered by Google translate";
this.linkLabelPoweredByGoogleTranslate.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LinkLabel1LinkClicked);
//
// labelPleaseWait
//
this.labelPleaseWait.AutoSize = true;
this.labelPleaseWait.Location = new System.Drawing.Point(703, 23);
this.labelPleaseWait.Name = "labelPleaseWait";
this.labelPleaseWait.Size = new System.Drawing.Size(176, 13);
this.labelPleaseWait.TabIndex = 10;
this.labelPleaseWait.Text = "Please wait... this may take a while";
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(705, 39);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(192, 16);
this.progressBar1.TabIndex = 11;
//
// subtitleListViewTo
//
this.subtitleListViewTo.AllowColumnReorder = true;
this.subtitleListViewTo.FirstVisibleIndex = -1;
this.subtitleListViewTo.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.subtitleListViewTo.FullRowSelect = true;
this.subtitleListViewTo.GridLines = true;
this.subtitleListViewTo.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.subtitleListViewTo.HideSelection = false;
this.subtitleListViewTo.Location = new System.Drawing.Point(471, 64);
this.subtitleListViewTo.Name = "subtitleListViewTo";
this.subtitleListViewTo.OwnerDraw = true;
this.subtitleListViewTo.Size = new System.Drawing.Size(428, 459);
this.subtitleListViewTo.SubtitleFontBold = false;
this.subtitleListViewTo.SubtitleFontName = "Tahoma";
this.subtitleListViewTo.SubtitleFontSize = 8;
this.subtitleListViewTo.TabIndex = 2;
this.subtitleListViewTo.UseCompatibleStateImageBehavior = false;
this.subtitleListViewTo.UseSyntaxColoring = true;
this.subtitleListViewTo.View = System.Windows.Forms.View.Details;
this.subtitleListViewTo.Click += new System.EventHandler(this.subtitleListViewTo_DoubleClick);
this.subtitleListViewTo.DoubleClick += new System.EventHandler(this.subtitleListViewTo_DoubleClick);
//
// subtitleListViewFrom
//
this.subtitleListViewFrom.AllowColumnReorder = true;
this.subtitleListViewFrom.FirstVisibleIndex = -1;
this.subtitleListViewFrom.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.subtitleListViewFrom.FullRowSelect = true;
this.subtitleListViewFrom.GridLines = true;
this.subtitleListViewFrom.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.subtitleListViewFrom.HideSelection = false;
this.subtitleListViewFrom.Location = new System.Drawing.Point(18, 64);
this.subtitleListViewFrom.Name = "subtitleListViewFrom";
this.subtitleListViewFrom.OwnerDraw = true;
this.subtitleListViewFrom.Size = new System.Drawing.Size(430, 459);
this.subtitleListViewFrom.SubtitleFontBold = false;
this.subtitleListViewFrom.SubtitleFontName = "Tahoma";
this.subtitleListViewFrom.SubtitleFontSize = 8;
this.subtitleListViewFrom.TabIndex = 0;
this.subtitleListViewFrom.UseCompatibleStateImageBehavior = false;
this.subtitleListViewFrom.UseSyntaxColoring = true;
this.subtitleListViewFrom.View = System.Windows.Forms.View.Details;
this.subtitleListViewFrom.Click += new System.EventHandler(this.subtitleListViewFrom_DoubleClick);
this.subtitleListViewFrom.DoubleClick += new System.EventHandler(this.subtitleListViewFrom_DoubleClick);
//
// labelApiKeyNotFound
//
this.labelApiKeyNotFound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.labelApiKeyNotFound.AutoSize = true;
this.labelApiKeyNotFound.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
this.labelApiKeyNotFound.Location = new System.Drawing.Point(202, 529);
this.labelApiKeyNotFound.Name = "labelApiKeyNotFound";
this.labelApiKeyNotFound.Size = new System.Drawing.Size(145, 13);
this.labelApiKeyNotFound.TabIndex = 12;
this.labelApiKeyNotFound.Text = "Warning: API key not found!";
//
// GoogleTranslate
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(925, 558);
this.Controls.Add(this.labelApiKeyNotFound);
this.Controls.Add(this.comboBoxFrom);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.labelPleaseWait);
this.Controls.Add(this.linkLabelPoweredByGoogleTranslate);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonTranslate);
this.Controls.Add(this.labelTo);
this.Controls.Add(this.comboBoxTo);
this.Controls.Add(this.subtitleListViewTo);
this.Controls.Add(this.subtitleListViewFrom);
this.Controls.Add(this.labelFrom);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.KeyPreview = true;
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(900, 500);
this.Name = "GoogleTranslate";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Google translate";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormGoogleTranslate_KeyDown);
this.Resize += new System.EventHandler(this.GoogleTranslate_Resize);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ComboBox comboBoxFrom;
private System.Windows.Forms.Label labelFrom;
private SubtitleListView subtitleListViewFrom;
private SubtitleListView subtitleListViewTo;
private System.Windows.Forms.Label labelTo;
private System.Windows.Forms.ComboBox comboBoxTo;
private System.Windows.Forms.Button buttonTranslate;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.LinkLabel linkLabelPoweredByGoogleTranslate;
private System.Windows.Forms.Label labelPleaseWait;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label labelApiKeyNotFound;
}
}

View File

@ -0,0 +1,569 @@
using Nikse.SubtitleEdit.Controls;
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Core.Translate;
using Nikse.SubtitleEdit.Logic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core.Common;
namespace Nikse.SubtitleEdit.Forms
{
public sealed partial class GenericTranslate : PositionAndSizeForm
{
public Subtitle TranslatedSubtitle { get; private set; }
private Subtitle _subtitle;
private bool _breakTranslation;
private bool _googleTranslate = true;
private const string SplitterString = "+-+";
private ITranslator _translator;
private enum FormattingType
{
None,
Italic,
ItalicTwoLines
}
private static string GoogleTranslateUrl => new GoogleTranslator2(Configuration.Settings.Tools.GoogleApiV2Key).GetUrl();
private FormattingType[] _formattingTypes;
private bool[] _autoSplit;
private string _targetTwoLetterIsoLanguageName;
public class ComboBoxItem
{
public string Text { get; set; }
public string Value { get; set; }
public ComboBoxItem(string text, string value)
{
if (text.Length > 1)
{
text = char.ToUpper(text[0]) + text.Substring(1).ToLowerInvariant();
}
Text = text;
Value = value;
}
public override string ToString()
{
return Text;
}
}
public GenericTranslate()
{
UiUtil.PreInitialize(this);
InitializeComponent();
UiUtil.FixFonts(this);
Text = Configuration.Settings.Language.GoogleTranslate.Title;
labelFrom.Text = Configuration.Settings.Language.GoogleTranslate.From;
labelTo.Text = Configuration.Settings.Language.GoogleTranslate.To;
buttonTranslate.Text = Configuration.Settings.Language.GoogleTranslate.Translate;
labelPleaseWait.Text = Configuration.Settings.Language.GoogleTranslate.PleaseWait;
linkLabelPoweredByGoogleTranslate.Text = Configuration.Settings.Language.GoogleTranslate.PoweredByGoogleTranslate;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
labelApiKeyNotFound.Text = string.Empty;
subtitleListViewFrom.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings);
subtitleListViewTo.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings);
subtitleListViewFrom.HideColumn(SubtitleListView.SubtitleColumn.CharactersPerSeconds);
subtitleListViewFrom.HideColumn(SubtitleListView.SubtitleColumn.WordsPerMinute);
subtitleListViewTo.HideColumn(SubtitleListView.SubtitleColumn.CharactersPerSeconds);
subtitleListViewTo.HideColumn(SubtitleListView.SubtitleColumn.WordsPerMinute);
UiUtil.InitializeSubtitleFont(subtitleListViewFrom);
UiUtil.InitializeSubtitleFont(subtitleListViewTo);
subtitleListViewFrom.AutoSizeColumns();
subtitleListViewFrom.AutoSizeColumns();
UiUtil.FixLargeFonts(this, buttonOK);
}
internal void Initialize(Subtitle subtitle, Subtitle target, string title, bool googleTranslate, Encoding encoding)
{
if (title != null)
{
Text = title;
}
_googleTranslate = googleTranslate;
if (!_googleTranslate)
{
_translator = new MicrosoftTranslator(Configuration.Settings.Tools.MicrosoftTranslatorApiKey, Configuration.Settings.Tools.MicrosoftTranslatorTokenEndpoint, Configuration.Settings.Tools.MicrosoftTranslatorCategory);
linkLabelPoweredByGoogleTranslate.Text = Configuration.Settings.Language.GoogleTranslate.PoweredByMicrosoftTranslate;
}
labelPleaseWait.Visible = false;
progressBar1.Visible = false;
_subtitle = subtitle;
if (target != null)
{
TranslatedSubtitle = new Subtitle(target);
subtitleListViewTo.Fill(TranslatedSubtitle);
}
else
{
TranslatedSubtitle = new Subtitle(subtitle);
foreach (var paragraph in TranslatedSubtitle.Paragraphs)
{
paragraph.Text = string.Empty;
}
}
string defaultFromLanguage = LanguageAutoDetect.AutoDetectGoogleLanguage(encoding); // Guess language via encoding
if (string.IsNullOrEmpty(defaultFromLanguage))
{
defaultFromLanguage = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle); // Guess language based on subtitle contents
}
if (defaultFromLanguage == "he")
{
defaultFromLanguage = "iw";
}
FillComboWithLanguages(comboBoxFrom);
int i = 0;
foreach (ComboBoxItem item in comboBoxFrom.Items)
{
if (item.Value == defaultFromLanguage)
{
comboBoxFrom.SelectedIndex = i;
break;
}
i++;
}
var installedLanguages = new List<InputLanguage>();
foreach (InputLanguage language in InputLanguage.InstalledInputLanguages)
{
installedLanguages.Add(language);
}
FillComboWithLanguages(comboBoxTo);
i = 0;
string uiCultureTargetLanguage = Configuration.Settings.Tools.GoogleTranslateLastTargetLanguage;
if (uiCultureTargetLanguage == defaultFromLanguage)
{
foreach (string s in Utilities.GetDictionaryLanguages())
{
string temp = s.Replace("[", string.Empty).Replace("]", string.Empty);
if (temp.Length > 4)
{
temp = temp.Substring(temp.Length - 5, 2).ToLowerInvariant();
if (temp != defaultFromLanguage && installedLanguages.Any(p => p.Culture.TwoLetterISOLanguageName.Contains(temp)))
{
uiCultureTargetLanguage = temp;
break;
}
}
}
}
if (uiCultureTargetLanguage == defaultFromLanguage)
{
foreach (InputLanguage language in installedLanguages)
{
if (language.Culture.TwoLetterISOLanguageName != defaultFromLanguage)
{
uiCultureTargetLanguage = language.Culture.TwoLetterISOLanguageName;
break;
}
}
}
if (uiCultureTargetLanguage == defaultFromLanguage && defaultFromLanguage == "en")
{
uiCultureTargetLanguage = "es";
}
if (uiCultureTargetLanguage == defaultFromLanguage)
{
uiCultureTargetLanguage = "en";
}
comboBoxTo.SelectedIndex = 0;
foreach (ComboBoxItem item in comboBoxTo.Items)
{
if (item.Value == uiCultureTargetLanguage)
{
comboBoxTo.SelectedIndex = i;
break;
}
i++;
}
subtitleListViewFrom.Fill(subtitle);
GoogleTranslate_Resize(null, null);
_formattingTypes = new FormattingType[_subtitle.Paragraphs.Count];
_autoSplit = new bool[_subtitle.Paragraphs.Count];
}
private void Translate(string source, string target, ITranslator translator, int maxTextSize, int maximumRequestArrayLength = 100)
{
buttonOK.Enabled = false;
buttonCancel.Enabled = false;
_breakTranslation = false;
buttonTranslate.Text = Configuration.Settings.Language.General.Cancel;
Cursor.Current = Cursors.WaitCursor;
progressBar1.Maximum = _subtitle.Paragraphs.Count;
progressBar1.Value = 0;
progressBar1.Visible = true;
labelPleaseWait.Visible = true;
var sourceParagraphs = new List<Paragraph>();
try
{
var log = new StringBuilder();
var sourceLength = 0;
var selectedItems = subtitleListViewFrom.SelectedItems;
var startIndex = selectedItems.Count <= 0 ? 0 : selectedItems[0].Index;
var start = startIndex;
int index = startIndex;
for (int i = startIndex; i < _subtitle.Paragraphs.Count; i++)
{
Paragraph p = _subtitle.Paragraphs[i];
sourceLength += Utilities.UrlEncode(p.Text).Length;
if ((sourceLength >= maxTextSize || sourceParagraphs.Count >= maximumRequestArrayLength) && sourceParagraphs.Count > 0)
{
var result = translator.Translate(source, target, sourceParagraphs, log);
FillTranslatedText(result, start, index - 1);
sourceLength = 0;
sourceParagraphs.Clear();
progressBar1.Refresh();
Application.DoEvents();
start = index;
}
sourceParagraphs.Add(p);
index++;
progressBar1.Value = index;
if (_breakTranslation)
{
break;
}
}
if (sourceParagraphs.Count > 0)
{
var result = translator.Translate(source, target, sourceParagraphs, log);
FillTranslatedText(result, start, index - 1);
}
}
catch (WebException webException)
{
if (translator.GetType() == typeof(GoogleTranslator1))
{
MessageBox.Show("Free API quota exceeded?" + Environment.NewLine +
Environment.NewLine +
webException.Source + ": " + webException.Message);
}
else if (translator.GetType() == typeof(GoogleTranslator2) && webException.Message.Contains("(400) Bad Request"))
{
MessageBox.Show("API key invalid (or perhaps billing is not enabled)?" + Environment.NewLine +
Environment.NewLine +
webException.Source + ": " + webException.Message);
}
else if (translator.GetType() == typeof(GoogleTranslator2) && webException.Message.Contains("(403) Forbidden."))
{
MessageBox.Show("Perhaps billing is not enabled (or API key is invalid)?" + Environment.NewLine +
Environment.NewLine +
webException.Source + ": " + webException.Message);
}
else
{
MessageBox.Show(webException.Source + ": " + webException.Message);
}
}
finally
{
labelPleaseWait.Visible = false;
progressBar1.Visible = false;
Cursor.Current = Cursors.Default;
buttonTranslate.Text = Configuration.Settings.Language.GoogleTranslate.Translate;
buttonTranslate.Enabled = true;
buttonOK.Enabled = true;
buttonCancel.Enabled = true;
Configuration.Settings.Tools.GoogleTranslateLastTargetLanguage = _targetTwoLetterIsoLanguageName;
}
}
private void FillTranslatedText(List<string> translatedLines, int start, int end)
{
int index = start;
foreach (string s in translatedLines)
{
if (index < TranslatedSubtitle.Paragraphs.Count)
{
var cleanText = CleanText(s, index);
TranslatedSubtitle.Paragraphs[index].Text = cleanText;
}
index++;
}
subtitleListViewTo.BeginUpdate();
subtitleListViewTo.Fill(TranslatedSubtitle);
subtitleListViewTo.SelectIndexAndEnsureVisible(end);
subtitleListViewTo.EndUpdate();
}
private void buttonTranslate_Click(object sender, EventArgs e)
{
if (buttonTranslate.Text == Configuration.Settings.Language.General.Cancel)
{
buttonTranslate.Enabled = false;
_breakTranslation = true;
buttonOK.Enabled = true;
buttonCancel.Enabled = true;
return;
}
_targetTwoLetterIsoLanguageName = ((ComboBoxItem)comboBoxTo.SelectedItem).Value;
Configuration.Settings.Tools.GoogleTranslateLastTargetLanguage = _targetTwoLetterIsoLanguageName;
var source = ((ComboBoxItem)comboBoxFrom.SelectedItem).Value;
var language = Configuration.Settings.Language.GoogleTranslate;
if (_googleTranslate && string.IsNullOrEmpty(Configuration.Settings.Tools.GoogleApiV2Key))
{
if (Configuration.Settings.Tools.GoogleApiV2KeyInfoShow)
{
using (var form = new DialogDoNotShowAgain("Subtitle Edit", language.GoogleApiKeyNeeded))
{
form.ShowDialog(this);
Configuration.Settings.Tools.GoogleApiV2KeyInfoShow = !form.DoNoDisplayAgain;
}
}
if (Configuration.Settings.Tools.GoogleTranslateNoKeyWarningShow)
{
using (var form = new DialogDoNotShowAgain("Subtitle Edit", language.GoogleNoApiKeyWarning))
{
form.ShowDialog(this);
Configuration.Settings.Tools.GoogleTranslateNoKeyWarningShow = !form.DoNoDisplayAgain;
}
}
labelApiKeyNotFound.Left = linkLabelPoweredByGoogleTranslate.Left + linkLabelPoweredByGoogleTranslate.Width + 20;
labelApiKeyNotFound.Text = language.GoogleNoApiKeyWarning;
Translate(source, _targetTwoLetterIsoLanguageName, new GoogleTranslator1(), Configuration.Settings.Tools.GoogleApiV1ChunkSize);
return;
}
if (!_googleTranslate && string.IsNullOrEmpty(Configuration.Settings.Tools.MicrosoftTranslatorApiKey))
{
MessageBox.Show(language.MsClientSecretNeeded);
return;
}
if (_googleTranslate)
{
Translate(source, _targetTwoLetterIsoLanguageName, new GoogleTranslator2(Configuration.Settings.Tools.GoogleApiV2Key), 1000);
}
else
{
Translate(source, _targetTwoLetterIsoLanguageName, new MicrosoftTranslator(Configuration.Settings.Tools.MicrosoftTranslatorApiKey, Configuration.Settings.Tools.MicrosoftTranslatorTokenEndpoint, Configuration.Settings.Tools.MicrosoftTranslatorCategory), 1000, MicrosoftTranslator.MaximumRequestArrayLength);
}
}
private string CleanText(string s, int index)
{
string cleanText = s.Replace("</p>", string.Empty).Trim();
int indexOfP = cleanText.IndexOf(SplitterString.Trim(), StringComparison.Ordinal);
if (indexOfP >= 0 && indexOfP < 4)
{
cleanText = cleanText.Remove(0, indexOfP);
}
cleanText = cleanText.Replace(SplitterString, string.Empty).Trim();
if (cleanText.Contains('\n') && !cleanText.Contains('\r'))
{
cleanText = cleanText.Replace("\n", Environment.NewLine);
}
cleanText = cleanText.Replace(" ...", "...");
cleanText = cleanText.Replace("<br/>", Environment.NewLine);
cleanText = cleanText.Replace("<br />", Environment.NewLine);
cleanText = cleanText.Replace("< br/>", Environment.NewLine);
cleanText = cleanText.Replace("<br/ >", Environment.NewLine);
cleanText = cleanText.Replace("<br / >", Environment.NewLine);
cleanText = cleanText.Replace("< br />", Environment.NewLine);
cleanText = cleanText.Replace("< br / >", Environment.NewLine);
cleanText = cleanText.Replace("< br/ >", Environment.NewLine);
cleanText = cleanText.Replace(Environment.NewLine + " ", Environment.NewLine);
cleanText = cleanText.Replace(" " + Environment.NewLine, Environment.NewLine);
cleanText = cleanText.Replace("<I>", "<i>");
cleanText = cleanText.Replace("< I>", "<i>");
cleanText = cleanText.Replace("</ i>", "</i>");
cleanText = cleanText.Replace("</ I>", "</i>");
cleanText = cleanText.Replace("</I>", "</i>");
cleanText = cleanText.Replace("< i >", "<i>");
if (cleanText.StartsWith("<i> ", StringComparison.Ordinal))
{
cleanText = cleanText.Remove(3, 1);
}
if (cleanText.EndsWith(" </i>", StringComparison.Ordinal))
{
cleanText = cleanText.Remove(cleanText.Length - 5, 1);
}
cleanText = cleanText.Replace(Environment.NewLine + "<i> ", Environment.NewLine + "<i>");
cleanText = cleanText.Replace(" </i>" + Environment.NewLine, "</i>" + Environment.NewLine);
if (_autoSplit[index])
{
cleanText = Utilities.AutoBreakLine(cleanText);
}
if (Utilities.GetNumberOfLines(cleanText) == 1 && Utilities.GetNumberOfLines(_subtitle.Paragraphs[index].Text) == 2)
{
if (!_autoSplit[index])
{
cleanText = Utilities.AutoBreakLine(cleanText);
}
}
if (_formattingTypes[index] == FormattingType.ItalicTwoLines || _formattingTypes[index] == FormattingType.Italic)
{
cleanText = "<i>" + cleanText + "</i>";
}
return cleanText;
}
public void FillComboWithLanguages(ComboBox comboBox)
{
if (!_googleTranslate)
{
foreach (var bingLanguageCode in _translator.GetTranslationPairs())
{
comboBox.Items.Add(new ComboBoxItem(bingLanguageCode.Name, bingLanguageCode.Code));
}
return;
}
FillComboWithGoogleLanguages(comboBox);
}
public void FillComboWithGoogleLanguages(ComboBox comboBox)
{
var translator = new GoogleTranslator2(Configuration.Settings.Tools.GoogleApiV2Key);
foreach (var pair in translator.GetTranslationPairs())
{
comboBox.Items.Add(new ComboBoxItem(pair.Name, pair.Code));
}
}
private void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
UiUtil.OpenUrl(_googleTranslate ? GoogleTranslateUrl : _translator.GetUrl());
}
private void ButtonOkClick(object sender, EventArgs e)
{
DialogResult = subtitleListViewTo.Items.Count > 0 ? DialogResult.OK : DialogResult.Cancel;
}
private void FormGoogleTranslate_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape && labelPleaseWait.Visible == false)
{
DialogResult = DialogResult.Cancel;
}
else if (e.KeyCode == Keys.Escape && labelPleaseWait.Visible)
{
_breakTranslation = true;
e.SuppressKeyPress = true;
}
else if (e.KeyCode == UiUtil.HelpKeys)
{
UiUtil.ShowHelp("#translation");
}
}
private void GoogleTranslate_Resize(object sender, EventArgs e)
{
int width = (Width / 2) - (subtitleListViewFrom.Left * 3) + 19;
subtitleListViewFrom.Width = width;
subtitleListViewTo.Width = width;
int height = Height - (subtitleListViewFrom.Top + buttonTranslate.Height + 60);
subtitleListViewFrom.Height = height;
subtitleListViewTo.Height = height;
comboBoxFrom.Left = subtitleListViewFrom.Left + (subtitleListViewFrom.Width - comboBoxFrom.Width);
labelFrom.Left = comboBoxFrom.Left - 5 - labelFrom.Width;
subtitleListViewTo.Left = width + (subtitleListViewFrom.Left * 2);
labelTo.Left = subtitleListViewTo.Left;
comboBoxTo.Left = labelTo.Left + labelTo.Width + 5;
buttonTranslate.Left = comboBoxTo.Left + comboBoxTo.Width + 9;
labelPleaseWait.Left = buttonTranslate.Left + buttonTranslate.Width + 9;
progressBar1.Left = labelPleaseWait.Left;
progressBar1.Width = subtitleListViewTo.Width - (progressBar1.Left - subtitleListViewTo.Left);
}
private void SyncListViews(ListView listViewSelected, SubtitleListView listViewOther)
{
if (listViewSelected.SelectedItems.Count > 0)
{
var first = listViewSelected.TopItem.Index;
int index = listViewSelected.SelectedItems[0].Index;
if (index < listViewOther.Items.Count)
{
listViewOther.SelectIndexAndEnsureVisible(index, false);
if (first >= 0)
{
listViewOther.TopItem = listViewOther.Items[first];
}
}
}
}
private void subtitleListViewFrom_DoubleClick(object sender, EventArgs e)
{
SyncListViews(subtitleListViewFrom, subtitleListViewTo);
}
private void subtitleListViewTo_DoubleClick(object sender, EventArgs e)
{
SyncListViews(subtitleListViewTo, subtitleListViewFrom);
}
public string GetFileNameWithTargetLanguage(string oldFileName, string videoFileName, Subtitle oldSubtitle, SubtitleFormat subtitleFormat)
{
if (!string.IsNullOrEmpty(_targetTwoLetterIsoLanguageName))
{
if (!string.IsNullOrEmpty(videoFileName))
{
return Path.GetFileNameWithoutExtension(videoFileName) + "." + _targetTwoLetterIsoLanguageName.ToLowerInvariant() + subtitleFormat.Extension;
}
if (!string.IsNullOrEmpty(oldFileName))
{
var s = Path.GetFileNameWithoutExtension(oldFileName);
if (oldSubtitle != null)
{
var lang = "." + LanguageAutoDetect.AutoDetectGoogleLanguage(oldSubtitle);
if (lang.Length == 3 && s.EndsWith(lang, StringComparison.OrdinalIgnoreCase))
{
s = s.Remove(s.Length - 3);
}
}
return s + "." + _targetTwoLetterIsoLanguageName.ToLowerInvariant() + subtitleFormat.Extension;
}
}
return null;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -248,6 +248,7 @@ namespace Nikse.SubtitleEdit.Forms
this.translatepoweredByMicrosoftToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.translateByGoogleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.translateFromSwedishToDanishToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.translateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.changeLanguageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -2299,7 +2300,9 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemAutoTranslate.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.translatepoweredByMicrosoftToolStripMenuItem,
this.translateByGoogleToolStripMenuItem,
this.translateFromSwedishToDanishToolStripMenuItem});
this.translateFromSwedishToDanishToolStripMenuItem,
this.translateToolStripMenuItem
});
this.toolStripMenuItemAutoTranslate.Name = "toolStripMenuItemAutoTranslate";
this.toolStripMenuItemAutoTranslate.Size = new System.Drawing.Size(94, 20);
this.toolStripMenuItemAutoTranslate.Text = "Auto-translate";
@ -2327,6 +2330,14 @@ namespace Nikse.SubtitleEdit.Forms
this.translateFromSwedishToDanishToolStripMenuItem.Size = new System.Drawing.Size(402, 22);
this.translateFromSwedishToDanishToolStripMenuItem.Text = "Translate from swedish to danish (powered by nikse.dk/mt)...";
this.translateFromSwedishToDanishToolStripMenuItem.Click += new System.EventHandler(this.TranslateFromSwedishToDanishToolStripMenuItemClick);
//
// translateToolStripMenuItem
//
this.translateToolStripMenuItem.Name = "translateToolStripMenuItem";
this.translateToolStripMenuItem.Size = new System.Drawing.Size(402, 22);
this.translateToolStripMenuItem.Text = "Generic Translate";
this.translateToolStripMenuItem.Click += new System.EventHandler(this.TranslateToolStripMenuItemClick);
//
// optionsToolStripMenuItem
//
@ -5353,6 +5364,7 @@ namespace Nikse.SubtitleEdit.Forms
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemAdjustAllTimes;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemAutoTranslate;
private System.Windows.Forms.ToolStripMenuItem translateByGoogleToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem translateToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem translateFromSwedishToDanishToolStripMenuItem;
private System.Windows.Forms.Timer timerStillTyping;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemVideo;

View File

@ -24,6 +24,7 @@ using Nikse.SubtitleEdit.Logic.VideoPlayers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
@ -67,6 +68,7 @@ namespace Nikse.SubtitleEdit.Forms
private string _fileName;
private int _videoAudioTrackNumber = -1;
public int VideoAudioTrackNumber
{
get => _videoAudioTrackNumber;
@ -78,6 +80,7 @@ namespace Nikse.SubtitleEdit.Forms
{
ReloadWaveform(VideoFileName, value);
}
_videoAudioTrackNumber = value;
}
}
@ -248,6 +251,7 @@ namespace Nikse.SubtitleEdit.Forms
numericUpDownDuration.Width += 5;
labelDuration.Left = numericUpDownDuration.Left - 3;
}
var xDiff = timeUpDownStartTime.Top - (labelStartTime.Top + labelStartTime.Height);
if (xDiff < 0) // DPI auto-size fixes: see https://github.com/SubtitleEdit/subtitleedit/issues/3981
{
@ -263,6 +267,7 @@ namespace Nikse.SubtitleEdit.Forms
comboBoxAutoContinue.Top += xDiff;
}
}
labelAutoDuration.Left = labelDuration.Left - (labelAutoDuration.Width - 5);
textBoxListViewText.BackColor = !IsSubtitleLoaded ? SystemColors.ActiveBorder : SystemColors.WindowFrame;
@ -2234,6 +2239,7 @@ namespace Nikse.SubtitleEdit.Forms
{
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, VideoFileName, _subtitleAlternateFileName, Configuration.Settings.General.CurrentVideoOffsetInMs);
}
Configuration.Settings.General.CurrentVideoOffsetInMs = 0;
openFileDialog1.InitialDirectory = file.DirectoryName;
@ -2380,6 +2386,7 @@ namespace Nikse.SubtitleEdit.Forms
{
// ignored
}
if (f.IsMine(list, tempFileName))
{
f.LoadSubtitle(_subtitle, list, fileName);
@ -3098,6 +3105,7 @@ namespace Nikse.SubtitleEdit.Forms
SubtitleListview1.Items[0].Selected = true;
SubtitleListview1.Items[0].Focused = true;
}
textBoxListViewText.BackColor = SystemColors.WindowFrame;
textBoxListViewTextAlternate.BackColor = SystemColors.WindowFrame;
@ -3537,8 +3545,10 @@ namespace Nikse.SubtitleEdit.Forms
lowerFileNameList.Add(file.FileName.ToLowerInvariant());
}
}
UiUtil.FixFonts(dropDownItems[dropDownItems.Count - 1]);
}
reopenToolStripMenuItem.DropDownItems.AddRange(dropDownItems.ToArray());
}
else
@ -3937,7 +3947,7 @@ namespace Nikse.SubtitleEdit.Forms
{
if (MessageBox.Show(_language.NegativeTimeWarning + Environment.NewLine +
string.Format(Configuration.Settings.Language.MultipleReplace.LinesFoundX, string.Join(", ", negativeTimeLines)),
Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
{
return DialogResult.No;
}
@ -3950,9 +3960,9 @@ namespace Nikse.SubtitleEdit.Forms
if (_fileDateTime != fileOnDisk && _fileDateTime != new DateTime())
{
if (MessageBox.Show(string.Format(_language.OverwriteModifiedFile,
_fileName, fileOnDisk.ToShortDateString(), fileOnDisk.ToString("HH:mm:ss"),
Environment.NewLine, _fileDateTime.ToShortDateString(), _fileDateTime.ToString("HH:mm:ss")),
Title + " - " + _language.FileOnDiskModified, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
_fileName, fileOnDisk.ToShortDateString(), fileOnDisk.ToString("HH:mm:ss"),
Environment.NewLine, _fileDateTime.ToShortDateString(), _fileDateTime.ToString("HH:mm:ss")),
Title + " - " + _language.FileOnDiskModified, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
{
return DialogResult.No;
}
@ -4351,6 +4361,7 @@ namespace Nikse.SubtitleEdit.Forms
{
format = new SubRip();
}
var formatType = format.GetType();
if (_oldSubtitleFormat == null)
@ -4772,6 +4783,7 @@ namespace Nikse.SubtitleEdit.Forms
textBoxListViewTextAlternate.Initialize(Configuration.Settings.General.SubtitleTextBoxSyntaxColor);
RefreshSelectedParagraph();
}
textBoxListViewText.BackColor = !IsSubtitleLoaded ? SystemColors.ActiveBorder : SystemColors.WindowFrame;
textBoxListViewTextAlternate.BackColor = !IsSubtitleLoaded ? SystemColors.ActiveBorder : SystemColors.WindowFrame;
@ -5000,6 +5012,7 @@ namespace Nikse.SubtitleEdit.Forms
{
sb.Append(", ");
}
sb.Append((index + 1).ToString(CultureInfo.InvariantCulture));
}
else
@ -6075,8 +6088,10 @@ namespace Nikse.SubtitleEdit.Forms
{
_timerClearStatus.Interval = 1500;
}
_timerClearStatus.Start();
}
ShowSourceLineNumber();
ShowLineInformationListView();
}
@ -7160,6 +7175,7 @@ namespace Nikse.SubtitleEdit.Forms
UndoToIndex(true);
rollBackCount++;
}
SubtitleListview1.EndUpdate();
Cursor.Current = Cursors.Default;
audioVisualizer.Invalidate();
@ -8963,7 +8979,7 @@ namespace Nikse.SubtitleEdit.Forms
if (len <= Configuration.Settings.General.SubtitleLineMaximumLength * Math.Max(numberOfLines, 2) &&
splitLines.Count == 2 && splitLines[0].StartsWith('-') && splitLines[1].StartsWith('-') &&
(splitLines[0].CountCharacters(false, Configuration.Settings.General.IgnoreArabicDiacritics) > Configuration.Settings.General.SubtitleLineMaximumLength ||
splitLines[1].CountCharacters(false, Configuration.Settings.General.IgnoreArabicDiacritics) > Configuration.Settings.General.SubtitleLineMaximumLength))
splitLines[1].CountCharacters(false, Configuration.Settings.General.IgnoreArabicDiacritics) > Configuration.Settings.General.SubtitleLineMaximumLength))
{
if (buttonUnBreak.Visible)
{
@ -9572,6 +9588,7 @@ namespace Nikse.SubtitleEdit.Forms
p.EndTime.TotalMilliseconds = TimeCode.MaxTimeTotalMilliseconds;
RefreshSelectedParagraph();
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainTextBoxSelectionToLower == e.KeyData && textBoxListViewText.SelectionLength > 0) // selection to lowercase
@ -9696,6 +9713,7 @@ namespace Nikse.SubtitleEdit.Forms
SubtitleListview1.SetText(firstIndex, p.Text);
SubtitleListview1.SetText(firstIndex + 1, next.Text);
}
var selectionStart = textBoxListViewText.SelectionStart;
tb.Text = p.Text;
if (selectionStart >= 0)
@ -9740,6 +9758,7 @@ namespace Nikse.SubtitleEdit.Forms
SubtitleListview1.SetText(firstIndex, p.Text);
SubtitleListview1.SetText(firstIndex + 1, next.Text);
}
var selectionStart = textBoxListViewText.SelectionStart;
tb.Text = p.Text;
if (selectionStart >= 0)
@ -10375,6 +10394,7 @@ namespace Nikse.SubtitleEdit.Forms
{
currentParagraph.EndTime.TotalMilliseconds = currentParagraph.EndTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
newParagraph.StartTime.TotalMilliseconds = currentParagraph.EndTime.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
}
@ -10540,6 +10560,7 @@ namespace Nikse.SubtitleEdit.Forms
{
_subtitleListViewIndex = -1;
}
p.Text = text1;
newParagraph.Text = text2;
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
@ -10992,6 +11013,7 @@ namespace Nikse.SubtitleEdit.Forms
{
s = s.Remove(0, 6);
}
return s;
}
@ -11106,6 +11128,7 @@ namespace Nikse.SubtitleEdit.Forms
}
private bool _skipDurationChangedEvent = false;
private void SetDurationInSeconds(double seconds)
{
_durationIsDirty = false;
@ -13002,8 +13025,10 @@ namespace Nikse.SubtitleEdit.Forms
{
OpenVideo(fileName);
}
_converted = true;
}
SetTitle();
Configuration.Settings.Save();
return true;
@ -13669,6 +13694,7 @@ namespace Nikse.SubtitleEdit.Forms
fs.Seek(fs.Position - buffer.Length + 1, SeekOrigin.Begin);
bytesRead = fs.Read(buffer, 0, buffer.Length);
}
header = new SpHeader(buffer);
}
}
@ -13986,6 +14012,7 @@ namespace Nikse.SubtitleEdit.Forms
{
audioVisualizer.FindDataBelowThreshold(Configuration.Settings.VideoControls.WaveformSeeksSilenceMaxVolume, Configuration.Settings.VideoControls.WaveformSeeksSilenceDurationSeconds);
}
e.SuppressKeyPress = true;
}
else if (audioVisualizer.Visible && e.KeyData == _shortcuts.WaveformSearchSilenceBack)
@ -13994,6 +14021,7 @@ namespace Nikse.SubtitleEdit.Forms
{
audioVisualizer.FindDataBelowThresholdBack(Configuration.Settings.VideoControls.WaveformSeeksSilenceMaxVolume, Configuration.Settings.VideoControls.WaveformSeeksSilenceDurationSeconds);
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainInsertAfter == e.KeyData && inListView)
@ -14027,6 +14055,7 @@ namespace Nikse.SubtitleEdit.Forms
{
ToggleDashes();
}
e.SuppressKeyPress = true;
}
else if (!toolStripMenuItemRtlUnicodeControlChars.Visible && _shortcuts.MainEditFixRTLViaUnicodeChars == e.KeyData && inListView)
@ -14450,6 +14479,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.CurrentPosition = p.StartTime.TotalSeconds;
}
}
e.SuppressKeyPress = true;
}
else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.D2)
@ -14462,6 +14492,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.CurrentPosition = p.EndTime.TotalSeconds;
}
}
e.SuppressKeyPress = true;
}
else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.D3)
@ -14476,6 +14507,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.CurrentPosition = p.StartTime.TotalSeconds;
}
}
e.SuppressKeyPress = true;
}
else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.D4)
@ -14490,6 +14522,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.CurrentPosition = p.StartTime.TotalSeconds;
}
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainVideoToggleStartEndCurrent == e.KeyData)
@ -14510,6 +14543,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainVideoPlayCurrent == e.KeyData)
@ -14525,6 +14559,7 @@ namespace Nikse.SubtitleEdit.Forms
_endSeconds = p.EndTime.TotalSeconds;
}
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainVideoGoToStartCurrent == e.KeyData)
@ -14533,6 +14568,7 @@ namespace Nikse.SubtitleEdit.Forms
{
GotoSubPositionAndPause();
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainVideo3000MsLeft == e.KeyData)
@ -14541,6 +14577,7 @@ namespace Nikse.SubtitleEdit.Forms
{
GoBackSeconds(3);
}
e.SuppressKeyPress = true;
}
else if (e.Modifiers == (Keys.Control | Keys.Alt | Keys.Shift) && e.KeyCode == Keys.W) // watermark
@ -14645,6 +14682,7 @@ namespace Nikse.SubtitleEdit.Forms
{
OpenVideo(videoFileName);
}
e.SuppressKeyPress = true;
}
}
@ -14659,6 +14697,7 @@ namespace Nikse.SubtitleEdit.Forms
{
UndockVideoControlsToolStripMenuItemClick(null, null);
}
e.SuppressKeyPress = true;
}
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _shortcuts.MainVideoFoucsSetVideoPosition)
@ -14704,6 +14743,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.Play();
_endSecondsNewPositionTicks = DateTime.UtcNow.Ticks;
}
e.SuppressKeyPress = true;
}
else if (e.KeyData == _shortcuts.Video1FrameRightWithPlay)
@ -14718,6 +14758,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.Play();
_endSecondsNewPositionTicks = DateTime.UtcNow.Ticks;
}
e.SuppressKeyPress = true;
}
else if (mediaPlayer.VideoPlayer != null && e.KeyData == _shortcuts.Video100MsLeft)
@ -14786,6 +14827,7 @@ namespace Nikse.SubtitleEdit.Forms
{
beamer.ShowDialog(this);
}
e.SuppressKeyPress = true;
}
else if (e.KeyData == _shortcuts.MainVideoFullscreen) // fullscreen
@ -15004,6 +15046,7 @@ namespace Nikse.SubtitleEdit.Forms
{
MoveLastWordDown(textBoxListViewText);
}
e.SuppressKeyPress = true;
}
else if (e.KeyData == _shortcuts.MainTextBoxMoveFirstWordFromNextUp)
@ -15016,6 +15059,7 @@ namespace Nikse.SubtitleEdit.Forms
{
MoveFirstWordInNextUp(textBoxListViewText);
}
e.SuppressKeyPress = true;
}
else if (e.KeyData == _shortcuts.MainTextBoxMoveLastWordDownCurrent)
@ -15028,6 +15072,7 @@ namespace Nikse.SubtitleEdit.Forms
{
MoveWordUpDownInCurrent(true, textBoxListViewText);
}
e.SuppressKeyPress = true;
}
else if (e.KeyData == _shortcuts.MainTextBoxMoveFirstWordUpCurrent)
@ -15040,6 +15085,7 @@ namespace Nikse.SubtitleEdit.Forms
{
MoveWordUpDownInCurrent(false, textBoxListViewText);
}
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainAutoCalcCurrentDuration == e.KeyData)
@ -15136,6 +15182,7 @@ namespace Nikse.SubtitleEdit.Forms
{
AudioWaveform_Click(null, null);
}
e.SuppressKeyPress = true;
}
@ -15407,6 +15454,7 @@ namespace Nikse.SubtitleEdit.Forms
e.SuppressKeyPress = true;
RunCustomSearch(Configuration.Settings.VideoControls.CustomSearchUrl5);
}
// put new entries above tabs
}
@ -15526,6 +15574,7 @@ namespace Nikse.SubtitleEdit.Forms
MakeHistoryForUndo(string.Format(_language.BeforeX, Configuration.Settings.Language.Settings.AdjustExtendToNextSubtitle));
historyAdded = true;
}
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
@ -15609,6 +15658,7 @@ namespace Nikse.SubtitleEdit.Forms
MakeHistoryForUndo(string.Format(_language.BeforeX, Configuration.Settings.Language.Settings.AdjustExtendPreviousLineEndToCurrentStart));
historyAdded = true;
}
previous.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
@ -15650,6 +15700,7 @@ namespace Nikse.SubtitleEdit.Forms
MakeHistoryForUndo(string.Format(_language.BeforeX, Configuration.Settings.Language.Settings.AdjustExtendNextLineStartToCurrentEnd));
historyAdded = true;
}
next.StartTime.TotalMilliseconds = p.EndTime.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
@ -15948,10 +15999,12 @@ namespace Nikse.SubtitleEdit.Forms
{
audioVisualizer.StartPositionSeconds = mediaPlayer.CurrentPosition - 0.2;
}
found = true;
break;
}
}
if (!found && _subtitle.Paragraphs.Count > 0 && _subtitle.Paragraphs[_subtitle.Paragraphs.Count - 1].StartTime.TotalMilliseconds < currentPosition)
{
var p = _subtitle.Paragraphs[_subtitle.Paragraphs.Count - 1];
@ -16002,6 +16055,7 @@ namespace Nikse.SubtitleEdit.Forms
{
add = highPercent - lowPercent - 0.3;
}
for (var startVolume = lowPercent + add; startVolume < 14; startVolume += 0.3)
{
var pos = audioVisualizer.FindDataBelowThresholdBackForStart(startVolume, silenceLengthInSeconds, p.StartTime.TotalSeconds);
@ -16320,6 +16374,7 @@ namespace Nikse.SubtitleEdit.Forms
{
SubtitleListview1.SetText(firstIndex, p.Text);
}
tb.Text = p.Text;
// keep cursor position
@ -16477,6 +16532,7 @@ namespace Nikse.SubtitleEdit.Forms
original.EndTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
}
}
SubtitleListview1.SetStartTimeAndDuration(i - 1, prev, p, _subtitle.GetParagraphOrDefault(i - 2));
}
@ -16583,6 +16639,7 @@ namespace Nikse.SubtitleEdit.Forms
original.StartTime.TotalMilliseconds = next.StartTime.TotalMilliseconds;
}
}
SubtitleListview1.SetStartTimeAndDuration(i + 1, next, _subtitle.GetParagraphOrDefault(i + 2), p);
}
@ -17484,6 +17541,7 @@ namespace Nikse.SubtitleEdit.Forms
{
SubtitleListview1.Items[selectedIndex].Selected = true;
}
RestartHistory();
}
}
@ -17505,6 +17563,7 @@ namespace Nikse.SubtitleEdit.Forms
InsertAfter(s);
}
}
SubtitleListview1.EndUpdate();
RestartHistory();
}
@ -17596,6 +17655,7 @@ namespace Nikse.SubtitleEdit.Forms
{
indices.Add(item.Index);
}
foreach (int i in indices)
{
if (_subtitleAlternate != null && Configuration.Settings.General.AllowEditOfOriginalSubtitle && SubtitleListview1.IsAlternateTextColumnVisible)
@ -17607,6 +17667,7 @@ namespace Nikse.SubtitleEdit.Forms
original.EndTime.TotalMilliseconds = TimeCode.MaxTimeTotalMilliseconds;
}
}
_subtitle.Paragraphs[i].StartTime.TotalMilliseconds = TimeCode.MaxTimeTotalMilliseconds;
_subtitle.Paragraphs[i].EndTime.TotalMilliseconds = TimeCode.MaxTimeTotalMilliseconds;
}
@ -18400,6 +18461,7 @@ namespace Nikse.SubtitleEdit.Forms
{
_subtitle.Paragraphs.Add(p);
}
ShowStatus(_language.PointSynchronizationDone);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
@ -18555,6 +18617,7 @@ namespace Nikse.SubtitleEdit.Forms
{
_subtitle.Paragraphs.Add(p);
}
ShowStatus(_language.PointSynchronizationDone);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
@ -18715,6 +18778,7 @@ namespace Nikse.SubtitleEdit.Forms
{
SubtitleListview1.SelectIndexAndEnsureVisible(0, true);
}
RefreshSelectedParagraph();
}
}
@ -19138,7 +19202,7 @@ namespace Nikse.SubtitleEdit.Forms
_subtitleAlternate != null &&
_subtitleAlternate.Paragraphs.Count > 0;
var originalChanged = originalActive &&
_changeAlternateSubtitleHash != _subtitleAlternate.GetFastHashCode(GetCurrentEncoding().BodyName);
_changeAlternateSubtitleHash != _subtitleAlternate.GetFastHashCode(GetCurrentEncoding().BodyName);
if (currentChanged || originalChanged)
{
AddTitleBarChangeAsterisk(currentChanged, originalChanged, originalActive);
@ -19172,6 +19236,7 @@ namespace Nikse.SubtitleEdit.Forms
s = s.Substring(0, s.Length - length).TrimEnd(' ', '*', '-') + "* - " + Title;
}
}
if (currentChanged)
{
s = s.Replace(" + ", "* + ");
@ -21320,10 +21385,12 @@ namespace Nikse.SubtitleEdit.Forms
MessageBox.Show(string.Format(_language.ErrorLoadingPluginXErrorY, pluginFileName, exception.Message));
}
}
foreach (var fileMenuItem in fileMenuItems)
{
fileToolStripMenuItem.DropDownItems.Insert(fileToolStripMenuItem.DropDownItems.Count - 2, fileMenuItem);
}
toolsToolStripMenuItem.DropDownItems.AddRange(toolsMenuItems.OrderBy(p => p.Text).ToArray());
toolStripMenuItemAutoTranslate.DropDownItems.AddRange(translateMenuItems.OrderBy(p => p.Text).ToArray());
toolStripMenuItemTranslateSelected.DropDownItems.AddRange(translateSelectedLinesMenuItems.OrderBy(p => p.Text).ToArray());
@ -21848,7 +21915,7 @@ namespace Nikse.SubtitleEdit.Forms
if (audioVisualizer.WavePeaks == null)
{
if (VideoFileName != null && (VideoFileName.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
VideoFileName.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
VideoFileName.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
{
return;
}
@ -22545,6 +22612,7 @@ namespace Nikse.SubtitleEdit.Forms
numberOfNewLines++;
}
}
int selectedLineIdx = numberOfNewLines; // Do not use 'GetLineFromCharIndex' as it also counts when lines are wrapped
// Get line from index.
@ -22651,6 +22719,7 @@ namespace Nikse.SubtitleEdit.Forms
text = tb.Text;
tb.SelectAll();
}
int selectionStart = tb.SelectionStart;
string color;
@ -22752,6 +22821,7 @@ namespace Nikse.SubtitleEdit.Forms
text = tb.Text;
tb.SelectAll();
}
int selectionStart = tb.SelectionStart;
using (var form = new ChooseFontName())
@ -25735,6 +25805,7 @@ namespace Nikse.SubtitleEdit.Forms
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
RestoreSubtitleListviewIndices();
}
ShowSource();
}
}
@ -26888,6 +26959,7 @@ namespace Nikse.SubtitleEdit.Forms
{
_subtitle.Paragraphs[index + i].Text = tmp.Paragraphs[i].Text;
}
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
RefreshSelectedParagraph();
@ -27495,6 +27567,7 @@ namespace Nikse.SubtitleEdit.Forms
p.Text = s + " " + p.Text;
SubtitleListview1.SetText(item.Index, p.Text);
}
RefreshSelectedParagraph();
}
else
@ -27879,6 +27952,7 @@ namespace Nikse.SubtitleEdit.Forms
{
_subtitleAlternate.InsertParagraphInCorrectTimeOrder(new Paragraph(newParagraph));
}
_subtitleAlternate.Renumber();
}
@ -28408,6 +28482,7 @@ namespace Nikse.SubtitleEdit.Forms
{
MakeHistoryForUndo(historyMessage);
}
if (newText.IsOnlyControlCharactersOrWhiteSpace())
{
_subtitle.Paragraphs.RemoveAt(idx);
@ -28416,6 +28491,7 @@ namespace Nikse.SubtitleEdit.Forms
{
p.Text = newText;
}
linesUpdated++;
}
@ -28431,6 +28507,7 @@ namespace Nikse.SubtitleEdit.Forms
{
MakeHistoryForUndo(historyMessage);
}
if (newText.IsOnlyControlCharactersOrWhiteSpace())
{
_subtitleAlternate.Paragraphs.RemoveAt(idx);
@ -28439,6 +28516,7 @@ namespace Nikse.SubtitleEdit.Forms
{
original.Text = newText;
}
linesUpdated++;
}
}
@ -28669,7 +28747,8 @@ namespace Nikse.SubtitleEdit.Forms
{
rubyText = "<ruby-text>" + rubyText + "</ruby-text>";
}
var rubyHtml = before + "<ruby-container><ruby-base>" + form.RubyBaseText + "</ruby-base>" + rubyText + "</ruby-container>" + after; // sami ruby tag fix
var rubyHtml = before + "<ruby-container><ruby-base>" + form.RubyBaseText + "</ruby-base>" + rubyText + "</ruby-container>" + after; // sami ruby tag fix
var formatType = GetCurrentSubtitleFormat().GetType();
if (formatType == typeof(Sami)) // sami ruby tag fix
{
@ -28682,6 +28761,7 @@ namespace Nikse.SubtitleEdit.Forms
.Replace("<ruby-text-italic>", string.Empty)
.Replace("</ruby-text-italic>", string.Empty);
}
tb.Text = rubyHtml;
}
}
@ -28861,6 +28941,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.VideoPlayer = libMpv;
mediaPlayer.SubtitleText = string.Empty;
}
libMpv.LoadSubtitle(openFileDialog1.FileName);
}
else if (mediaPlayer.VideoPlayer is LibVlcDynamic libvlc)
@ -28912,5 +28993,136 @@ namespace Nikse.SubtitleEdit.Forms
{
splitContainerListViewAndText_SplitterMoved(null, null);
}
private void TranslateToolStripMenuItemClick(object sender, EventArgs e)
{
Debug.WriteLine("clicked");
var useGoogle = true;
var onlySelectedLines = false;
if (!IsSubtitleLoaded)
{
DisplaySubtitleNotLoadedMessage();
return;
}
bool isAlternateVisible = SubtitleListview1.IsAlternateTextColumnVisible;
ReloadFromSourceView();
using (var googleTranslate = new GenericTranslate())
{
SaveSubtitleListviewIndices();
string title = _language.GoogleTranslate;
if (!useGoogle)
{
title = _language.MicrosoftTranslate;
}
if (onlySelectedLines)
{
var selectedLines = new Subtitle();
foreach (int index in SubtitleListview1.SelectedIndices)
{
selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]);
}
title += " - " + _language.SelectedLines;
if (_subtitleAlternate != null)
{
var paragraphs = new List<Paragraph>();
foreach (int index in SubtitleListview1.SelectedIndices)
{
var original = Utilities.GetOriginalParagraph(index, _subtitle.Paragraphs[index], _subtitleAlternate.Paragraphs);
if (original != null)
{
paragraphs.Add(original);
}
}
if (paragraphs.Count == selectedLines.Paragraphs.Count)
{
googleTranslate.Initialize(new Subtitle(paragraphs), selectedLines, title, useGoogle, GetCurrentEncoding());
}
else
{
googleTranslate.Initialize(selectedLines, null, title, useGoogle, GetCurrentEncoding());
}
}
else
{
googleTranslate.Initialize(selectedLines, null, title, useGoogle, GetCurrentEncoding());
}
}
else
{
googleTranslate.Initialize(_subtitle, null, title, useGoogle, GetCurrentEncoding());
}
if (googleTranslate.ShowDialog(this) == DialogResult.OK)
{
_subtitleListViewIndex = -1;
string oldFileName = _fileName;
MakeHistoryForUndo(_language.BeforeGoogleTranslation);
if (onlySelectedLines)
{
// we only update selected lines
int i = 0;
foreach (int index in SubtitleListview1.SelectedIndices)
{
_subtitle.Paragraphs[index] = googleTranslate.TranslatedSubtitle.Paragraphs[i];
i++;
}
ShowStatus(_language.SelectedLinesTranslated);
}
else
{
ShowSubtitleTimer.Stop();
var oldHash = _changeSubtitleHash;
_subtitleAlternate = new Subtitle(_subtitle);
_subtitleAlternateFileName = _fileName;
_fileName = null;
_subtitle.Paragraphs.Clear();
foreach (var p in googleTranslate.TranslatedSubtitle.Paragraphs)
{
_subtitle.Paragraphs.Add(new Paragraph(p));
}
ShowStatus(_language.SubtitleTranslated);
_changeAlternateSubtitleHash = oldHash;
_changeSubtitleHash = -1;
ShowSubtitleTimer.Start();
}
ShowSource();
if (!onlySelectedLines)
{
SubtitleListview1.ShowAlternateTextColumn(_languageGeneral.OriginalText);
SubtitleListview1.AutoSizeAllColumns(this);
var oldHash = _changeAlternateSubtitleHash;
SetupAlternateEdit();
_changeAlternateSubtitleHash = oldHash;
}
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
if (!onlySelectedLines)
{
ResetHistory();
_fileName = googleTranslate.GetFileNameWithTargetLanguage(oldFileName, VideoFileName, _subtitleAlternate, GetCurrentSubtitleFormat());
}
RestoreSubtitleListviewIndices();
_converted = true;
SetTitle();
SetEncoding(Encoding.UTF8);
if (!isAlternateVisible)
{
toolStripMenuItemShowOriginalInPreview.Checked = false;
Configuration.Settings.General.ShowOriginalAsPreviewIfAvailable = false;
audioVisualizer.Invalidate();
}
}
}
}
}
}
}

View File

@ -229,6 +229,12 @@
<Compile Include="Forms\ExportPngXmlDialogOpenFolder.Designer.cs">
<DependentUpon>ExportPngXmlDialogOpenFolder.cs</DependentUpon>
</Compile>
<Compile Include="Forms\GenericTranslate.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\GenericTranslate.Designer.cs">
<DependentUpon>GenericTranslate.cs</DependentUpon>
</Compile>
<Compile Include="Forms\ImportCdg.cs">
<SubType>Form</SubType>
</Compile>
@ -1206,6 +1212,10 @@
<EmbeddedResource Include="Forms\ExportPngXmlDialogOpenFolder.resx">
<DependentUpon>ExportPngXmlDialogOpenFolder.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\GenericTranslate.resx">
<DependentUpon>GenericTranslate.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Forms\ImportCdg.resx">
<DependentUpon>ImportCdg.cs</DependentUpon>
</EmbeddedResource>