/// <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 Marjani.Net.Utility.Translator t = new Marjani.Net.Utility.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; } }
/// <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) { if (dgvData.Rows.Count < 1) { MessageBox.Show("There aren't any record! please import language xml file"); return; } for (int i = 0; i < dgvData.Rows.Count; i++) { var row = dgvData.Rows[i]; // Initialize the translator Marjani.Net.Utility.Translator t = new Marjani.Net.Utility.Translator(); t.TargetLanguage = (string)this._comboTo.SelectedItem; t.SourceText = row.Cells[1].Value.ToString(); // Translate the text try { this.Cursor = Cursors.WaitCursor; this._lblStatus.Text = "Translating... Line (" + (i + 1) + "): " + row.Cells[1].Value.ToString(); this._lblStatus.Update(); t.Translate(); row.Cells[2].Value = t.Translation; dgvData.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { this._lblStatus.Text = string.Empty; this.Cursor = Cursors.Default; } } }