/// <summary> /// Translate selected rows /// </summary> /// <param name="provider">Translation provider to handle the process</param> /// <param name="from">Source language (can be null)</param> /// <param name="to">Target language</param> private void EditorControl_TranslateRequested(TRANSLATE_PROVIDER provider, string from, string to) { try { List <AbstractTranslateInfoItem> data = new List <AbstractTranslateInfoItem>(); AddToTranslationList(SelectedRows, data); // collect data to translate TranslationHandler.Translate(data, provider, from, to); foreach (AbstractTranslateInfoItem item in data) { item.ApplyTranslation(); // modify the editor's data } } catch (Exception ex) { Dictionary <string, string> add = null; if (ex is CannotParseResponseException) { CannotParseResponseException cpex = ex as CannotParseResponseException; add = new Dictionary <string, string>(); add.Add("Full response:", cpex.FullResponse); } VLOutputWindow.VisualLocalizerPane.WriteException(ex, add); VisualLocalizer.Library.Components.MessageBox.ShowException(ex, add); } }
public void Translate_TranllationReturnsValidValue(string fromWord, string fromLanguage, string toWord, string toLanguage) { TranslationHandler.AddEntry(fromWord, fromLanguage, toWord, toLanguage); Assert.AreEqual(toWord, TranslationHandler.Translate(fromWord, fromLanguage, toLanguage)); }
public void Translate_TranllationThwowsExceptionIfNotFound(string fromWord, string fromLanguage, string toWord, string toLanguage) { TranslationHandler.AddEntry("Hello", "EN", "Привет", "RU"); Assert.ThrowsException <Exception>(() => TranslationHandler.Translate(fromWord, fromLanguage, toLanguage), $"{fromWord} {fromLanguage} {toLanguage}"); }
public void Translate_HasNullParameters(string fromWord, string fromLanguage, string toLanguage) { Assert.ThrowsException <ArgumentNullException>(() => TranslationHandler.Translate(null, fromLanguage, toLanguage)); Assert.ThrowsException <ArgumentNullException>(() => TranslationHandler.Translate(fromWord, null, toLanguage)); Assert.ThrowsException <ArgumentNullException>(() => TranslationHandler.Translate(fromWord, fromLanguage, null)); }