Example #1
0
        public void TestYMLBackSlashValue()
        {
            string      filename       = PathToTestData + "testBackslash.yml";
            string      backslashValue = "data\\Kontoauszuege\\test.csv";
            TYml2Xml    converterYml   = new TYml2Xml(filename);
            XmlDocument docFromYML     = converterYml.ParseYML2XML();

            XmlNode node = TXMLParser.FindNodeRecursive(docFromYML.DocumentElement, "testname");

            Assert.AreEqual(backslashValue, TXMLParser.GetAttribute(node, "Filename"));

            // does writing of the backslash value work as well?
            TXMLParser.SetAttribute(node, "Filename", backslashValue);
            TYml2Xml.Xml2Yml(docFromYML, filename + ".new");

            Assert.AreEqual(true, TTextFile.SameContent(filename,
                                                        filename + ".new"), "the files should be the same: " + filename);
            System.IO.File.Delete(filename + ".new");
        }
Example #2
0
        private static void ProcessRadioGroupLabels(XmlNode node)
        {
            StringCollection optionalValues =
                TYml2Xml.GetElements(TXMLParser.GetChild(node, "OptionalValues"));

            node.RemoveAll();
            XmlNode OptionalValuesLabel = node.OwnerDocument.CreateElement("LabelsForOptionalValues");

            node.AppendChild(OptionalValuesLabel);

            foreach (string s in optionalValues)
            {
                string label = s;

                if (label.StartsWith("="))
                {
                    label = label.Substring(1).Trim();
                }

                XmlNode LabelNode = node.OwnerDocument.CreateElement(TYml2Xml.XMLLIST);
                OptionalValuesLabel.AppendChild(LabelNode);
                TXMLParser.SetAttribute(LabelNode, "name", Catalog.GetString(label));
            }
        }
Example #3
0
        private static void CreateLocalisedYamlFile(string ALanguageCode, string AYamlfile)
        {
            TLogging.Log(AYamlfile);

            string localisedYamlFile = AYamlfile.Replace(".yaml", "." + ALanguageCode + ".yaml");

            TYml2Xml    parser;
            XmlDocument localisedYamlFileDoc = new XmlDocument();

            if (File.Exists(localisedYamlFile))
            {
                // TODO parse the localised yaml file and add translations to the po file
                parser = new TYml2Xml(localisedYamlFile);
                localisedYamlFileDoc = parser.ParseYML2XML();
            }

            // parse the yaml file
            parser = new TYml2Xml(AYamlfile);
            XmlDocument yamlFile = parser.ParseYML2XML();

            SortedList   xmlNodes    = new SortedList();
            TCodeStorage CodeStorage = new TCodeStorage(yamlFile, xmlNodes);

            XmlNode RootNode = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "RootNode");

            RootNode.Attributes.RemoveAll();
            TXMLParser.SetAttribute(RootNode, "BaseYaml", Path.GetFileName(AYamlfile));

            // get controls node
            XmlNode Controls = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Controls");

            if (Controls != null)
            {
                foreach (XmlNode control in Controls)
                {
                    AdjustLabel(control, CodeStorage, localisedYamlFileDoc);
                }
            }

            // get actions node
            XmlNode Actions = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Actions");

            if (Actions != null)
            {
                foreach (XmlNode action in Actions)
                {
                    AdjustLabel(action, CodeStorage, localisedYamlFileDoc);
                }
            }

            // menu items
            XmlNode menuitems = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Menu");

            if (menuitems != null)
            {
                foreach (XmlNode menu in menuitems)
                {
                    if (menu.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(menu, CodeStorage, localisedYamlFileDoc);
                }
            }

            // toolbar buttons
            XmlNode tbbuttons = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Toolbar");

            if (tbbuttons != null)
            {
                foreach (XmlNode tbb in tbbuttons)
                {
                    if (tbb.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(tbb, CodeStorage, localisedYamlFileDoc);
                }
            }

            // TODO parse the cs file for string constants
            // TODO warn about Catalog.GetString calls in manualcode file
            // TODO add constants to localised yaml file

            TYml2Xml.Xml2Yml(yamlFile, localisedYamlFile);
        }
Example #4
0
        private static void AdjustLabel(XmlNode node, TCodeStorage CodeStorage, XmlDocument AOrigLocalisedYaml)
        {
            XmlNode TranslatedNode  = TXMLParser.FindNodeRecursive(AOrigLocalisedYaml, node.Name);
            string  TranslatedLabel = string.Empty;

            if (TranslatedNode != null)
            {
                TranslatedLabel = TXMLParser.GetAttribute(TranslatedNode, "Label");
            }

            TControlDef ctrlDef = new TControlDef(node, CodeStorage);
            string      Label   = ctrlDef.Label;

            if ((ctrlDef.GetAttribute("NoLabel") == "true") || (ctrlDef.controlTypePrefix == "pnl") ||
                (TXMLParser.FindNodeRecursive(node.OwnerDocument, "act" + ctrlDef.controlName.Substring(ctrlDef.controlTypePrefix.Length)) != null) ||
                ctrlDef.GetAttribute("Action").StartsWith("act"))
            {
                Label = string.Empty;
            }

            if ((ctrlDef.controlTypePrefix == "rgr") && (TXMLParser.GetChild(node, "OptionalValues") != null))
            {
                ProcessRadioGroupLabels(node);
            }
            else if (ctrlDef.controlTypePrefix == "mni")
            {
                // drop all attributes
                node.Attributes.RemoveAll();

                foreach (XmlNode menu in node.ChildNodes)
                {
                    if (menu.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(menu, CodeStorage, AOrigLocalisedYaml);
                }
            }
            else
            {
                // drop all attributes and children nodes
                node.RemoveAll();
            }

            if (Label.Length > 0)
            {
                if ((TranslatedLabel != Label) && (TranslatedLabel != Catalog.GetString(Label)) && (TranslatedLabel.Length > 0))
                {
                    // add to po file
                    if (!NewTranslations.ContainsKey(Label))
                    {
                        NewTranslations.Add(Label, TranslatedLabel);
                    }

                    TXMLParser.SetAttribute(node, "Label", TranslatedLabel);
                }
                else
                {
                    TXMLParser.SetAttribute(node, "Label", Catalog.GetString(Label));
                }
            }
        }