Example #1
0
        /// <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);
        }