-
Notifications
You must be signed in to change notification settings - Fork 44
/
Plugin.cs
56 lines (45 loc) · 1.95 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using SubtitleEdit;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.PluginLogic
{
public class DeeplProTranslate : IPlugin // dll file name must "<classname>.dll" - e.g. "Haxor.dll"
{
string IPlugin.Name => "DeepL Pro Translate";
string IPlugin.Text => "Translate with DeepL.com Pro";
decimal IPlugin.Version => 1.7M;
string IPlugin.Description => "Translate subtitle with DeepL.com API (free or Pro)";
string IPlugin.ActionType => "translate"; // Can be one of these: file, tool, sync, translate, spellcheck
string IPlugin.Shortcut => string.Empty;
string IPlugin.DoAction(Form parentForm, string subtitle, double frameRate, string listViewLineSeparatorString, string subtitleFileName, string videoFileName, string rawText)
{
subtitle = subtitle.Trim();
if (string.IsNullOrEmpty(subtitle))
{
MessageBox.Show("No subtitle loaded", parentForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return string.Empty;
}
if (!string.IsNullOrEmpty(listViewLineSeparatorString))
{
Configuration.ListViewLineSeparatorString = listViewLineSeparatorString;
}
var list = new List<string>();
foreach (var line in subtitle.Replace(Environment.NewLine, "\n").Split('\n'))
{
list.Add(line);
}
var sub = new Subtitle();
var srt = new SubRip();
srt.LoadSubtitle(sub, list, subtitleFileName);
using (var form = new MainForm(sub, (this as IPlugin).Text, (this as IPlugin).Description, parentForm))
{
if (form.ShowDialog(parentForm) == DialogResult.OK)
{
return form.FixedSubtitle;
}
}
return string.Empty;
}
}
}