/// <summary> /// Translates multiple segments, possibly using a fuzzy TM hit for improvement /// </summary> public TranslationResult[] TranslateCorrectSegment(Segment[] segs, Segment[] tmSources, Segment[] tmTargets) { TranslationResult[] results = new TranslationResult[segs.Length]; try { var texts = segs.Select(s => createTextFromSegment(s, FormattingAndTagsUsageOption.Plaintext)).ToList(); int i = 0; foreach (string translation in FiskmoMTServiceHelper.BatchTranslate(options, texts, this.srcLangCode, this.trgLangCode)) { results[i] = new TranslationResult(); results[i].Translation = createSegmentFromResult(segs[i], translation, FormattingAndTagsUsageOption.Plaintext); i++; } } catch (Exception e) { // Use the MTException class is to wrap the original exceptions occurred during the translation. for (var i = 0; i < results.Count(); i++) { if (results[i] == null) { results[i] = new TranslationResult(); } string localizedMessage = LocalizationHelper.Instance.GetResourceString("NetworkError"); results[i].Exception = new MTException(string.Format(localizedMessage, e.Message), string.Format("A network error occured ({0}).", e.Message), e); } } return(results); }
private async Task <LoginResult> loginCore(string userName, string password) { var loginResult = new LoginResult() { UserName = userName, Password = password }; try { // try to login // Do not call any blocking service in the user interface thread; it has to use background threads. string tokenCode = await Task.Run(() => FiskmoMTServiceHelper.Login(userName, password, this.mtServicePortTextBox.Text)); if (string.IsNullOrEmpty(tokenCode)) { // invalid user name or password loginResult.LoginSuccessful = false; } else { // successful login loginResult.LoginSuccessful = true; // try to get the list of the supported languages in the background // Do not call any blocking service in the user interface thread; it has to use background threads. loginResult.SupportedLanguages = await Task.Run(() => FiskmoMTServiceHelper.ListSupportedLanguages(tokenCode, this.mtServicePortTextBox.Text)); } } catch (Exception ex) { loginResult.Exception = ex; } return(loginResult); }
public void StoreTranslation(TranslationUnit transunit) { try { FiskmoMTServiceHelper.StoreTranslation(options, transunit.Source.PlainText, transunit.Target.PlainText, this.srcLangCode, this.trgLangCode); } catch (Exception e) { // Use the MTException class is to wrap the original exceptions occurred during the translation. string localizedMessage = LocalizationHelper.Instance.GetResourceString("NetworkError"); throw new MTException(string.Format(localizedMessage, e.Message), string.Format("A network error occured ({0}).", e.Message), e); } }
/// <summary> /// Translates a single segment, possibly using a fuzzy TM hit for improvement /// </summary> public TranslationResult TranslateCorrectSegment(Segment segm, Segment tmSource, Segment tmTarget) { TranslationResult result = new TranslationResult(); try { string textToTranslate = createTextFromSegment(segm, FormattingAndTagsUsageOption.Plaintext); string translation = FiskmoMTServiceHelper.Translate(options, textToTranslate, this.srcLangCode, this.trgLangCode); result.Translation = createSegmentFromResult(segm, translation, FormattingAndTagsUsageOption.Plaintext); } catch (Exception e) { // Use the MTException class is to wrap the original exceptions occurred during the translation. string localizedMessage = LocalizationHelper.Instance.GetResourceString("NetworkError"); result.Exception = new MTException(string.Format(localizedMessage, e.Message), string.Format("A network error occured ({0}).", e.Message), e); } return(result); }