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); }
/// <summary> /// 将XLS中的数据解析为DataTable /// <remarks> /// <para>解析规则:</para> /// <para>1.默认第一行为列标题,之后的所有行都为数据行</para> /// </remarks> /// </summary> /// <param name="pWorkSheet">工作簿对象</param> /// <param name="pResult">抽取结果详情</param> /// <returns>抽取出的DataTable</returns> public override System.Data.DataTable Extract(object pSource, out IETCLResultItem[] pResult) { DefaultExtractor defaultExtractor = new DefaultExtractor(); object dtData; bool bResult = defaultExtractor.Process(pSource, out dtData, out pResult); if (bResult) { this.OriginalData = (DataTable)dtData; return(this.OriginalData); } else { return(null); } }
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); }
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); }