/// <summary> /// Handles the Click event of the _btnTranslate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void _btnTranslate_Click(object sender, EventArgs e) { // Initialize the translator Translator t = new Translator(); t.SourceLanguage = (string) this._comboFrom.SelectedItem; t.TargetLanguage = (string) this._comboTo.SelectedItem; t.SourceText = this._editSourceText.Text; this._editTarget.Text = string.Empty; this._editTarget.Update(); this._editReverseTranslation.Text = string.Empty; this._editReverseTranslation.Update(); // Translate the text try { // Forward translation this.Cursor = Cursors.WaitCursor; this._lblStatus.Text = "Translating..."; this._lblStatus.Update(); t.Translate(); this._editTarget.Text = t.Translation; this._editTarget.Update(); // Reverse translation this._lblStatus.Text = "Reverse translating..."; this._lblStatus.Update(); Thread.Sleep (500); // let Google breathe t.SourceLanguage = (string) this._comboTo.SelectedItem; t.TargetLanguage = (string) this._comboFrom.SelectedItem; t.SourceText = this._editTarget.Text; t.Translate(); this._editReverseTranslation.Text = t.Translation; } catch (Exception ex) { MessageBox.Show (ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { this._lblStatus.Text = string.Empty; this.Cursor = Cursors.Default; } }
private SimpleData TranslateLang(Translator t, SimpleData temp) { t.SourceLanguage = (string)this._comboFrom.SelectedItem; t.TargetLanguage = (string)this._comboTo.SelectedItem; t.SourceText = temp.En; try { // Forward translation this.Cursor = Cursors.WaitCursor; this._lblStatus.Text = "Being translation..." + temp.KhoaChinh + "...Key"; this._lblStatus.Update(); t.Translate(); var stext = t.Translation; stext = stext.Replace(">", ">"); if (stext.StartsWith("gt;")) { stext = stext.Replace("gt;", ">"); } stext = stext.Replace("<", "<"); if (stext.StartsWith("lt;")) { stext = stext.Replace("<", "<"); } stext = stext.Replace("% 1 $ s", " %1$s "); stext = stext.Replace("% 2 $ s", " %2$s "); stext = stext.Replace("% 3 $ s", " %3$s "); stext = stext.Replace("% 4 $ s", " %4$s "); stext = stext.Replace("% 5 $ s", " %5$s "); stext = stext.Replace("% 6 $ s", " %6$s "); stext = stext.Replace("% d", " %d "); stext = stext.Replace("% s", " %s "); if (stext.StartsWith("D ")) { stext = stext.Replace("D ", "%d "); } if (stext.StartsWith("S ")) { stext = stext.Replace("S ", "%s "); } stext = stext.Replace("_QQ_", " \"_QQ_\" "); temp.Vi = stext; this._lblStatus.Text = "Translate completed..." + temp.KhoaChinh + "...Key"; this._lblStatus.Update(); } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { this._lblStatus.Text = string.Empty; this.Cursor = Cursors.Default; } return temp; }