private void translator_TranslationReceived(object sender, TranslationReceivedEventArgs e) { if (this.InvokeRequired) { this.Invoke(new EventHandler <TranslationReceivedEventArgs>(this.translator_TranslationReceived), new[] { sender, e }); } else { try { var resourceSet = this.context.CurrentLocalResourceSet; foreach (var translationResult in e.Results) { // invoke 'after translation hook' to allow other plugins to tamper with the translation this.webTranslatorPlugIn.InvokeAfterItemAutoTranslation(translationResult); // TODO : HANDLE translationResult.Error resourceSet.GetStringItem(translationResult.Key).Value = translationResult.Text; if (this.markForReviewCheckBox.Checked) { resourceSet[translationResult.Key].ReviewPending = true; } } } catch (Exception exception) { Tools.ShowExceptionMessageBox("Failed to use translation results", exception); } } }
private void ExclusionButton_Click(object sender, EventArgs e) { try { var form = new ExclusionsForm(this.context.CurrentBaseResourceSet.Exclusions); form.ShowDialog(this); } catch (Exception exception) { Tools.ShowExceptionMessageBox(exception); } }
private void DetectButton_Click(object sender, EventArgs e) { try { var translator = this.context.Container.Resolve <ITranslatorEngine>(); var language = translator.DetectLanguage(GetValuesForTranslation(this.context.CurrentBaseResourceSet)); SetCombo(comboBox1, language); } catch (Exception exception) { Tools.ShowExceptionMessageBox(exception); } }
private void TranslationComplete(IAsyncResult ar) { this.Invoke(new System.Threading.ThreadStart(() => { try { this.translator.EndTranslate(ar); MessageBox.Show("Translation Done!"); this.Close(); } catch (Exception exception) { Tools.ShowExceptionMessageBox(exception); } })); }
private void TranslateButton_Click(object sender, EventArgs e) { this.UseWaitCursor = true; try { if (!running) { var sourceLanguage = (string)comboBox1.SelectedValue; var targetLanguage = (string)comboBox2.SelectedValue; var values = GetValuesForTranslation(this.context.CurrentBaseResourceSet).ToList(); // filter out already translated items, unless opposite is selected by end-user var translateAll = (int)comboBox3.SelectedValue == 0; var filteredValues = from p in values where !this.context.CurrentLocalResourceSet.HasValue(p.Text) || translateAll select p; // invoke 'before translation hook' to allow other plugins to tamper with the translation foreach (var translationItem in filteredValues) { this.webTranslatorPlugIn.InvokeBeforeItemAutoTranslation(translationItem); } translator = this.context.Container.Resolve <ITranslatorEngine>(); translator.TranslationReceived += this.translator_TranslationReceived; this.running = true; this.RefreshStatus(); translator.BeginTranslate(values, sourceLanguage, targetLanguage, this.TranslationComplete, null); } else { this.translator.Stop(); } } catch (Exception exception) { Tools.ShowExceptionMessageBox(exception); } finally { this.UseWaitCursor = false; } }