public GoogleOrMicrosoftTranslate() { UiUtil.PreInitialize(this); InitializeComponent(); UiUtil.FixFonts(this); using (var gt = new GoogleTranslate()) { gt.FillComboWithGoogleLanguages(comboBoxFrom); gt.FillComboWithGoogleLanguages(comboBoxTo); } RemovedLanguagesNotInMicrosoftTranslate(comboBoxFrom); RemovedLanguagesNotInMicrosoftTranslate(comboBoxTo); Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.Title; labelGoogleTranslate.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.GoogleTranslate; labelMicrosoftTranslate.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.MicrosoftTranslate; labelFrom.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.From; labelTo.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.To; labelSourceText.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.SourceText; buttonGoogle.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.GoogleTranslate; buttonMicrosoft.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.MicrosoftTranslate; buttonTranslate.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.Translate; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; UiUtil.FixLargeFonts(this, buttonCancel); buttonGoogle.Text = string.Empty; buttonMicrosoft.Text = string.Empty; }
public GoogleOrMicrosoftTranslate() { InitializeComponent(); using (var gt = new GoogleTranslate()) { gt.FillComboWithGoogleLanguages(comboBoxFrom); gt.FillComboWithGoogleLanguages(comboBoxTo); } RemovedLanguagesNotInMicrosoftTranslate(comboBoxFrom); RemovedLanguagesNotInMicrosoftTranslate(comboBoxTo); Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.Title; labelGoogleTranslate.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.GoogleTranslate; labelMicrosoftTranslate.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.MicrosoftTranslate; labelFrom.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.From; labelTo.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.To; labelSourceText.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.SourceText; buttonGoogle.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.GoogleTranslate; buttonMicrosoft.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.MicrosoftTranslate; buttonTranslate.Text = Configuration.Settings.Language.GoogleOrMicrosoftTranslate.Translate; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; UiUtil.FixLargeFonts(this, buttonCancel); buttonGoogle.Text = string.Empty; buttonMicrosoft.Text = string.Empty; }
private void Translate() { Cursor = Cursors.WaitCursor; try { string from = (comboBoxFrom.SelectedItem as Nikse.SubtitleEdit.Forms.GoogleTranslate.ComboBoxItem).Value; string to = (comboBoxTo.SelectedItem as Nikse.SubtitleEdit.Forms.GoogleTranslate.ComboBoxItem).Value; string languagePair = from + "|" + to; buttonGoogle.Text = string.Empty; buttonGoogle.Text = Forms.GoogleTranslate.TranslateTextViaApi(textBoxSourceText.Text, languagePair); using (var gt = new GoogleTranslate()) { Subtitle subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph(0, 0, textBoxSourceText.Text)); gt.Initialize(subtitle, string.Empty, false, System.Text.Encoding.UTF8); from = FixMsLocale(from); to = FixMsLocale(to); gt.DoMicrosoftTranslate(from, to); buttonMicrosoft.Text = gt.TranslatedSubtitle.Paragraphs[0].Text; } } finally { Cursor = Cursors.Default; } }
public SyncPointsSync() { InitializeComponent(); buttonSetSyncPoint.Text = Configuration.Settings.Language.PointSync.SetSyncPoint; buttonRemoveSyncPoint.Text = Configuration.Settings.Language.PointSync.RemoveSyncPoint; buttonOK.Text = Configuration.Settings.Language.General.Ok; buttonApplySync.Text = Configuration.Settings.Language.PointSync.ApplySync; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; labelNoOfSyncPoints.Text = string.Format(Configuration.Settings.Language.PointSync.SyncPointsX, 0); labelSyncInfo.Text = Configuration.Settings.Language.PointSync.Info; buttonFindText.Text = Configuration.Settings.Language.VisualSync.FindText; buttonFindTextOther.Text = Configuration.Settings.Language.VisualSync.FindText; SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings); subtitleListView2.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings); SubtitleListview1.InitializeTimestampColumnWidths(this); subtitleListView2.InitializeTimestampColumnWidths(this); UiUtil.InitializeSubtitleFont(SubtitleListview1); UiUtil.InitializeSubtitleFont(subtitleListView2); SubtitleListview1.AutoSizeAllColumns(this); subtitleListView2.AutoSizeAllColumns(this); UiUtil.FixLargeFonts(this, buttonOK); labelAdjustFactor.Text = string.Empty; GoogleTranslate gt = new GoogleTranslate(); gt.FillComboWithGoogleLanguages(comboBoxOtherSubLanguage); gt.FillComboWithGoogleLanguages(comboBoxSubToSyncLanguage); comboBoxOtherSubLanguage.SelectedItem = comboBoxOtherSubLanguage.Items[19]; comboBoxSubToSyncLanguage.SelectedItem = comboBoxSubToSyncLanguage.Items[18]; }
private Subtitle TranslateSub(Subtitle subtitleToTranslate, string languagePair) { Subtitle otherTranslated = new Subtitle(subtitleToTranslate, true); Parallel.For(0, otherTranslated.Paragraphs.Count, i => { otherTranslated.Paragraphs[i].Text = GoogleTranslate.TranslateTextViaScreenScraping(subtitleToTranslate.Paragraphs[i].Text, languagePair, Encoding.Default, false); }); return(otherTranslated); }
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; } }
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); using (var gt = new GoogleTranslate()) { Subtitle subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph(0, 0, textBoxSourceText.Text)); gt.Initialize(subtitle, string.Empty, false, System.Text.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 TranslateViaGoogle(bool onlySelectedLines, bool useGoogle) { if (!IsSubtitleLoaded) { DisplaySubtitleNotLoadedMessage(); return; } bool isAlternateVisible = SubtitleListview1.IsAlternateTextColumnVisible; ReloadFromSourceView(); using (var googleTranslate = new GoogleTranslate()) { SaveSubtitleListviewIndices(); string title = _language.GoogleTranslate; if (!useGoogle) title = _language.MicrosoftTranslate; if (onlySelectedLines) { var selectedLines = new Subtitle { WasLoadedWithFrameNumbers = _subtitle.WasLoadedWithFrameNumbers }; foreach (int index in SubtitleListview1.SelectedIndices) selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]); title += " - " + _language.SelectedLines; googleTranslate.Initialize(selectedLines, title, useGoogle, GetCurrentEncoding()); } else { googleTranslate.Initialize(_subtitle, title, useGoogle, GetCurrentEncoding()); } if (googleTranslate.ShowDialog(this) == DialogResult.OK) { _subtitleListViewIndex = -1; 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 { _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); } ShowSource(); if (!onlySelectedLines) { SubtitleListview1.ShowAlternateTextColumn(_languageGeneral.OriginalText); SubtitleListview1.AutoSizeAllColumns(this); SetupAlternateEdit(); } SubtitleListview1.Fill(_subtitle, _subtitleAlternate); ResetHistory(); RestoreSubtitleListviewIndices(); _converted = true; SetTitle(); //if (googleTranslate.ScreenScrapingEncoding != null) // SetEncoding(googleTranslate.ScreenScrapingEncoding); SetEncoding(Encoding.UTF8); if (!isAlternateVisible) { toolStripMenuItemShowOriginalInPreview.Checked = false; Configuration.Settings.General.ShowOriginalAsPreviewIfAvailable = false; audioVisualizer.Invalidate(); } } } }
private void TranslateViaGoogle(bool onlySelectedLines, bool useGoogle) { if (IsSubtitleLoaded) { ReloadFromSourceView(); var googleTranslate = new GoogleTranslate(); _formPositionsAndSizes.SetPositionAndSize(googleTranslate); SaveSubtitleListviewIndexes(); string title = _language.GoogleTranslate; if (!useGoogle) title = _language.MicrosoftTranslate; if (onlySelectedLines) { var selectedLines = new Subtitle { WasLoadedWithFrameNumbers = _subtitle.WasLoadedWithFrameNumbers }; foreach (int index in SubtitleListview1.SelectedIndices) selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]); title += " - " + _language.SelectedLines; googleTranslate.Initialize(selectedLines, title, useGoogle, GetCurrentEncoding()); } else { googleTranslate.Initialize(_subtitle, title, useGoogle, GetCurrentEncoding()); } if (googleTranslate.ShowDialog(this) == DialogResult.OK) { _subtitleListViewIndex = -1; 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 { _subtitleAlternate = new Subtitle(_subtitle); _subtitleAlternateFileName = _fileName; _fileName = null; _subtitle.Paragraphs.Clear(); foreach (Paragraph p in googleTranslate.TranslatedSubtitle.Paragraphs) _subtitle.Paragraphs.Add(new Paragraph(p)); ShowStatus(_language.SubtitleTranslated); } ShowSource(); if (!onlySelectedLines) { SubtitleListview1.ShowAlternateTextColumn(Configuration.Settings.Language.General.OriginalText); SubtitleListview1.AutoSizeAllColumns(this); SetupAlternateEdit(); } SubtitleListview1.Fill(_subtitle, _subtitleAlternate); ResetHistory(); RestoreSubtitleListviewIndexes(); _converted = true; SetTitle(); //if (googleTranslate.ScreenScrapingEncoding != null) // SetEncoding(googleTranslate.ScreenScrapingEncoding); SetEncoding(Encoding.UTF8); } _formPositionsAndSizes.SavePositionAndSize(googleTranslate); } else { MessageBox.Show(_language.NoSubtitleLoaded, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
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); using (var gt = new GoogleTranslate()) { Subtitle subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph(0, 0, textBoxSourceText.Text)); gt.Initialize(subtitle, string.Empty, false, System.Text.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 = (comboBoxFrom.SelectedItem as Nikse.SubtitleEdit.Forms.GoogleTranslate.ComboBoxItem).Value; string to = (comboBoxTo.SelectedItem as Nikse.SubtitleEdit.Forms.GoogleTranslate.ComboBoxItem).Value; string languagePair = from + "|" + to; buttonGoogle.Text = string.Empty; buttonGoogle.Text = Forms.GoogleTranslate.TranslateTextViaApi(textBoxSourceText.Text, languagePair); using (var gt = new GoogleTranslate()) { Subtitle subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph(0, 0, textBoxSourceText.Text)); gt.Initialize(subtitle, string.Empty, false, System.Text.Encoding.UTF8); from = FixMsLocale(from); to = FixMsLocale(to); gt.DoMicrosoftTranslate(from, to); buttonMicrosoft.Text = gt.TranslatedSubtitle.Paragraphs[0].Text; } } finally { Cursor = Cursors.Default; } }