public void CanExtractSimpleFile(string filename) { var bundle = EmbeddedFilesReader.ReadString("XliffLib.Integration.TestFiles." + filename + ".json").ToBundle(); var xliff = EmbeddedFilesReader.ReadString("XliffLib.Integration.TestFiles." + filename + ".xlf"); var extractor = new DefaultExtractor(); var xliffModel = extractor.Extract(bundle, "en-US", "it-IT"); var xliffString = extractor.Write(xliffModel, true); var cleanedExpected = System.Text.RegularExpressions.Regex.Replace(xliff, @"\s+", " "); var cleanedResult = System.Text.RegularExpressions.Regex.Replace(xliffString, @"\s+", " "); Assert.AreEqual(cleanedExpected, cleanedResult); }
static void Main(string[] args) { var path = System.Reflection.Assembly.GetExecutingAssembly().Location; var directory = System.IO.Path.GetDirectoryName(path); var content = System.IO.File.ReadAllText(Path.Combine(directory, "Samples", "original.txt")); var bundle = new Bundle(); var doc = new Document(); bundle.Documents.Add(doc); var property = new Property("original", content); doc.Containers.Add(property); //Extractor extractor = new SimpleExtractor(); Extractor extractor = new DefaultExtractor(); XliffDocument xliff = extractor.Extract(bundle, "en-GB", "it-IT"); try { var result = extractor.Write(xliff, true); Console.WriteLine(result); System.IO.File.WriteAllText(Path.Combine(directory, "Samples", "extraction.xlf"), result); } catch (ValidationException e) { Console.WriteLine("ValidationException Details:"); Console.WriteLine(e.Message); if (e.Data != null) { foreach (var key in e.Data.Keys) { Console.WriteLine(" '{0}': '{1}'", key, e.Data[key]); } } } Console.ReadLine(); }
public void CanExtractAndMerge(string filename) { var bundleString = EmbeddedFilesReader.ReadString("XliffLib.Integration.TestFiles." + filename + ".json"); var bundle = bundleString.ToBundle(); var extractor = new DefaultExtractor(); var xliffModel = extractor.Extract(bundle, "en-US", "it-IT"); var xliffString = extractor.Write(xliffModel, true); XmlDocument doc = new XmlDocument(); doc.LoadXml(xliffString); var allSources = doc.GetElementsByTagName("source"); foreach (XmlNode source in allSources) { var newTarget = doc.CreateElement("target", "urn:oasis:names:tc:xliff:document:2.0"); newTarget.InnerXml = source.InnerXml; source.ParentNode.AppendChild(newTarget); } var newXliff = doc.OuterXml; var merger = new DefaultMerger(); xliffModel = merger.Read(newXliff); var resultingBundle = merger.Merge(xliffModel); var jsonResult = resultingBundle.ToJson(); JObject expected = JObject.Parse(bundleString); JObject result = JObject.Parse(jsonResult); Assert.IsTrue(JToken.DeepEquals(expected, result), "The two bundles are different:\r\nExpected {0}\r\nResult {1}", bundleString, jsonResult); }