public void ValidationReportsErrorsOnMissingSourceElement() { var xliffText = @"<xliff xmlns=""urn:oasis:names:tc:xliff:document:1.2"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" version=""1.2"" xsi:schemaLocation=""urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd""> <file datatype=""xml"" source-language=""en"" target-language=""fr"" original=""test.resx""> <body> <trans-unit id=""Alpha""> <target state=""new"">Alpha {0}</target> <note /> </trans-unit> </body> </file> </xliff>"; var document = new XlfDocument(); document.Load(new StringReader(xliffText)); var validationErrors = GetValidationErrors(document); Assert.Collection(validationErrors, new Action <XmlSchemaException>[] { e => Assert.Equal(expected: "The element 'trans-unit' in namespace 'urn:oasis:names:tc:xliff:document:1.2' has invalid child element 'target' in namespace 'urn:oasis:names:tc:xliff:document:1.2'. List of possible elements expected: 'source' in namespace 'urn:oasis:names:tc:xliff:document:1.2'.", actual: e.Message) }); }
private static ISet <string> UntranslatedResources(string xliff) { var xliffDocument = new XlfDocument(); xliffDocument.Load(new StringReader(xliff)); return(xliffDocument.GetUntranslatedResourceIDs()); }
private static string Sort(string xliff) { var xliffDocument = new XlfDocument(); xliffDocument.Load(new StringReader(xliff)); xliffDocument.Sort(); var writer = new StringWriter(); xliffDocument.Save(writer); return(writer.ToString()); }
internal XlfDocument LoadXlfDocument(string path, string language = null, bool createIfNonExistent = false) { var document = new XlfDocument(); if (File.Exists(path)) { document.Load(path); } else if (createIfNonExistent) { Release.Assert(!string.IsNullOrEmpty(language)); document.LoadNew(language); } else { throw new FileNotFoundException($"File not found: {path}", path); } return(document); }
private static string Update(string xliff, string resx) { var xliffDocument = new XlfDocument(); if (string.IsNullOrEmpty(xliff)) { xliffDocument.LoadNew("fr"); } else { xliffDocument.Load(new StringReader(xliff)); } var resxDocument = new ResxDocument(); resxDocument.Load(new StringReader(resx)); xliffDocument.Update(resxDocument, "test.resx"); var writer = new StringWriter(); xliffDocument.Save(writer); return(writer.ToString()); }