示例#1
0
        public void NewStringsAdded()
        {
            using (var testDir = new TemporaryFolder(GetType().Name))
            {
                var poFile = testDir.Combine("mesages.de.po");
                File.WriteAllText(poFile, DePoData);
                var stringsFile = testDir.Combine("strings-de.xml");
                File.WriteAllText(stringsFile, DeStringsData);

                // SUT
                PoToXml.StoreLocalizedStrings(poFile, stringsFile, null);

                var result = File.ReadAllText(stringsFile);
                // The resulting file should contain the 5 original groups plus 3 new (attributes, literals, context help)
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath("/strings/group", 8);
                const string attGroupXpath = "/strings/group[@id='LocalizedAttributes']";
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(attGroupXpath, 1);
                const string attStringXpath = attGroupXpath + "/string";
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(attStringXpath, 6);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    attStringXpath + "[@id='Abbreviation (Best Analysis)' and @txt='Abkürzung (Bestes Analyse)']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    attStringXpath + "[@id='Allomorph' and @txt='Allomorph']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    attStringXpath + "[@id='Choose {0}' and @txt='{0} wählen']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    attStringXpath + "[@id='Comment' and @txt='Kommentar']", 1);
                const string litGroupXpath = "/strings/group[@id='LocalizedLiterals']";
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(litGroupXpath, 1);
                const string litStringXpath = litGroupXpath + "/string";
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(litStringXpath, 2);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    litStringXpath + "[@id='Allomorph' and @txt='Allomorph']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    litStringXpath + "[@id='Analysis ' and @txt='Analyse ']", 1);
                const string helpGroupXpath = "/strings/group[@id='LocalizedContextHelp']";
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(helpGroupXpath, 1);
                const string helpStringXpath = helpGroupXpath + "/string";
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(helpStringXpath, 5);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    helpStringXpath + "[@id='AllomorphAdjacency']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    helpStringXpath + "[@id='AllomorphAdjacency' and @txt='Klicken Sie auf die Taste.']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    helpStringXpath + "[@id='CmdInsertCustomItem' and @txt='Ein neues {0} erstellen.']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    helpStringXpath + "[@id='CmdInsertLexEntryType' and @txt='Ein neues {0} erstellen.']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    helpStringXpath + "[@id='CmdInsertPossibility' and @txt='Ein neues {0} erstellen.']", 1);
                AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
                    helpStringXpath + "[@id='CmdCreateProjectShortcut' and @txt='Eine Desktop-Verknüpfung zu diesem Projekt erstellen.']", 1);
            }
        }
示例#2
0
        public void TestWriteAndReadPoFile()
        {
            var poStrings   = new List <POString>();
            var fwLayoutDoc = XDocument.Parse(FwlayoutData);

            Assert.IsNotNull(fwLayoutDoc.Root);
            XmlToPo.ProcessConfigElement(fwLayoutDoc.Root, "/Language Explorer/Configuration/Parts/LexEntry.fwlayout", poStrings);
            var fwDictConfigDoc = XDocument.Parse(DictConfigData);

            Assert.IsNotNull(fwDictConfigDoc.Root);
            XmlToPo.ProcessFwDictConfigElement(fwDictConfigDoc.Root, "/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig", poStrings);
            Assert.AreEqual(53, poStrings.Count);
            Assert.AreEqual("Lexeme Form", poStrings[0].MsgIdAsString());
            Assert.AreEqual("modified on: ", poStrings[49].MsgIdAsString());
            poStrings.Sort(POString.CompareMsgIds);
            // SUT
            POString.MergeDuplicateStrings(poStrings);
            Assert.AreEqual(40, poStrings.Count);
            Assert.AreEqual(" - ", poStrings[0].MsgIdAsString());
            Assert.AreEqual("Variants", poStrings[39].MsgIdAsString());
            var sw = new StringWriter();

            XmlToPo.WritePotFile(sw, "/home/testing/fw", poStrings);
            var potFileStr = sw.ToString();

            Assert.IsNotNull(potFileStr);
            var sr      = new StringReader(potFileStr);
            var dictPot = PoToXml.ReadPoFile(sr, null);

            Assert.AreEqual(40, dictPot.Count);
            var listPot = dictPot.ToList();

            Assert.AreEqual(" - ", listPot[0].Value.MsgIdAsString());
            Assert.AreEqual("Variants", listPot[39].Value.MsgIdAsString());

            var posHeadword = dictPot["Headword"];

            Assert.AreEqual(6, posHeadword.AutoComments.Count, "Headword AutoComments");
            Assert.AreEqual("/Language Explorer/Configuration/Parts/LexEntry.fwlayout::/LayoutInventory/layout[\"LexEntry-jtview-CrossRefPub\"]/part[@ref=\"MLHeadWordPub\"]/@label", posHeadword.AutoComments[0]);
            Assert.AreEqual("/Language Explorer/Configuration/Parts/LexEntry.fwlayout::/LayoutInventory/layout[\"LexEntry-jtview-SubentryUnderPub\"]/part[@ref=\"MLHeadWordPub\"]/@label", posHeadword.AutoComments[1]);
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Main Entry']/ConfigurationItem/@name", posHeadword.AutoComments[2]);
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='MainEntrySubentries']/ConfigurationItem/@name", posHeadword.AutoComments[3]);
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Minor Entry (Complex Forms)']/ConfigurationItem/@name", posHeadword.AutoComments[4]);
            Assert.AreEqual("(String used 5 times.)", posHeadword.AutoComments[5]);

            var posComma = dictPot[", "];

            Assert.AreEqual(4, posComma.AutoComments.Count, "AutoCommas");
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Allomorphs']/@between", posComma.AutoComments[0]);
            Assert.AreEqual("(String used 3 times.)", posComma.AutoComments[3]);
        }
示例#3
0
        public void StringsPreserved()
        {
            using (var testDir = new TemporaryFolder(GetType().Name))
            {
                var poFile = testDir.Combine("mesages.de.po");
                File.WriteAllText(poFile, DePoData);
                var stringsFile = testDir.Combine("strings-de.xml");
                File.WriteAllText(stringsFile, DeStringsData);

                // SUT
                PoToXml.StoreLocalizedStrings(poFile, stringsFile, null);

                var fullFileContent = File.ReadAllText(stringsFile);
                AssertThatXmlStartsWith(XDocument.Parse(DeStringsData).Root, XDocument.Parse(fullFileContent).Root);
                Assert.Greater(fullFileContent.Length, DeStringsData.Length + 640,
                               "The resulting file should be considerably longer than the original. 640 characters ought to be enough (for anyone).");
            }
        }
示例#4
0
 public void FindContextHelpId(string comment, string id)
 {
     Assert.AreEqual(id, PoToXml.FindContextHelpId(comment));
 }
示例#5
0
        public void ReadPoData()
        {
            var srIn         = new StringReader(FrenchPoData);
            var dictFrenchPo = PoToXml.ReadPoFile(srIn, null);
            var rgsPoStrings = dictFrenchPo.ToList();
            var postr0       = rgsPoStrings[0].Value;

            Assert.IsNotNull(postr0, "French po string[0] has data");
            Assert.IsNotNull(postr0.MsgId, "French po string[0] has MsgId data");
            Assert.AreEqual(1, postr0.MsgId.Count, "French po string[0] has one line of MsgId data");
            Assert.AreEqual(" - ", postr0.MsgId[0], "French po string[0] has the expected MsgId data");
            Assert.AreEqual(" - ", postr0.MsgIdAsString(), "French po string[0] is ' - '");
            Assert.AreEqual(1, postr0.MsgStr.Count, "French po string[0] has one line of MsgStr data");
            Assert.AreEqual(" - ", postr0.MsgStr[0], "French po string[0] MsgStr is ' - '");
            Assert.IsNull(postr0.UserComments, "French po string[0] has no User Comments (as expected)");
            Assert.IsNull(postr0.References, "French po string[0] has no Reference data (as expected)");
            Assert.IsNull(postr0.Flags, "French po string[0] has no Flags data (as expected)");
            Assert.IsNotNull(postr0.AutoComments, "French po string[0] has Auto Comments");
            Assert.AreEqual(3, postr0.AutoComments.Count, "French po string[0] has three lines of Auto Comments");
            Assert.AreEqual("separate name and abbreviation (space dash space)", postr0.AutoComments[0], "French po string[0] has the expected first line of Auto Comment");

            var postr5 = rgsPoStrings[5].Value;

            Assert.IsNotNull(postr5, "French po string[5] has data");
            Assert.IsNotNull(postr5.MsgId, "French po string[5] has MsgId data");
            Assert.AreEqual(1, postr5.MsgId.Count, "French po string[5] has one line of MsgId data");
            Assert.AreEqual("Academic Domain", postr5.MsgId[0], "French po string[5] has the expected MsgId data");
            Assert.AreEqual("Academic Domain", postr5.MsgIdAsString(), "French po string[5] is 'Academic Domain'");
            Assert.AreEqual(1, postr5.MsgStr.Count, "French po string[5] has one line of MsgStr data");
            Assert.AreEqual("Domaine technique", postr5.MsgStr[0], "French po string[5] has the expected MsgStr data");
            Assert.IsNotNull(postr5.UserComments, "French po string[5] has User Comments");
            Assert.AreEqual(1, postr5.UserComments.Count, "French po string[5] has one line of User Comments");
            Assert.AreEqual("JDX:JN", postr5.UserComments[0], "French po string[5] has the expected User Comment");
            Assert.IsNull(postr5.References, "French po string[5] has no Reference data (as expected)");
            Assert.IsNull(postr5.Flags, "French po string[5] has no Flags data (as expected)");
            Assert.IsNotNull(postr5.AutoComments, "French po string[5] has Auto Comments");
            Assert.AreEqual(1, postr5.AutoComments.Count, "French po string[5] has one line of Auto Comments");
            Assert.AreEqual("/|strings-en.xml::/PossibilityListItemTypeNames/DomainTypes|", postr5.AutoComments[0], "French po string[5] has the expected Auto Comment");

            var postr48 = rgsPoStrings[48].Value;

            Assert.IsNotNull(postr48, "French po string[48] has data");
            Assert.IsNotNull(postr48.MsgId, "French po string[48] has MsgId data");
            Assert.AreEqual(1, postr48.MsgId.Count, "French po string[48] has one line of MsgId data");
            Assert.AreEqual("You still have {0} difference(s) left.  Are you sure you want to exit?", postr48.MsgId[0], "French po string[48] has the expected MsgId data");
            Assert.AreEqual("You still have {0} difference(s) left.  Are you sure you want to exit?", postr48.MsgIdAsString(),
                            "French po string[48] is 'You still have {0} difference(s) left.  Are you sure you want to exit?'");
            Assert.AreEqual(1, postr48.MsgStr.Count, "French po string[48] has one line of MsgStr data");
            Assert.AreEqual("Il reste {0} différences. Êtes-vous sûr de vouloir quitter?", postr48.MsgStr[0], "French po string[48] has the expected MsgStr data");
            Assert.IsNotNull(postr48.UserComments, "French po string[48] has User Comments");
            Assert.AreEqual(1, postr48.UserComments.Count, "French po string[48] has one line of User Comments");
            Assert.AreEqual("JDX", postr48.UserComments[0], "French po string[48] has the expected User Comment");
            Assert.IsNull(postr48.References, "French po string[48] has no Reference data (as expected)");
            Assert.IsNull(postr48.Flags, "French po string[48] has no Flags data (as expected)");
            Assert.IsNotNull(postr48.AutoComments, "French po string[48] has Auto Comments");
            Assert.AreEqual(2, postr48.AutoComments.Count, "French po string[48] has two lines of Auto Comments");
            Assert.AreEqual("This text will be displayed if a user tries to exit the diff dialog before all the differences have been taken care of.",
                            postr48.AutoComments[0], "French po string[48] has the expected first line of Auto Comment");
            Assert.AreEqual("/Src/TE/TeResources/TeStrings.resx::kstidExitDiffMsg",
                            postr48.AutoComments[1], "French po string[48] has the expected second line of Auto Comment");

            var postr49 = rgsPoStrings[49].Value;

            Assert.IsNotNull(postr49, "French po string[49] has data");
            Assert.IsNotNull(postr49.MsgId, "French po string[49] has MsgId data");
            Assert.AreEqual(1, postr49.MsgId.Count, "French po string[49] has one line of MsgId data");
            Assert.AreEqual("You don't know how to translate this yet do you?", postr49.MsgId[0], "French po string[49] has the expected MsgId data");
            Assert.AreEqual("Que?", postr49.MsgStrAsString());
            Assert.IsNotNull(postr49.Flags);
            Assert.AreEqual(postr49.Flags[0], "fuzzy");
            Assert.AreEqual(50, dictFrenchPo.Count);
        }