string DumpLines(PoReader reader) { StringWriter writer = new StringWriter(); PoReader.PoLine line; while ((line = reader.ReadLine()) != null) { writer.Write("{0}: ", reader.lineNumber); switch (line.kind) { case PoReader.PoLineKind.Blank: writer.WriteLine("blank"); break; case PoReader.PoLineKind.Comment: writer.WriteLine("comment"); break; case PoReader.PoLineKind.LocationComment: writer.WriteLine("location: {0},{1}", line.str1, line.str2); break; case PoReader.PoLineKind.KeywordString: writer.WriteLine("kw({0}): '{1}'", line.str1, line.str2); break; case PoReader.PoLineKind.String: writer.WriteLine("str: '{0}'", line.str1); break; default: writer.WriteLine("unknown"); break; } } writer.WriteLine("EOF"); return(writer.ToString()); }
public void issue_24_1() { var a = new PoReader().Read(Path.Combine(IDIR, "issue24.po"), -1).Assets.ToArray(); a.Length.Is(1); a[0].TransPairs.Count().Is(2); var p = a[0].TransPairs.ToArray(); p[0].Source.ToString().Is("foo"); p[0].Target.ToString().Is(""); p[0].Notes.Count().Is(1); p[0].Notes.ElementAt(0).Is("abc"); p[1].Source.ToString().Is("bar"); p[1].Target.ToString().Is(""); p[1].Notes.Count().Is(1); p[1].Notes.ElementAt(0).Is("def"); }
public void ReadSamplePoEntries() { PoReader reader = new PoReader(GetTestFile("SamplePo.po")); List <PoEntry> entries = reader.ReadPo(); StringWriter writer = new StringWriter(); foreach (PoEntry entry in entries) { writer.WriteLine("====Entry==="); writer.WriteLine("English: '{0}'", entry.NonLocalized); writer.WriteLine("Translated: '{0}'", entry.Localized); writer.WriteLine("Locations:"); foreach (PoLocation location in entry.Locations) { writer.WriteLine(" {0},{1}", location.FileName, location.Name); } } string result = writer.ToString(); string expected = @"====Entry=== English: 'Purple Pen is free software and may be copied and shared.' Translated: 'Purple Pen est un logiciel libre et peut être copié et partagé.' Locations: AboutForm.resx,freeLabel.Text ====Entry=== English: 'View Full License' Translated: 'Voir la licence complète' Locations: AboutForm.resx,okButton.Text AddCourse.resx,okButton.Text ====Entry=== English: 'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ' Translated: 'CE LOGICIEL EST FOURNI ""TEL QUEL"" PAR LES DÉTENTEURS DU COPYRIGHT ET PAR LES CONTRIBUTEURS. TOUTES GARANTIES EXPLICITES OU IMPLICITES (INCLUANT, MAIS ' Locations: AboutForm.resx,disclaimerLabel.Text "; Assert.AreEqual(expected, result); }
public void ConvertQuotedString() { string result; result = PoReader.ConvertQuotedString(@" hello "); Assert.AreEqual(" hello ", result); result = PoReader.ConvertQuotedString(@" h\nllo "); Assert.AreEqual(" h\r\nllo ", result); result = PoReader.ConvertQuotedString(@" hello\"""); Assert.AreEqual(" hello\"", result); result = PoReader.ConvertQuotedString(@" he\\\\llo "); Assert.AreEqual(" he\\\\llo ", result); result = PoReader.ConvertQuotedString(@" he\0llo "); Assert.AreEqual(" he\0llo ", result); result = PoReader.ConvertQuotedString(@" he\0176llo "); Assert.AreEqual(" he\x7ello ", result); }
public void ReadSamplePoLines() { PoReader reader = new PoReader(GetTestFile("SamplePo.po")); string result = DumpLines(reader); string expected = @"1: comment 2: comment 3: comment 4: kw(msgid): '' 5: kw(msgstr): '' 6: str: 'Project-Id-Version: purple-pen ' 7: str: 'Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS> ' 8: blank 9: location: AboutForm.resx,freeLabel.Text 10: kw(msgid): 'Purple Pen is free software and may be copied and shared.' 11: kw(msgstr): 'Purple Pen est un logiciel libre et peut être copié et partagé.' 12: blank 13: location: AboutForm.resx,okButton.Text 14: location: AddCourse.resx,okButton.Text 15: kw(msgid): 'View Full License' 16: kw(msgstr): 'Voir la licence complète' 17: blank 18: blank 19: blank 20: location: AboutForm.resx,disclaimerLabel.Text 21: kw(msgid): '' 22: str: 'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS ' 23: str: 'IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ' 24: kw(msgstr): '' 25: str: 'CE LOGICIEL EST FOURNI ""TEL QUEL"" PAR LES DÉTENTEURS DU COPYRIGHT ET PAR ' 26: str: 'LES CONTRIBUTEURS. TOUTES GARANTIES EXPLICITES OU IMPLICITES (INCLUANT, MAIS ' EOF "; Assert.AreEqual(expected, result); }