Exemplo n.º 1
0
        private static Segment createSegmentFromResult(Segment originalSegment, string translatedText, FormattingAndTagsUsageOption formattingAndTagUsage)
        {
            if (formattingAndTagUsage == FormattingAndTagsUsageOption.Plaintext)
            {
                return(SegmentBuilder.CreateFromTrimmedStringAndITags(translatedText, originalSegment.ITags));
            }
            else if (formattingAndTagUsage == FormattingAndTagsUsageOption.OnlyFormatting)
            {
                // Convert to segment (conversion is needed because the result can contain formatting information)
                var convertedSegment = SegmentHtmlConverter.ConvertHtml2Segment(translatedText, originalSegment.ITags);
                var sb = new SegmentBuilder();
                sb.AppendSegment(convertedSegment);

                // Insert the tags to the end of the segment
                foreach (InlineTag it in originalSegment.ITags)
                {
                    sb.AppendInlineTag(it);
                }

                return(sb.ToSegment());
            }
            else
            {
                return(SegmentHtmlConverter.ConvertHtml2Segment(translatedText, originalSegment.ITags));
            }
        }