protected virtual void AddContextProps(XliffTransPair pair, XElement tu) { foreach (var context in tu.Elements(X + "context-group").Elements(X + "context")) { AddProp(pair, "context/" + ((string)context.Attribute("context-type") ?? ""), (string)context ?? ""); } }
protected virtual void AddTuAttrProps(XliffTransPair pair, XElement tu) { foreach (var attr in tu.Attributes().Where(a => a.Name != "id")) { AddProp(pair, attr.Name.LocalName, attr.Value); } }
/// <summary> /// Extracts a single TransPair from a trans-unit element. /// </summary> /// <param name="tu">A trans-unit element.</param> /// <returns>A TransPair.</returns> protected virtual XliffTransPair ExtractSinglePair(XElement tu) { var source = tu.Element(X + "source"); var target = tu.Element(X + "target"); var pair = new XliffTransPair() { Serial = IsInterSegment(tu) ? -1 : 1, Id = (string)tu.Attribute("id"), Source = GetInline(source) ?? InlineString.Empty, Target = GetInline(target) ?? InlineString.Empty, SourceLang = GetLang(source) ?? SourceLang, TargetLang = GetLang(target) ?? TargetLang, }; MatchTags(pair.Source, pair.Target); pair.AddNotes(GetNotes(tu)); AddTuAttrProps(pair, tu); AddContextProps(pair, tu); if (source != null) { AddSourceAttrProps(pair, source); } if (target != null) { AddTargetAttrProps(pair, target); } return(pair); }
protected virtual XliffTransPair ExtractSinglePair(XElement tu) { var source = tu.Element(X + "source"); var target = tu.Element(X + "target"); var pair = new XliffTransPair() { Serial = ((string)tu.Attribute("translate") == "no") ? -1 : 1, Id = (string)tu.Attribute("id"), Source = GetInline(source) ?? InlineString.Empty, Target = GetInline(target) ?? InlineString.Empty, SourceLang = GetLang(source) ?? SourceLang, TargetLang = GetLang(target) ?? TargetLang, }; MatchTags(pair.Source, pair.Target); pair.AddNotes(GetNotes(tu)); foreach (var attr in tu.Attributes().Where(a => a.Name != "id")) { AddProp(pair, attr.Name.LocalName, attr.Value); } foreach (var context in tu.Elements(X + "context-group").Elements(X + "context")) { AddProp(pair, "context/" + ((string)context.Attribute("context-type") ?? ""), (string)context ?? ""); } return(pair); }
protected virtual void AddTargetAttrProps(XliffTransPair pair, XElement target) { foreach (var attr in target.Attributes() .Where(a => a.Name.Namespace != XNamespace.Xml && a.Name.Namespace != XNamespace.Xmlns)) { AddProp(pair, attr.Name.LocalName, attr.Value); } }
protected virtual XliffTransPair ExtractSegmentedPair(SegmentData src, SegmentData tgt, string slang, string tlang, IEnumerable <string> notes) { var selem = src.Element; var telem = tgt.Element; var pair = new XliffTransPair() { Serial = (selem != null) || (telem != null) ? 1 : -1, Id = (string)selem?.Attribute("mid") ?? (string)telem?.Attribute("mid") ?? "*", Source = GetInline(selem) ?? src.InlineString ?? InlineString.Empty, Target = GetInline(telem) ?? tgt.InlineString ?? InlineString.Empty, SourceLang = slang, TargetLang = tlang, }; MatchTags(pair.Source, pair.Target); pair.AddNotes(notes); return(pair); }
protected virtual XliffTransPair ExtractSingleAltPair(XElement alt) { var source = alt.Element(X + "seg-source") ?? alt.Element(X + "source") ?? alt.Parent.Element(X + "seg-source") ?? alt.Parent.Element(X + "source"); var target = alt.Element(X + "target"); var pair = new XliffTransPair() { Id = (string)alt.Parent.Attribute("id"), Source = GetInline(source) ?? InlineString.Empty, Target = GetInline(target) ?? InlineString.Empty, SourceLang = GetLang(source) ?? SourceLang, TargetLang = GetLang(target) ?? TargetLang, }; AddProp(pair, "origin", (string)alt.Attribute("origin")); MatchTags(pair.Source, pair.Target); pair.AddNotes(GetNotes(alt)); return(pair); }
protected override void AddTargetAttrProps(XliffTransPair pair, XElement target) { // Wordfast XLIFF puts multiple segment metadata in a single attribute target/@gs4tr:seginfo // in a _unique_ format. // We parse it into a set of multiple properties. var seginfo = target.Attribute(GS + "seginfo"); if (seginfo != null) { try { foreach (var attr in XElement.Parse((string)seginfo).Attributes()) { AddProp(pair, attr.Name.LocalName, attr.Value); } seginfo.Remove(); } catch (Exception) { } } base.AddTargetAttrProps(pair, target); }
protected virtual void AddProp(XliffTransPair pair, string key, string value) { PropMan.Put(ref pair._Props, key, value); }