Beispiel #1
0
        public override AXmlResourceItem Clone()
        {
            var cloneObj = new AXmlPlural()
            {
                Name = this.Name,
            };

            cloneObj.Comments.AddRange(this.Comments);

            foreach (var item in this.Items)
            {
                cloneObj.Items.Add(item.Key, item.Value.Clone());
            }

            return(cloneObj);
        }
        public static AXmlResource ReadAXml(string path)
        {
            AXmlResource  res = null;
            DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path));

            string[] folderParts = dir.Name.Split('-');

            using (XmlReader reader = XmlReader.Create(path, new XmlReaderSettings()
            {
                IgnoreComments = false
            }))
            {
                res = new AXmlResource();
                AXmlPlural    xmlPlural       = null;
                bool          resourceContent = false;
                List <string> comments        = new List <string>();
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Comment)
                    {
                        comments.Add(reader.Value.Trim());
                        continue;
                    }
                    if (reader.IsStartElement())
                    {
                        if (reader.Name == N_RESOURCE)
                        {
                            resourceContent = true;
                            continue;
                        }
                    }
                    if (!resourceContent)
                    {
                        continue;
                    }

                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (reader.Name == N_PLURALS)
                        {
                            xmlPlural = null;
                            continue;
                        }
                        else if (reader.Name == N_RESOURCE)
                        {
                            resourceContent = false;
                            continue;
                        }
                    }

                    if (reader.IsStartElement())
                    {
                        if (reader.Name == N_STRING)
                        {
                            AXmlString xmlString = new AXmlString();
                            xmlString.Name = reader.GetAttribute(A_NAME);
                            if (comments.Count > 0)
                            {
                                xmlString.Comments.AddRange(comments);
                                comments.Clear();
                            }
                            string trans = reader.GetAttribute(A_TRANSLATABLE);
                            if (!string.IsNullOrEmpty(trans))
                            {
                                xmlString.IsTranslatable = Convert.ToBoolean(trans);
                            }
                            xmlString.Value = reader.ReadElementContentAsString();
                            res.Add(xmlString);
                            continue;
                        }
                        else if (reader.Name == N_PLURALS)
                        {
                            xmlPlural      = new AXmlPlural();
                            xmlPlural.Name = reader.GetAttribute(A_NAME);
                            if (comments.Count > 0)
                            {
                                xmlPlural.Comments.AddRange(comments);
                                comments.Clear();
                            }
                            res.Add(xmlPlural);
                            continue;
                        }
                        else if (reader.Name == N_ITEM)
                        {
                            if (xmlPlural == null)
                            {
                                continue;
                            }

                            AXmlPluralItem item = new AXmlPluralItem();
                            item.Quantity = (QuantityType)Enum.Parse(typeof(QuantityType), reader.GetAttribute(A_QUANTITY));
                            item.Value    = reader.ReadElementContentAsString();

                            xmlPlural.Add(item);
                        }
                    }
                }
            }

            if (res != null)
            {
                res.FolderParts = folderParts;
            }

            return(res);
        }