Пример #1
0
        /// <summary>
        /// Parse a localization string into a WixVariableRow.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private static void ParseString(IMessaging messaging, XElement node, IDictionary <string, BindVariable> variables)
        {
            string           id                = null;
            bool             overridable       = false;
            SourceLineNumber sourceLineNumbers = SourceLineNumber.CreateFromXObject(node);

            foreach (XAttribute attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || LocalizationParser.WxlNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Id":
                        id = Common.GetAttributeIdentifierValue(messaging, sourceLineNumbers, attrib);
                        break;

                    case "Overridable":
                        overridable = YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib);
                        break;

                    case "Localizable":
                        ;     // do nothing
                        break;

                    default:
                        messaging.Write(ErrorMessages.UnexpectedAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString()));
                        break;
                    }
                }
                else
                {
                    messaging.Write(ErrorMessages.UnsupportedExtensionAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString()));
                }
            }

            string value = Common.GetInnerText(node);

            if (null == id)
            {
                messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, "String", "Id"));
            }
            else if (0 == id.Length)
            {
                messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, "String", "Id", 0));
            }

            if (!messaging.EncounteredError)
            {
                var variable = new BindVariable
                {
                    SourceLineNumbers = sourceLineNumbers,
                    Id          = id,
                    Overridable = overridable,
                    Value       = value,
                };

                LocalizationParser.AddWixVariable(messaging, variables, variable);
            }
        }
Пример #2
0
        /// <summary>
        /// Parses the WixLocalization element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private static Localization ParseWixLocalizationElement(IMessaging messaging, XElement node)
        {
            int              codepage          = -1;
            string           culture           = null;
            SourceLineNumber sourceLineNumbers = SourceLineNumber.CreateFromXObject(node);

            foreach (XAttribute attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || LocalizationParser.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(messaging, sourceLineNumbers, attrib);
                        break;
                    }
                }
                else
                {
                    Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib);
                }
            }

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

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

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

                    default:
                        messaging.Write(ErrorMessages.UnexpectedElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString()));
                        break;
                    }
                }
                else
                {
                    messaging.Write(ErrorMessages.UnsupportedExtensionElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString()));
                }
            }

            return(messaging.EncounteredError ? null : new Localization(codepage, culture, variables, localizedControls));
        }