예제 #1
0
        /// <summary>
        /// Parses the WixLocalization element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private static Localization ParseWixLocalizationElement(XElement node, TableDefinitionCollection tableDefinitions)
        {
            int              codepage          = -1;
            string           culture           = null;
            SourceLineNumber sourceLineNumbers = SourceLineNumber.CreateFromXObject(node);

            foreach (XAttribute attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || Localizer.WxlNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Codepage":
                        codepage = Common.GetValidCodePage(attrib.Value, true, false, sourceLineNumbers);
                        break;

                    case "Culture":
                        culture = attrib.Value;
                        break;

                    case "Language":
                        // do nothing; @Language is used for locutil which can't convert Culture to lcid
                        break;

                    default:
                        Common.UnexpectedAttribute(sourceLineNumbers, attrib);
                        break;
                    }
                }
                else
                {
                    Common.UnexpectedAttribute(sourceLineNumbers, attrib);
                }
            }

            Dictionary <string, WixVariableRow>   variables         = new Dictionary <string, WixVariableRow>();
            Dictionary <string, LocalizedControl> localizedControls = new Dictionary <string, LocalizedControl>();

            foreach (XElement child in node.Elements())
            {
                if (Localizer.WxlNamespace == child.Name.Namespace)
                {
                    switch (child.Name.LocalName)
                    {
                    case "String":
                        Localizer.ParseString(child, variables, tableDefinitions);
                        break;

                    case "UI":
                        Localizer.ParseUI(child, localizedControls);
                        break;

                    default:
                        Messaging.Instance.OnMessage(WixErrors.UnexpectedElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString()));
                        break;
                    }
                }
                else
                {
                    Messaging.Instance.OnMessage(WixErrors.UnsupportedExtensionElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString()));
                }
            }

            return(Messaging.Instance.EncounteredError ? null : new Localization(codepage, culture, variables, localizedControls));
        }
예제 #2
0
        /// <summary>
        /// Parses the WixLocalization element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private void ParseWixLocalizationElement(XElement node)
        {
            int              codepage          = -1;
            string           culture           = null;
            SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);

            foreach (XAttribute attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || Localization.WxlNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Codepage":
                        codepage = Common.GetValidCodePage(attrib.Value, true);
                        break;

                    case "Culture":
                        culture = attrib.Value;
                        break;

                    case "Language":
                        // do nothing; @Language is used for locutil which can't convert Culture to lcid
                        break;

                    default:
                        Common.UnexpectedAttribute(sourceLineNumbers, attrib, Localization.OnMessage);
                        break;
                    }
                }
                else
                {
                    Common.UnsupportedExtensionAttribute(sourceLineNumbers, attrib, Localization.OnMessage);
                }
            }

            this.codepage = codepage;
            this.culture  = String.IsNullOrEmpty(culture) ? String.Empty : culture.ToLower(CultureInfo.InvariantCulture);

            foreach (XElement child in node.Elements())
            {
                if (Localization.WxlNamespace == child.Name.Namespace)
                {
                    switch (child.Name.LocalName)
                    {
                    case "String":
                        this.ParseString(child);
                        break;

                    case "UI":
                        this.ParseUI(child);
                        break;

                    default:
                        throw new WixException(WixErrors.UnexpectedElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString()));
                    }
                }
                else
                {
                    throw new WixException(WixErrors.UnsupportedExtensionElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString()));
                }
            }
        }