示例#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);
        }
示例#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>

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

            var results = new SearchResults();

            results.SourceSegment = segment.Duplicate();

            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, segment.ToString()));
                return(results);
            }

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

            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
                translatedText = LookupAmz(tagplacer.PreparedSourceText, _options);

                //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
                translatedText = LookupAmz(sourcetext, _options);

                //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, newseg.ToPlain()));

            return(results);
        }
示例#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);
        }