コード例 #1
0
        protected QtTranslation(XmlDocument document) : base(new Dictionary <string, QtTranslationContext>())
        {
            XmlElement ts = document.FirstElement("TS");

            if (ts == null)
            {
                throw new QtTranslationException("Invalid Translation file. The root node isn't 'TS'.");
            }
            if (!ts.HasAttribute("language"))
            {
                throw QtTranslationException.InvalideNoNodeFound("TS", "language");
            }
            if (!ts.HasAttribute("version"))
            {
                throw QtTranslationException.InvalideNoNodeFound("TS", "version");
            }
            if (ts.GetAttribute("version") != "2.1")
            {
                throw new QtTranslationException("Unsuported version of QtTranslation file.\nThe 2.1 version is the only supported.");
            }

            try
            {
                Language = CultureInfo.GetCultureInfo(ts.GetAttribute("language"));
                Version  = new VersionClass(ts.GetAttribute("version"));
            }
            catch (Exception ex)
            {
                throw new QtTranslationException(ex);
            }

            XmlElement[] context = ts.GetElements("context");
            if (context.Length == 0)
            {
                throw QtTranslationException.InvalideNoNodeFound("context");
            }

            foreach (XmlElement item in context)
            {
                try
                {
                    AddContext(new QtTranslationContext(item));
                }
                catch
                {
                }
            }
        }
コード例 #2
0
        internal QtTranslationMessage(XmlElement message)
        {
            XmlElement location = message.FirstElement("location");

            if (location == null)
            {
                throw QtTranslationException.InvalideNoNodeFound("location");
            }
            if (!location.HasAttribute("filename"))
            {
                throw QtTranslationException.InvalideNoNodeFound("location", "filename");
            }
            if (!location.HasAttribute("line"))
            {
                throw QtTranslationException.InvalideNoNodeFound("location", "line");
            }

            foreach (XmlElement item in message.EnumerableElement("location"))
            {
                Locations.Add(new QtTranslationLocation(item.GetAttribute("filename"), int.Parse(item.GetAttribute("line"))));
            }

            XmlElement source = message.FirstElement("source");

            if (source == null)
            {
                throw QtTranslationException.InvalideNoNodeFound("source");
            }

            XmlElement translation = message.FirstElement("translation");

            if (translation == null)
            {
                throw QtTranslationException.InvalideNoNodeFound("translation");
            }

            Source      = source.InnerText;
            Translation = translation.InnerText;

            XmlElement comment = message.FirstElement("comment");

            if (comment != null && !comment.InnerText.IsNullOrWhiteSpace())
            {
                Comment = comment.InnerText;
            }
        }
コード例 #3
0
        internal QtTranslationContext(XmlElement element) : this()
        {
            XmlElement name = element.LastElement("name");

            if (name == null)
            {
                throw QtTranslationException.InvalideNoNodeFound("name");
            }

            Name = name.InnerText.Trim();

            foreach (var item in element.GetElements("message"))
            {
                try
                {
                    AddMessage(new QtTranslationMessage(item));
                }
                catch (Exception)
                {
                }
            }
        }