internal TranslatableDocument LoadSourceDocument(string path, string format) { TranslatableDocument document; string extension = Path.GetExtension(path); if (format.Equals("Resx", StringComparison.OrdinalIgnoreCase)) { document = new ResxDocument(); } else if (format.Equals("Unstructured", StringComparison.OrdinalIgnoreCase)) { document = new UnstructuredDocument(); } else if (format.Equals("Vsct", StringComparison.OrdinalIgnoreCase)) { document = new VsctDocument(); } else if (format.Equals("XamlRule", StringComparison.OrdinalIgnoreCase)) { document = new XamlRuleDocument(); } else { throw new BuildErrorException($"Unknown source file format '{format}'.") { RelatedFile = path }; } document.Load(path); return(document); }
public void RewriteFileReferenceToAbsoluteInDestinyFolder() { string sourceFolder = Directory.GetCurrentDirectory(); string expectedAbsoluteLocation = Path.Combine( Directory.GetCurrentDirectory(), @"Resources\Package.ico".Replace('\\', Path.DirectorySeparatorChar)); string source = @"<root> <data name=""400"" type=""System.Resources.ResXFileRef, System.Windows.Forms""> <value>Resources\Package.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> </root>"; var translations = new Dictionary <string, string> { ["Hello"] = "Bonjour!", }; string expectedTranslation = @"<root> <data name=""400"" type=""System.Resources.ResXFileRef, System.Windows.Forms""> <value>ABSOLUTEPATH;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> </root>".Replace("ABSOLUTEPATH", expectedAbsoluteLocation); var document = new ResxDocument(); var writer = new StringWriter(); document.Load(new StringReader(source)); document.RewriteRelativePathsToAbsolute( Path.Combine(sourceFolder, "Resources.resx")); document.Save(writer); AssertEx.EqualIgnoringLineEndings(expectedTranslation, writer.ToString()); }
public void SetUp() { _test1 = new ResxDocument(TestUtils.LoadTest1()); _test2 = new ResxDocument(TestUtils.LoadTest2()); _test3 = new ResxDocument(TestUtils.LoadTest3()); _test4 = new ResxDocument(TestUtils.LoadTest4()); }
public void ResxDocumentToXmlWithChanges() { var test1 = new ResxDocument(TestUtils.LoadTest1()); test1.Data.Add(new ResxData { Name = "Test_key_4", Value = "Test value 4", Space = "preserve" }); Assert.AreEqual(TestUtils.LoadTest2().ToString(), test1.ToXml().ToString()); }
public void Load() { var test1 = new ResxDocument(TestUtils.LoadTest1()); Assert.AreEqual(3, test1.Data.Count); Assert.AreEqual("Test_key_1", test1.Data[0].Name); Assert.AreEqual(null, test1.Data[0].Type); Assert.AreEqual(null, test1.Data[0].Mimetype); Assert.AreEqual("preserve", test1.Data[0].Space); Assert.AreEqual("Test value 1", test1.Data[0].Value); Assert.AreEqual("A comment", test1.Data[0].Comment); }
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()); }
public void BasicLoadAndTranslate() { string source = @"<root> <data name=""Hello"" xml:space=""preserve""> <value>Hello!</value> </data> <data name=""Goodbye"" xml:space=""preserve""> <value>Goodbye!</value> </data> </root>"; var translations = new Dictionary <string, string> { ["Hello"] = "Bonjour!", ["Goodbye"] = "Au revoir!", }; string expectedTranslation = @"<root> <data name=""Hello"" xml:space=""preserve""> <value>Bonjour!</value> </data> <data name=""Goodbye"" xml:space=""preserve""> <value>Au revoir!</value> </data> </root>"; var document = new ResxDocument(); var writer = new StringWriter(); document.Load(new StringReader(source)); document.Translate(translations); document.Save(writer); AssertEx.EqualIgnoringLineEndings(expectedTranslation, writer.ToString()); }
public void ResxDocumentToXml() { var test1 = new ResxDocument(TestUtils.LoadTest1()); Assert.AreEqual(TestUtils.LoadTest1().ToString(), test1.ToXml().ToString()); }