Skip to content

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
studyzy committed Oct 23, 2017
1 parent 712cb6f commit 7f720ef
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 508 deletions.
957 changes: 478 additions & 479 deletions LearnEnglishBySubtitle/Forms/AboutBox.resx

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions LearnEnglishBySubtitle/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions LearnEnglishBySubtitle/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,22 +520,22 @@ private void ToolStripMenuItemAbount_Click(object sender, EventArgs e)

private void ToolStripMenuItemDonate_Click(object sender, EventArgs e)
{
//Process.Start("http://imewlconverter.googlecode.com/svn/wiki/donate.html");

DonationForm donation=new DonationForm();
donation.Show();
donation.Activate();
}

private void ToolStripMenuItemLastVersion_Click(object sender, EventArgs e)
{
Process.Start("https://sourceforge.net/projects/learnenglishbysubtitle/files/");
Process.Start("https://github.com/studyzy/LearnEnglishBySubtitle/releases");
}



private void ToolStripMenuItemHelp_Click(object sender, EventArgs e)
{
Process.Start("https://code.google.com/p/learn-english-by-subtitle");
Process.Start("https://github.com/studyzy/LearnEnglishBySubtitle/wiki");
}


Expand Down Expand Up @@ -615,7 +615,15 @@ private void SentenceTranslateToolStripMenuItem_Click(object sender, EventArgs e
if (cell.ColumnIndex == 2)//只对字幕句子进行翻译
{
var sentence = cell.Value.ToString();
cell.Value = sentence+"\r\n"+ translateService.TranslateToChinese(sentence);
try
{
cell.Value = sentence + "\r\n" + translateService.TranslateToChinese(sentence);
}
catch (Exception ex)
{

MessageBox.Show("整句翻译服务调用失败,请尝试其他服务");
}
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions LearnEnglishBySubtitle/Forms/PronunciationForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions LearnEnglishBySubtitle/LearnEnglishBySubtitle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.105.2, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.105.2\lib\net40\System.Data.SQLite.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion LearnEnglishBySubtitle/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("studyzy")]
[assembly: AssemblyProduct("深蓝英文字幕助手")]
[assembly: AssemblyCopyright("Copyright © studyzy 2014")]
[assembly: AssemblyCopyright("Copyright © studyzy 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "config", Watch = true)]
Expand Down
53 changes: 48 additions & 5 deletions LearnEnglishBySubtitle/TranslateServices/BaiduTranslateService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
Expand All @@ -10,13 +11,55 @@ class BaiduTranslateService:TranslateService
{
public override string TranslateToChinese(string englishSentence)
{
string url =
"http://openapi.baidu.com/public/2.0/bmt/translate?client_id=jiNe8qrbuOznKxZPk0DEHrE4&from=en&to=zh&q=" +
HttpUtility.UrlEncode( englishSentence);
string appid = ConfigurationManager.AppSettings["Baidu.AppId"];
if (string.IsNullOrEmpty(appid))
{
appid = "20171023000090334";
}
string privKey = ConfigurationManager.AppSettings["Baidu.PrivateKey"];
if (string.IsNullOrEmpty(privKey))
{
privKey = "86OHi2BPw5Zd52a79o3Q";
}
var salt = "888";
var sign = CreateMD5( appid + englishSentence + salt + privKey);
string url =
"http://api.fanyi.baidu.com/api/trans/vip/translate?q=" + HttpUtility.UrlEncode(englishSentence) + "&from=en&to=zh&appid="+appid+"&salt="+salt+"&sign=" +sign
;
string html = GetHtml(url);
var doc = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(html, "baidu-fanyi");
var txt = doc.SelectSingleNode("baidu-fanyi/trans_result/dst").InnerText;
var doc = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseResult>(html);
var txt = doc.trans_result[0].dst;
return txt;
}
private string CreateMD5(string input)
{
// Use input string to calculate MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);

// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString().ToLower();
}
}
}

public class ResponseResult
{
public string from { get; set; }
public string to { get; set; }
public TransResult[] trans_result { get; set; }
}

public class TransResult
{
public string src { get; set; }
public string dst { get; set; }
}
}
5 changes: 5 additions & 0 deletions LearnEnglishBySubtitle/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<appSettings>
<!--请在该网站申请百度翻译服务,并填写分配的值 https://fanyi.baidu.com/ -->
<add key="Baidu.AppId" value=""/>
<add key="Baidu.PrivateKey" value=""/>
</appSettings>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
Expand Down

0 comments on commit 7f720ef

Please sign in to comment.