/// <summary> /// Demonstrates how to store <see cref="Glossary"/> data in a <see cref="Unit"/> element. /// </summary> public static void StoreGlossary() { GlossaryEntry entry; MarkedSpan span; Segment segment; Translation translation; Unit unit; // Create a unit to hold the glossary. unit = new Unit("id"); unit.Glossary = new Glossary(); entry = new GlossaryEntry(); entry.Reference = "#m1"; unit.Glossary.Entries.Add(entry); // Create a term that looks like: <gls:term source="publicTermbase">TAB key</gls:term> entry.Term.Source = "publicTermbase"; entry.Term.Text = "TAB key"; // Create a translation that looks like: <gls:translation id="1" source="myTermbase">Tabstopptaste</gls:translation> translation = new Translation("1"); translation.Source = "myTermbase"; translation.Text = "Tabstopptaste"; entry.Translations.Add(translation); // Create a translation that looks like: <gls:translation ref="#m2" source="myTermbase">TAB-TASTE</gls:translation> translation = new Translation(); translation.Reference = "#m1"; translation.Source = "myTermbase"; translation.Text = "TAB-TASTE"; entry.Translations.Add(translation); // Create a definition that looks like: // <gls:definition source="publicTermbase">A keyboard key that is traditionally used to insert tab" // characters into a document.</gls:definition> entry.Definition = new Definition(); entry.Definition.Source = "publicTermbase"; entry.Definition.Text = "A keyboard key that is traditionally used to insert tab characters into a document."; // Create a segment to which the glossary refers. segment = new Segment(); segment.Source = new Source(); segment.Source.Text.Add(new PlainText("Press the ")); span = new MarkedSpan("m1"); span.Type = "term"; span.Text.Add(new PlainText("TAB key")); segment.Source.Text.Add(span); segment.Target = new Target(); segment.Target.Text.Add(new PlainText("Drücken Sie die ")); span = new MarkedSpan("m1"); span.Type = "term"; span.Text.Add(new PlainText("TAB-TASTE")); segment.Target.Text.Add(span); unit.Resources.Add(segment); }
public void XliffWriter_MarkedSpan() { MarkedSpan span1; MarkedSpan span2; Segment segment; Unit unit; string actualValue; unit = new Unit("u1"); this._document.SourceLanguage = "en-us"; this._document.Files.Add(new File("f1")); this._document.Files[0].Containers.Add(unit); segment = new Segment("s1"); unit.Resources.Add(segment); segment.Source = new Source(); span1 = new MarkedSpan("mrk1"); segment.Source.Text.Add(span1); Console.WriteLine("Test with valid values."); actualValue = this.Serialize(); // Translate value will be automatically written because type is generic (default). Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanWithValidValues), actualValue); Console.WriteLine("Test with term."); span1.Type = MarkedSpanTypes.Term; actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanWithTerm), actualValue); Console.WriteLine("Test with custom type."); span1.Type = "my:type"; actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanWithCustomType), actualValue); Console.WriteLine("Test with nested spans."); span1.Type = MarkedSpanTypes.Comment; span1.Value = "this is a comment"; span2 = new MarkedSpan("mrk2"); span2.Translate = true; span1.Text.Add(span2); actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanWithNestedMarkedSpan), actualValue); }
public void XliffWriter_Glossary() { MarkedSpan span; Segment segment; Unit unit; unit = new Unit("u1"); unit.Glossary = new Glossary(); unit.Glossary.Entries.Add(new GlossaryEntry()); unit.Glossary.Entries[0].Id = "entry1"; unit.Glossary.Entries[0].Reference = Utilities.MakeIri("m1"); unit.Glossary.Entries[0].Definition = new Definition(); unit.Glossary.Entries[0].Definition.Source = "definitionSource"; unit.Glossary.Entries[0].Definition.Text = "definition text"; unit.Glossary.Entries[0].Term.Source = "termSource"; unit.Glossary.Entries[0].Term.Text = "term text"; unit.Glossary.Entries[0].Translations.Add(new Translation()); unit.Glossary.Entries[0].Translations[0].Id = "trans1"; unit.Glossary.Entries[0].Translations[0].Reference = Utilities.MakeIri("m1"); unit.Glossary.Entries[0].Translations[0].Source = "transSource"; unit.Glossary.Entries[0].Translations[0].Text = "translation text"; span = new MarkedSpan("m1"); span.Type = "term"; span.Text.Add(new PlainText("text")); segment = new Segment(); segment.Source = new Source(); segment.Source.Text.Add(span); segment.State = TranslationState.Initial; this._document.SourceLanguage = "en-us"; this._document.Files.Add(new File("f1")); this._document.Files[0].Containers.Add(unit); unit.Resources.Add(segment); Assert.AreEqual( TestUtilities.GetFileContents(TestData.GlossaryWithValidValues), this.Serialize(), "Serialized document is incorrect."); }
public void XliffElement_SelectorPath_Target() { MarkedSpan span; Group group; Unit unit; Segment segment; XliffDocument document; span = new MarkedSpan("mrk1"); segment = new Segment(); segment.Target = new Target(); segment.Target.Text.Add(span); unit = new Unit("u1"); unit.Resources.Add(segment); group = new Group("g1"); group.Containers.Add(unit); document = new XliffDocument(); document.Files.Add(new File("f1")); document.Files[0].Containers.Add(group); Console.WriteLine("Test with segment without Id."); Assert.AreEqual("#/f=f1/g=g1/u=u1/t=mrk1", span.SelectorPath, "SelectorPath is incorrect."); Console.WriteLine("Test with all items with Id."); segment.Id = "s1"; Assert.AreEqual("#/f=f1/g=g1/u=u1/t=mrk1", span.SelectorPath, "SelectorPath is incorrect."); Console.WriteLine("Test with tag without Id."); span.Id = null; Assert.AreEqual("#/f=f1/g=g1/u=u1/s1", span.SelectorPath, "SelectorPath is incorrect."); Console.WriteLine("Test with tag and segment without Id."); segment.Id = null; span.Id = null; Assert.AreEqual("#/f=f1/g=g1/u=u1", span.SelectorPath, "SelectorPath is incorrect."); }
public void MarkedSpanStart_Defaults() { MarkedSpan spanParent; Unit unitParent; Console.WriteLine("Test with element child of unit with false Translate."); unitParent = new Unit(); unitParent.Translate = false; this._element.Parent = unitParent; Assert.AreEqual(this._element.Translate, unitParent.Translate, "Translate is incorrect."); Console.WriteLine("Test with element child of unit with true Translate."); unitParent.Translate = true; Assert.AreEqual(this._element.Translate, unitParent.Translate, "Translate is incorrect."); Console.WriteLine("Test with element child of mrk with false Translate."); spanParent = new MarkedSpan(); spanParent.Translate = false; spanParent.Parent = unitParent; this._element.Parent = spanParent; Assert.AreEqual(this._element.Translate, spanParent.Translate, "Translate is incorrect."); Console.WriteLine("Test with element child of mrk with true Translate."); spanParent.Translate = true; Assert.AreEqual(this._element.Translate, spanParent.Translate, "Translate is incorrect."); }
public void XliffElement_SelectorPath() { MarkedSpan span; Group group; Unit unit; Segment segment; XliffDocument document; span = new MarkedSpan("mrk1"); segment = new Segment(); segment.Source = new Source(); segment.Source.Text.Add(span); unit = new Unit("u1"); unit.Resources.Add(segment); group = new Group("g1"); group.Containers.Add(unit); document = new XliffDocument(); document.Files.Add(new File("f1")); document.Files[0].Containers.Add(group); Console.WriteLine("Test for document."); Assert.AreEqual("#", document.SelectorPath, "SelectorPath is incorrect."); Console.WriteLine("Test for file."); Assert.AreEqual("#/f=f1", document.Files[0].SelectorPath, "SelectorPath is incorrect."); Console.WriteLine("Test for group."); Assert.AreEqual("#/f=f1/g=g1", group.SelectorPath, "SelectorPath is incorrect."); Console.WriteLine("Test for unit."); Assert.AreEqual("#/f=f1/g=g1/u=u1", unit.SelectorPath, "SelectorPath is incorrect."); }
public void TestInitialize() { this._element = new MarkedSpan(); this._provider = this._element; }