Exemplo n.º 1
0
        /// <summary>
        /// Used to do batch find-replace on a segment with tags.
        /// </summary>
        /// <param name="inSegment"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private Segment GetEditedSegment(SegmentEditor editor, Segment inSegment)
        {
            var newSeg = new Segment(inSegment.Culture);

            foreach (var element in inSegment.Elements)
            {
                var elType = element.GetType();

                if (elType.ToString() != "Sdl.LanguagePlatform.Core.Tag")                 //if other than tag, make string and edit it
                {
                    var temp = editor.EditText(element.ToString());
                    newSeg.Add(temp);                     //add edited text to segment
                }
                else
                {
                    newSeg.Add(element);                     //if tag just add the tag
                }
            }
            return(newSeg);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs the actual search by looping through the
        /// delimited segment pairs contained in the text file.
        /// Depening on the search mode, a segment lookup (with exact machting) or a source / target
        /// concordance search is done.
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="segment"></param>
        /// <returns></returns>

        #region "SearchSegment"

        public SearchResults SearchSegment(SearchSettings settings, Segment segment)
        {
            var translation = new Segment(_languageDirection.TargetCulture);            //this will be the target segment

            #region "SearchResultsObject"

            var results = new SearchResults();
            results.SourceSegment = segment.Duplicate();

            #endregion "SearchResultsObject"

            #region "Confirmation Level"

            if (!_options.ResendDrafts && _inputTu.ConfirmationLevel != ConfirmationLevel.Unspecified) //i.e. if it's status is other than untranslated
            {                                                                                          //don't do the lookup, b/c we don't need to pay google to translate text already translated if we edit a segment
                translation.Add(PluginResources.TranslationLookupDraftNotResentMessage);
                //later get these strings from resource file
                results.Add(CreateSearchResult(segment, translation));
                return(results);
            }

            #endregion "Confirmation Level"

            // Look up the currently selected segment in the collection (normal segment lookup).

            #region "SegmentLookup"

            var translatedText = "";
            //a new seg avoids modifying the current segment object
            var newseg = segment.Duplicate();

            //do preedit if checked
            var sendTextOnly = _options.SendPlainTextOnly || !newseg.HasTags;
            if (!sendTextOnly)
            {
                //do preedit with tagged segment
                if (_options.UsePreEdit)
                {
                    if (_preLookupSegmentEditor == null)
                    {
                        _preLookupSegmentEditor = new SegmentEditor(_options.PreLookupFilename);
                    }
                    newseg = GetEditedSegment(_preLookupSegmentEditor, newseg);
                }
                //return our tagged target segment
                var tagplacer = new MtTranslationProviderTagPlacer(newseg);
                ////tagplacer is constructed and gives us back a properly marked up source string for google
                if (_options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    translatedText = LookupGt(tagplacer.PreparedSourceText, _options, "html");
                }
                else if (_options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    translatedText = LookupMst(tagplacer.PreparedSourceText, _options, "text/html");
                }
                //now we send the output back to tagplacer for our properly tagged segment
                translation = tagplacer.GetTaggedSegment(translatedText).Duplicate();

                //now do post-edit if that option is checked
                if (_options.UsePostEdit)
                {
                    if (_postLookupSegmentEditor == null)
                    {
                        _postLookupSegmentEditor = new SegmentEditor(_options.PostLookupFilename);
                    }
                    translation = GetEditedSegment(_postLookupSegmentEditor, translation);
                }
            }
            else             //only send plain text
            {
                var sourcetext = newseg.ToPlain();
                //do preedit with string
                if (_options.UsePreEdit)
                {
                    if (_preLookupSegmentEditor == null)
                    {
                        _preLookupSegmentEditor = new SegmentEditor(_options.PreLookupFilename);
                    }
                    sourcetext = GetEditedString(_preLookupSegmentEditor, sourcetext);
                    //change our source segment so it gets sent back with modified text to show in translation results window that it was changed before sending
                    newseg.Clear();
                    newseg.Add(sourcetext);
                }

                //now do lookup
                if (_options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    translatedText = LookupGt(sourcetext, _options, "html");                     //plain??
                }
                else if (_options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    translatedText = LookupMst(sourcetext, _options, "text/plain");
                }
                //now do post-edit if that option is checked
                if (_options.UsePostEdit)
                {
                    if (_postLookupSegmentEditor == null)
                    {
                        _postLookupSegmentEditor = new SegmentEditor(_options.PostLookupFilename);
                    }
                    translatedText = GetEditedString(_postLookupSegmentEditor, translatedText);
                }
                translation.Add(translatedText);
            }

            results.Add(CreateSearchResult(newseg, translation));
            #endregion "SegmentLookup"

            #region "Close"
            return(results);

            #endregion "Close"
        }
Exemplo n.º 3
0
        /// <summary>
        /// Used to do batch find-replace on a string of plain text.
        /// </summary>
        /// <param name="sourcetext"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private string GetEditedString(SegmentEditor editor, string sourcetext)
        {
            var result = editor.EditText(sourcetext);

            return(result);
        }