Merge remote-tracking branch 'refs/remotes/Kwoth/master' into dev
This commit is contained in:
commit
f6b25dffb7
@ -75,6 +75,7 @@ namespace NadekoBot.Modules.Translator.Helpers
|
||||
this.TranslationTime = TimeSpan.Zero;
|
||||
DateTime tmStart = DateTime.Now;
|
||||
string translation = string.Empty;
|
||||
string text = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
@ -83,19 +84,15 @@ namespace NadekoBot.Modules.Translator.Helpers
|
||||
GoogleTranslator.LanguageEnumToIdentifier(sourceLanguage),
|
||||
GoogleTranslator.LanguageEnumToIdentifier(targetLanguage),
|
||||
HttpUtility.UrlEncode(sourceText));
|
||||
string outputFile = Path.GetTempFileName();
|
||||
using (WebClient wc = new WebClient())
|
||||
{
|
||||
wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
|
||||
wc.DownloadFile(url, outputFile);
|
||||
text = wc.DownloadString(url);
|
||||
}
|
||||
|
||||
// Get translated text
|
||||
if (File.Exists(outputFile))
|
||||
{
|
||||
|
||||
// Get phrase collection
|
||||
string text = File.ReadAllText(outputFile);
|
||||
// string text = File.ReadAllText(outputFile);
|
||||
int index = text.IndexOf(string.Format(",,\"{0}\"", GoogleTranslator.LanguageEnumToIdentifier(sourceLanguage)));
|
||||
if (index == -1)
|
||||
{
|
||||
@ -144,7 +141,6 @@ namespace NadekoBot.Modules.Translator.Helpers
|
||||
this.TranslationSpeechUrl = string.Format("https://translate.googleapis.com/translate_tts?ie=UTF-8&q={0}&tl={1}&total=1&idx=0&textlen={2}&client=gtx",
|
||||
HttpUtility.UrlEncode(translation), GoogleTranslator.LanguageEnumToIdentifier(targetLanguage), translation.Length);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Error = ex;
|
||||
|
Loading…
Reference in New Issue
Block a user