public SearchResults SearchSegment(SearchSettings settings, Segment segment) { var translation = new Segment(_languageDirection.TargetCulture); var results = new SearchResults { SourceSegment = segment.Duplicate() }; try { var newseg = segment.Duplicate(); if (newseg.HasTags && !_options.SendPlainText) { var tagPlacer = new DeepLTranslationProviderTagPlacer(newseg); var translatedText = LookupDeepL(tagPlacer.PreparedSourceText); if (!string.IsNullOrEmpty(translatedText)) { translation = tagPlacer.GetTaggedSegment(translatedText); results.Add(CreateSearchResult(newseg, translation)); return(results); } } else { var sourcetext = newseg.ToPlain(); var translatedText = LookupDeepL(sourcetext); if (!string.IsNullOrEmpty(translatedText)) { translation.Add(translatedText); results.Add(CreateSearchResult(newseg, translation)); return(results); } } } catch (Exception e) { _logger.Error($"SearchSegment method: {e.Message}\n {e.StackTrace}"); throw; } return(results); }
public SearchResults SearchSegment(SearchSettings settings, Segment segment) { var translation = new Segment(_languageDirection.TargetCulture); var results = new SearchResults() { SourceSegment = segment.Duplicate() }; // if there are match in tm the provider will not search the segment #region "Confirmation Level" if (_inputTu.ConfirmationLevel != ConfirmationLevel.Unspecified) { //translation.Add(PluginResources.TranslationLookupDraftNotResentMessage); translation.Add("dddfd"); //later get these strings from resource file results.Add(CreateSearchResult(segment, translation, segment.ToString())); return(results); } var newseg = segment.Duplicate(); if (newseg.HasTags) { var tagPlacer = new DeepLTranslationProviderTagPlacer(newseg); var translatedText = LookupDeepl(tagPlacer.PreparedSourceText); translation = tagPlacer.GetTaggedSegment(translatedText); results.Add(CreateSearchResult(newseg, translation, newseg.ToPlain())); return(results); } else { var sourcetext = newseg.ToPlain(); var translatedText = LookupDeepl(sourcetext); translation.Add(translatedText); results.Add(CreateSearchResult(newseg, translation, newseg.ToPlain())); return(results); } #endregion }
private List <SearchResults> GetPreTranslationSearchResults(List <PreTranslateSegment> preTranslateList) { var resultsList = new List <SearchResults>(preTranslateList.Capacity); for (int i = 0; i < resultsList.Capacity; i++) { resultsList.Add(null); } foreach (var preTranslate in preTranslateList) { if (preTranslate != null) { var translation = new Segment(_languageDirection.TargetCulture); var newSeg = preTranslate.TranslationUnit.SourceSegment.Duplicate(); if (newSeg.HasTags && !_options.SendPlainText) { var tagPlacer = new DeepLTranslationProviderTagPlacer(newSeg); translation = tagPlacer.GetTaggedSegment(preTranslate.PlainTranslation); preTranslate.TranslationSegment = translation; } else { translation.Add(preTranslate.PlainTranslation); } var searchResult = CreateSearchResult(newSeg, translation); var results = new SearchResults { SourceSegment = newSeg }; results.Add(searchResult); var index = preTranslateList.IndexOf(preTranslate); resultsList.RemoveAt(index); resultsList.Insert(index, results); } } return(resultsList); }