private void Translate() { Cursor = Cursors.WaitCursor; try { string from = ((GoogleTranslate.ComboBoxItem)comboBoxFrom.SelectedItem).Value; string to = ((GoogleTranslate.ComboBoxItem)comboBoxTo.SelectedItem).Value; buttonGoogle.Text = string.Empty; // google translate buttonGoogle.Text = new GoogleTranslator1().Translate(from, to, new List <Paragraph> { new Paragraph { Text = textBoxSourceText.Text } }, new StringBuilder()).FirstOrDefault(); // ms translator if (!string.IsNullOrEmpty(Configuration.Settings.Tools.MicrosoftTranslatorApiKey) && !string.IsNullOrEmpty(Configuration.Settings.Tools.MicrosoftTranslatorTokenEndpoint)) { var translator = new MicrosoftTranslator(Configuration.Settings.Tools.MicrosoftTranslatorApiKey, Configuration.Settings.Tools.MicrosoftTranslatorTokenEndpoint, Configuration.Settings.Tools.MicrosoftTranslatorCategory); var result = translator.Translate(from, to, new List <Paragraph> { new Paragraph { Text = textBoxSourceText.Text } }, new StringBuilder()); buttonMicrosoft.Text = result[0]; } } finally { Cursor = Cursors.Default; } }
public void Execute(IUBotStudio ubotStudio, Dictionary <string, string> parameters) { var clientId = parameters["Client Id"].Trim(); var clientSecret = parameters["Client Secret"].Trim(); var text = parameters["Text"]; var originalLanguage = parameters["Original Language"]; var destinationLanguage = parameters["Destination Language"]; MicrosoftTranslator microsoftTranslator = new MicrosoftTranslator(clientId, clientSecret); _returnValue = microsoftTranslator.Translate(text, originalLanguage, destinationLanguage); }
private void Translate() { Cursor = Cursors.WaitCursor; try { string from = (comboBoxFrom.SelectedItem as GoogleTranslate.ComboBoxItem).Value; string to = (comboBoxTo.SelectedItem as GoogleTranslate.ComboBoxItem).Value; string languagePair = from + "|" + to; buttonGoogle.Text = string.Empty; // google translate bool romanji = languagePair.EndsWith("|romanji", StringComparison.InvariantCulture); if (romanji) { languagePair = from + "|ja"; } var screenScrapingEncoding = GoogleTranslate.GetScreenScrapingEncoding(languagePair); buttonGoogle.Text = GoogleTranslate.TranslateTextViaScreenScraping(textBoxSourceText.Text, languagePair, screenScrapingEncoding, romanji); // ms translator if (!string.IsNullOrEmpty(Configuration.Settings.Tools.MicrosoftTranslatorApiKey)) { var translator = new MicrosoftTranslator(Configuration.Settings.Tools.MicrosoftTranslatorApiKey); var result = translator.Translate(from, to, new List <string> { textBoxSourceText.Text }, new StringBuilder()); buttonMicrosoft.Text = result[0]; } else { using (var gt = new GoogleTranslate()) { var subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph(0, 0, textBoxSourceText.Text)); gt.Initialize(subtitle, string.Empty, false, Encoding.UTF8); from = FixMsLocale(from); to = FixMsLocale(to); gt.DoMicrosoftTranslate(from, to); buttonMicrosoft.Text = gt.TranslatedSubtitle.Paragraphs[0].Text; } } } finally { Cursor = Cursors.Default; } }
private void Translate() { Cursor = Cursors.WaitCursor; try { string from = ((GoogleTranslate.ComboBoxItem)comboBoxFrom.SelectedItem).Value; string to = ((GoogleTranslate.ComboBoxItem)comboBoxTo.SelectedItem).Value; buttonGoogle.Text = string.Empty; // google translate buttonGoogle.Text = new GoogleTranslator1().Translate(from, to, new List <Paragraph> { new Paragraph { Text = textBoxSourceText.Text } }, new StringBuilder()).FirstOrDefault(); // ms translator if (!string.IsNullOrEmpty(Configuration.Settings.Tools.MicrosoftTranslatorApiKey)) { var translator = new MicrosoftTranslator(Configuration.Settings.Tools.MicrosoftTranslatorApiKey); var result = translator.Translate(from, to, new List <Paragraph> { new Paragraph { Text = textBoxSourceText.Text } }, new StringBuilder()); buttonMicrosoft.Text = result[0]; } else { using (var gt = new GoogleTranslate()) { var subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph(0, 0, textBoxSourceText.Text)); gt.Initialize(subtitle, string.Empty, false, Encoding.UTF8); from = FixMsLocale(from); to = FixMsLocale(to); gt.DoMicrosoftTranslate(from, to); buttonMicrosoft.Text = gt.TranslatedSubtitle.Paragraphs[0].Text; } } } finally { Cursor = Cursors.Default; } }