Пример #1
0
        private IText CreateText(string segText)
        {
            ITextProperties textProperties = PropertiesFactory.CreateTextProperties(segText);
            IText           textContent    = ItemFactory.CreateText(textProperties);

            return(textContent);
        }
Пример #2
0
        public override void InlinePlaceholderTag(IPlaceholderTagProperties tagInfo)
        {
            var originalText = tagInfo.GetMetaData(EmbeddedContentConstants.EmbeddedContentMetaKey);

            if (originalText != null)
            {
                var textInfo = PropertiesFactory.CreateTextProperties(originalText);
                Text(textInfo);
            }
            else
            {
                base.InlinePlaceholderTag(tagInfo);
            }
        }
Пример #3
0
        public override void InlineEndTag(IEndTagProperties tagInfo)
        {
            string originalText = tagInfo.GetMetaData(EmbeddedContentMetaKey);

            if (originalText != null)
            {
                ITextProperties textInfo = PropertiesFactory.CreateTextProperties(originalText);
                base.Text(textInfo);
            }
            else
            {
                base.InlineEndTag(tagInfo);
            }
        }
        // protect text from being altered during translation
        // by locking it
        private void WriteLockedContent(string LockedContent)
        {
            //create opening tag for locked content
            ILockedContentProperties Lockedprops = PropertiesFactory.CreateLockedContentProperties(LockTypeFlags.Manual);

            Output.LockedContentStart(Lockedprops);

            //create text inside of locked content
            ITextProperties textProps = PropertiesFactory.CreateTextProperties(LockedContent);

            Output.Text(textProps);

            //close locked content
            Output.LockedContentEnd();
        }
Пример #5
0
        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            // ignore structure segment
            if (!paragraphUnit.IsStructure)
            {
                foreach (var segmentPair in paragraphUnit.SegmentPairs)
                {
                    if (IsTargetEmpty(segmentPair))
                    {
                        // copy source
                        if (Settings.CopyTargetContent.Value)
                        {
                            Implementation.SourceToTargetCopy.Copy(segmentPair, ItemFactory);
                        }
                        else // generate random text
                        {
                            Implementation.RandomTargetGenerator.Generate(segmentPair, ItemFactory);
                        }
                        SetConformationLevel(segmentPair);
                    }

                    if (!string.IsNullOrEmpty(Settings.AppendStart.Value))
                    {
                        segmentPair.Target.Insert(0,
                                                  ItemFactory.CreateText(
                                                      PropertiesFactory.CreateTextProperties(Settings.AppendStart.Value)));
                    }

                    if (!string.IsNullOrEmpty(Settings.AppendEnd.Value))
                    {
                        segmentPair.Target.Insert(segmentPair.Target.Count,
                                                  ItemFactory.CreateText(
                                                      PropertiesFactory.CreateTextProperties(Settings.AppendEnd.Value)));
                    }
                }
            }
            base.ProcessParagraphUnit(paragraphUnit);
        }
Пример #6
0
        public IAbstractMarkupData Text(string text)
        {
            var textProperties = PropertiesFactory.CreateTextProperties(text);

            return(ItemFactory.CreateText(textProperties));
        }
Пример #7
0
        public ISegment GetUpdatedSegment(ISegment targetSegment, IEnumerable <Token> tokens, ISegment sourceSegment)
        {
            var vector          = new List <int>();
            var lockedContentId = 0;

            //store original segment
            var originalSegment = (ISegment)targetSegment.Clone();

            //remove old content
            targetSegment.Clear();

            foreach (var item in tokens)
            {
                switch (item.Type)
                {
                case Token.TokenType.TagOpen:
                    var tagPairOpen = (IAbstractMarkupDataContainer)GetElement(
                        GetTagID(item.Content), originalSegment, sourceSegment, item.Type);
                    tagPairOpen.Clear();
                    InsertItemOnLocation(vector, ref targetSegment,
                                         (IAbstractMarkupData)tagPairOpen);
                    vector.Add(((ITagPair)tagPairOpen).IndexInParent);
                    break;

                case Token.TokenType.TagClose:
                    vector.RemoveAt(vector.Count - 1);
                    break;

                case Token.TokenType.TagPlaceholder:
                    InsertItemOnLocation(vector, ref targetSegment,
                                         GetElement(GetTagID(item.Content), originalSegment, sourceSegment,
                                                    item.Type));
                    break;

                case Token.TokenType.Text:
                    InsertItemOnLocation(vector, ref targetSegment, ItemFactory.CreateText(
                                             PropertiesFactory.CreateTextProperties(item.Content)));
                    break;

                case Token.TokenType.LockedContent:
                    InsertItemOnLocation(vector, ref targetSegment,
                                         GetElement(lockedContentId.ToString(), originalSegment, sourceSegment,
                                                    item.Type));
                    lockedContentId++;
                    break;

                case Token.TokenType.CommentStart:
                    var commentContainer = GetComment(item);
                    InsertItemOnLocation(vector, ref targetSegment,
                                         (IAbstractMarkupData)commentContainer);
                    vector.Add(((ICommentMarker)commentContainer).IndexInParent);
                    break;

                case Token.TokenType.CommentEnd:
                    if (vector.Count > 0)
                    {
                        vector.RemoveAt(vector.Count - 1);
                    }

                    break;

                case Token.TokenType.RevisionMarker:
                    //hasTrackedChanges = true;
                    if (item.RevisionType == Token.RevisionMarkerType.InsertStart)
                    {
                        var insertContainer = GetRevisionMarker(item, RevisionType.Insert);
                        InsertItemOnLocation(vector, ref targetSegment,
                                             (IAbstractMarkupData)insertContainer);
                        vector.Add(((IRevisionMarker)insertContainer).IndexInParent);
                    }
                    else if (item.RevisionType == Token.RevisionMarkerType.DeleteStart)
                    {
                        var insertContainer = GetRevisionMarker(item, RevisionType.Delete);
                        InsertItemOnLocation(vector, ref targetSegment,
                                             (IAbstractMarkupData)insertContainer);
                        vector.Add(((IRevisionMarker)insertContainer).IndexInParent);
                    }
                    else
                    {
                        if (vector.Count > 0)
                        {
                            vector.RemoveAt(vector.Count - 1);
                        }
                    }

                    break;
                }
            }

            return(targetSegment);
        }
        private int PerformReplaceIterator(Location textLocation, int textIndexStart, int textLength, ref int textIndex)
        {
            bool isWarning = false;

            _lockedCharactersCount = 0;
            TextCharacterCountingIterator iterator = new TextCharacterCountingIterator(textLocation);

            do
            {
                // if (iterator.CharacterCount + iterator.CharactersToNextLocation > textIndexStart)
                if (iterator.CharacterCount + iterator.CharactersToNextLocation + _charactersShift > textIndexStart)
                {
                    // text with tags - do not replace, report warning
                    //if (iterator.CharacterCount + iterator.CharactersToNextLocation < textIndexStart + textLength)
                    if (iterator.CharacterCount + iterator.CharactersToNextLocation + _charactersShift < textIndexStart + textLength)
                    {
                        //textIndex = (iterator.CharacterCount + iterator.CharactersToNextLocation) - (textIndexStart + textLength);
                        textIndex = (iterator.CharacterCount + iterator.CharactersToNextLocation + _charactersShift) - (textIndexStart + textLength);
                        isWarning = true;
                    }

                    #region IText
                    IText text = iterator.CurrentLocation.ItemAtLocation as IText;
                    if (text != null && !isWarning)
                    {
                        // real index in IText
                        textIndex = textIndexStart - (iterator.CharacterCount + _charactersShift);

                        // replace the text of IText
                        string replacedText = TextReplace(text.Properties.Text, textIndex, textLength);
                        iterator.CurrentLocation.ItemAtLocation.Parent[iterator.CurrentLocation.ItemAtLocation.IndexInParent] =
                            ItemFactory.CreateText(PropertiesFactory.CreateTextProperties(replacedText));
                        return(0);
                    }
                    #endregion

                    #region Tags
                    if (isWarning)
                    {
                        IPlaceholderTag phTag   = iterator.CurrentLocation.ItemAtLocation as IPlaceholderTag;
                        ITagPair        tagPair = iterator.CurrentLocation.ItemAtLocation as ITagPair;
                        if (phTag != null || tagPair != null)
                        {
                            return(-1);
                        }
                        tagPair = iterator.CurrentLocation.BottomLevel.Parent as ITagPair;
                        if (iterator.CurrentLocation.BottomLevel.IsAtEndOfParent && tagPair != null)
                        {
                            return(-1);
                        }
                    }
                    #endregion

                    #region Comment
                    if (isWarning)
                    {
                        ICommentMarker comment = iterator.CurrentLocation.ItemAtLocation as ICommentMarker;
                        if (comment != null)
                        {
                            return(-3);
                        }
                        comment = iterator.CurrentLocation.BottomLevel.Parent as ICommentMarker;
                        if (iterator.CurrentLocation.BottomLevel.IsAtEndOfParent && comment != null)
                        {
                            return(-3);
                        }
                    }
                    #endregion
                }

                #region LockedContent
                ILockedContent content = iterator.CurrentLocation.ItemAtLocation as ILockedContent;
                if (content != null)
                {
                    if (isWarning)
                    {
                        return(-2);
                    }
                    // real index in ILockedContent
                    textIndex = textIndexStart - (iterator.CharacterCount + _charactersShift);

                    // call the iterator for Locked Content
                    Location lockedLocation = new Location((IAbstractMarkupDataContainer)content.Content, true);
                    int      sts            = PerformReplaceIterator(lockedLocation, textIndex, textLength, ref textIndex);

                    // CODE TO FIX TextCharacterCountingIterator BUG !!! >>
                    // if TextCharacterCountingIterator failed to get CharactersToNextLocation,
                    // we calculate it manually and save as _charactersShift
                    if (iterator.CharactersToNextLocation == 0)
                    {
                        _charactersShift += _lockedCharactersCount;
                    }
                    if (sts != -4)
                    {
                        return(sts);
                    }
                }
                content = iterator.CurrentLocation.BottomLevel.Parent as ILockedContent;
                if (iterator.CurrentLocation.BottomLevel.IsAtEndOfParent && content != null)
                {
                    if (isWarning)
                    {
                        return(-1);
                    }
                }
                #endregion
            } while (iterator.MoveNext());

            _lockedCharactersCount = iterator.CharacterCount;

            return(-4);
        }
        // output translatable text
        private void WriteText(string TextContent)
        {
            ITextProperties textProperties = PropertiesFactory.CreateTextProperties(TextContent);

            Output.Text(textProperties);
        }