public void SingleParagraphPlainTextUnitIsLeftUntouched() { var xliff = @"<?xml version=""1.0"" encoding=""utf-8""?> <xliff srcLang=""en-GB"" version=""2.0"" trgLang=""it-IT"" xmlns=""urn:oasis:names:tc:xliff:document:2.0""> <file id=""f1""> <unit id=""u1""> <segment> <source>Hello World!</source> <target>Hello World!</target> </segment> </unit> </file> </xliff>"; XliffDocument document = LoadXliff(xliff); var inlineprocessing = new InlineCodeProcessing(); var newDocument = inlineprocessing.ExecuteMerge(document); Assert.AreEqual(1, newDocument.Files[0].Containers.Count); var unit = newDocument.Files[0].Containers[0] as Unit; Assert.AreEqual(1, unit.CollapseChildren <Target>()[0].Text.Count); var segment = unit.CollapseChildren <Target>()[0].Text[0] as PlainText; Assert.IsNotNull(segment); Assert.AreEqual("Hello World!", segment.Text); }
public void TargetWithPhGetConvertedToCDataWithBrHtmlTag() { var xliff = @"<?xml version=""1.0"" encoding=""utf-8""?> <xliff srcLang=""en-GB"" version=""2.0"" trgLang=""it-IT"" xmlns=""urn:oasis:names:tc:xliff:document:2.0""> <file id=""f1""> <unit id=""u1""> <segment> <source>Hello <ph id=""1"" subType=""xlf:lb"" type=""fmt""/>World!</source> <target>Hello <ph id=""1"" subType=""xlf:lb"" type=""fmt""/>World!</target> </segment> </unit> </file> </xliff>"; XliffDocument document = LoadXliff(xliff); var inlineprocessing = new InlineCodeProcessing(); var newDocument = inlineprocessing.ExecuteMerge(document); Assert.AreEqual(1, newDocument.Files[0].Containers.Count); var unit = newDocument.Files[0].Containers[0] as Unit; Assert.AreEqual(1, unit.CollapseChildren <Target>()[0].Text.Count); var segment = unit.CollapseChildren <Target>()[0].Text[0] as CDataTag; Assert.IsNotNull(segment); Assert.AreEqual("Hello <br/>World!", segment.Text); }
public void SingleParagraphCDataWithoutFormattigIsLeftUntouched() { var xliff = @"<?xml version=""1.0"" encoding=""utf-8""?> <xliff srcLang=""en-GB"" version=""2.0"" xmlns=""urn:oasis:names:tc:xliff:document:2.0""> <file id=""f1""> <unit id=""u1""> <segment> <source><![CDATA[Hello World!]]></source> </segment> </unit> </file> </xliff>"; XliffDocument document = LoadXliff(xliff); var inlineprocessing = new InlineCodeProcessing(); var newDocument = inlineprocessing.ExecuteExtraction(document); Assert.AreEqual(1, newDocument.Files[0].Containers.Count); var unit = newDocument.Files[0].Containers[0] as Unit; Assert.IsNull(unit.OriginalData); Assert.AreEqual(1, unit.CollapseChildren <Source>()[0].Text.Count); var segment = unit.CollapseChildren <Source>()[0].Text[0] as PlainText; Assert.IsNotNull(segment); Assert.AreEqual("Hello World!", segment.Text); }
public void TargetWithImgSrcAndSubflowsConvertedToCDataWithImgTagWithAttribute() { var xliff = @"<?xml version=""1.0"" encoding=""utf-8""?> <xliff srcLang=""en-GB"" version=""2.0"" trgLang=""it-IT"" xmlns=""urn:oasis:names:tc:xliff:document:2.0""> <file id=""f1""> <group id=""u1-g""> <unit id=""u1-1-src""> <segment> <source>http://consilium.eu/en/logo.jpg</source> <target>http://consilium.eu/it/logo.jpg</target> </segment> </unit> <unit id=""u1-1-title""> <segment> <source>Council Logo</source> <target>Council Logo Ita</target> </segment> </unit> <unit id=""u1""> <segment> <source>Link to <ph subFlows=""u1-1-src u1-1-title"" id=""1"" type=""image""/>Council site in English!</source> <target>Link to <ph subFlows=""u1-1-src u1-1-title"" id=""1"" type=""image""/>Council site in Italian!</target> </segment> </unit> </group> </file> </xliff>"; XliffDocument document = LoadXliff(xliff); var inlineprocessing = new InlineCodeProcessing(); var newDocument = inlineprocessing.ExecuteMerge(document); var xliffString = new DefaultExtractor().Write(newDocument, true); Assert.AreEqual(1, newDocument.Files[0].Containers.Count); var unit = newDocument.Files[0].Containers[0] as Unit; Assert.IsNotNull(unit); Assert.AreEqual(1, unit.CollapseChildren <Target>()[0].Text.Count); var segment = unit.CollapseChildren <Target>()[0].Text[0] as CDataTag; Assert.IsNotNull(segment); Assert.AreEqual("Link to <img src=\"http://consilium.eu/it/logo.jpg\" title=\"Council Logo Ita\"/>Council site in Italian!", segment.Text); }
public void TextWithBoldUnitCreatesUnitWithOriginalDataAndInlineCode() { var xliff = @"<?xml version=""1.0"" encoding=""utf-8""?> <xliff srcLang=""en-GB"" version=""2.0"" xmlns=""urn:oasis:names:tc:xliff:document:2.0""> <file id=""f1""> <unit id=""u1""> <segment> <source><![CDATA[Hello <b>World</b>!]]></source> </segment> </unit> </file> </xliff>"; XliffDocument document = LoadXliff(xliff); var inlineprocessing = new InlineCodeProcessing(); var newDocument = inlineprocessing.ExecuteExtraction(document); Assert.AreEqual(1, newDocument.Files[0].Containers.Count); var unit = newDocument.Files[0].Containers[0] as Unit; Assert.IsNotNull(unit.OriginalData); Assert.AreEqual(2, unit.OriginalData.DataElements.Count); var dataItem1 = unit.OriginalData.DataElements.Single(d => d.Id.Equals("d1")).Text[0].ToString(); var dataItem2 = unit.OriginalData.DataElements.Single(d => d.Id.Equals("d2")).Text[0].ToString(); Assert.AreEqual("<b>", dataItem1); Assert.AreEqual("</b>", dataItem2); var segment = unit.CollapseChildren <Source>()[0]; Assert.AreEqual(3, segment.Text.Count); var text1 = segment.Text[0] as PlainText; var pc = segment.Text[1] as SpanningCode; var text2 = segment.Text[2] as PlainText; Assert.IsNotNull(text1); Assert.IsNotNull(pc); Assert.IsNotNull(text2); Assert.AreEqual("Hello ", text1.Text); Assert.AreEqual("World", (pc.Text[0] as PlainText).Text); Assert.AreEqual("d1", pc.DataReferenceStart); Assert.AreEqual("d2", pc.DataReferenceEnd); Assert.AreEqual("!", text2.Text); }
public void TargetWithNestedUnitsWithPcGetConvertedToCDataWithBHtmlTag() { var xliff = @"<?xml version=""1.0"" encoding=""utf-8""?> <xliff srcLang=""en-GB"" version=""2.0"" trgLang=""it-IT"" xmlns=""urn:oasis:names:tc:xliff:document:2.0""> <file id=""f1""> <unit id=""u1""> <segment> <source>Hello <pc id=""1"" subType=""xlf:b"" type=""fmt"">World 1</pc>!</source> <target>Hello <pc id=""1"" subType=""xlf:b"" type=""fmt"">World 1</pc>!</target> </segment> </unit> <group id=""g1""> <unit id=""u2""> <segment> <source>Hello <pc id=""1"" subType=""xlf:b"" type=""fmt"">World 2</pc>!</source> <target>Hello <pc id=""1"" subType=""xlf:b"" type=""fmt"">World 2</pc>!</target> </segment> </unit> </group> </file> </xliff>"; XliffDocument document = LoadXliff(xliff); var inlineprocessing = new InlineCodeProcessing(); var newDocument = inlineprocessing.ExecuteMerge(document); Assert.AreEqual(2, newDocument.Files[0].Containers.Count); var unit1 = newDocument.Files[0].Containers[0] as Unit; var group = newDocument.Files[0].Containers[1] as Group; var unit2 = group.Containers[0] as Unit; Assert.AreEqual(1, unit1.CollapseChildren <Target>()[0].Text.Count); var segment1 = unit1.CollapseChildren <Target>()[0].Text[0] as CDataTag; Assert.IsNotNull(segment1); Assert.AreEqual("Hello <strong>World 1</strong>!", segment1.Text); Assert.AreEqual(1, unit2.CollapseChildren <Target>()[0].Text.Count); var segment2 = unit2.CollapseChildren <Target>()[0].Text[0] as CDataTag; Assert.IsNotNull(segment2); Assert.AreEqual("Hello <strong>World 2</strong>!", segment2.Text); }
public void TextWithHrefUnitCreatesNewGroupWithSubflow() { var xliff = @"<?xml version=""1.0"" encoding=""utf-8""?> <xliff srcLang=""en-GB"" version=""2.0"" xmlns=""urn:oasis:names:tc:xliff:document:2.0""> <file id=""f1""> <unit id=""u1""> <segment> <source><![CDATA[Link to <a href=""http://consilium.eu"">Council site</a>!]]></source> </segment> </unit> </file> </xliff>"; XliffDocument document = LoadXliff(xliff); var inlineprocessing = new InlineCodeProcessing(); var newDocument = inlineprocessing.ExecuteExtraction(document); Assert.AreEqual(1, newDocument.Files[0].Containers.Count); var group = newDocument.Files[0].Containers[0] as Group; Assert.IsNotNull(group); Assert.AreEqual("u1-g", group.Id); Assert.AreEqual(2, group.Containers.Count); var unitSubflow = group.Containers[0] as Unit; Assert.AreEqual("u1-1-href", unitSubflow.Id); Assert.AreEqual(1, unitSubflow.CollapseChildren <Source>()[0].Text.Count); var subFlowSegment = unitSubflow.CollapseChildren <Source>()[0].Text[0] as PlainText; Assert.IsNotNull(subFlowSegment); Assert.AreEqual("http://consilium.eu", subFlowSegment.Text); var unit = group.Containers[1] as Unit; Assert.IsNotNull(unit.OriginalData); Assert.AreEqual(2, unit.OriginalData.DataElements.Count); var dataItem1 = unit.OriginalData.DataElements.Single(d => d.Id.Equals("d1")).Text[0].ToString(); var dataItem2 = unit.OriginalData.DataElements.Single(d => d.Id.Equals("d2")).Text[0].ToString(); Assert.AreEqual("<a href=\"http://consilium.eu\">", dataItem1); Assert.AreEqual("</a>", dataItem2); var segment = unit.CollapseChildren <Source>()[0]; Assert.AreEqual(3, segment.Text.Count); var text1 = segment.Text[0] as PlainText; var pc = segment.Text[1] as SpanningCode; var text2 = segment.Text[2] as PlainText; Assert.IsNotNull(text1); Assert.IsNotNull(pc); Assert.IsNotNull(text2); Assert.AreEqual("Link to ", text1.Text); Assert.AreEqual("Council site", (pc.Text[0] as PlainText).Text); Assert.AreEqual("d1", pc.DataReferenceStart); Assert.AreEqual("d2", pc.DataReferenceEnd); Assert.AreEqual("u1-1-href", pc.SubFlowsStart); Assert.AreEqual("!", text2.Text); }