// Token: 0x06006EC1 RID: 28353 RVA: 0x001FD7E4 File Offset: 0x001FB9E4
        private static LocalizabilityGroup LookupAndSetLocalizabilityAttribute(string input)
        {
            LocalizabilityGroup localizabilityGroup = new LocalizabilityGroup();
            StringBuilder       stringBuilder       = new StringBuilder();

            for (int i = 0; i < input.Length; i++)
            {
                if (char.IsWhiteSpace(input[i]))
                {
                    if (stringBuilder.Length > 0)
                    {
                        LocComments.ParseLocalizabilityString(stringBuilder.ToString(), localizabilityGroup);
                        stringBuilder = new StringBuilder();
                    }
                }
                else
                {
                    stringBuilder.Append(input[i]);
                }
            }
            if (stringBuilder.Length > 0)
            {
                LocComments.ParseLocalizabilityString(stringBuilder.ToString(), localizabilityGroup);
            }
            return(localizabilityGroup);
        }
        private void GetLocalizabilityForElementNode(
            BamlStartElementNode node,
            out LocalizabilityAttribute localizability,
            out string formattingTag
            )
        {
            localizability = null;
            formattingTag  = null;

            // get the names we need
            string assemblyName = node.AssemblyName;
            string className    = node.TypeFullName;

            // query the resolver
            ElementLocalizability result = _resolver.GetElementLocalizability(
                assemblyName,
                className
                );

            LocalizabilityGroup comment = null;

            comment = _resolver.GetLocalizabilityComment(node, BamlConst.ContentSuffix);

            if (comment != null)
            {
                localizability = comment.Override(result.Attribute);
            }
            else
            {
                localizability = result.Attribute;
            }

            formattingTag = result.FormattingTag;
        }
Exemple #3
0
        private static void ParseLocalizabilityString(
            string value,
            LocalizabilityGroup attributeGroup
            )
        {
            int enumValue;

            if (ReadabilityIndexTable.TryGet(value, out enumValue))
            {
                attributeGroup.Readability = (Readability)enumValue;
                return;
            }

            if (ModifiabilityIndexTable.TryGet(value, out enumValue))
            {
                attributeGroup.Modifiability = (Modifiability)enumValue;
                return;
            }

            if (LocalizationCategoryIndexTable.TryGet(value, out enumValue))
            {
                attributeGroup.Category = (LocalizationCategory)enumValue;
                return;
            }

            throw new FormatException(SR.Get(SRID.InvalidLocalizabilityValue, value));
        }
        // Token: 0x06006EB6 RID: 28342 RVA: 0x001FCF00 File Offset: 0x001FB100
        internal bool TryGetContent(BamlLocalizableResourceKey key, BamlTreeNode currentNode, out string content)
        {
            content = string.Empty;
            BamlNodeType nodeType = currentNode.NodeType;

            if (nodeType == BamlNodeType.StartElement)
            {
                BamlStartElementNode bamlStartElementNode = (BamlStartElementNode)currentNode;
                if (bamlStartElementNode.Content == null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (BamlTreeNode bamlTreeNode in bamlStartElementNode.Children)
                    {
                        nodeType = bamlTreeNode.NodeType;
                        if (nodeType != BamlNodeType.StartElement)
                        {
                            if (nodeType == BamlNodeType.Text)
                            {
                                stringBuilder.Append(BamlResourceContentUtil.EscapeString(((BamlTextNode)bamlTreeNode).Content));
                            }
                        }
                        else
                        {
                            string value;
                            if (!this.TryFormatElementContent(key, (BamlStartElementNode)bamlTreeNode, out value))
                            {
                                return(false);
                            }
                            stringBuilder.Append(value);
                        }
                    }
                    bamlStartElementNode.Content = stringBuilder.ToString();
                }
                content = bamlStartElementNode.Content;
                return(true);
            }
            if (nodeType == BamlNodeType.Property)
            {
                bool             result           = true;
                BamlPropertyNode bamlPropertyNode = (BamlPropertyNode)currentNode;
                content = BamlResourceContentUtil.EscapeString(bamlPropertyNode.Value);
                string text = content;
                string text2;
                string text3;
                if (MarkupExtensionParser.GetMarkupExtensionTypeAndArgs(ref text, out text2, out text3))
                {
                    LocalizabilityGroup localizabilityComment = this._resolver.GetLocalizabilityComment(bamlPropertyNode.Parent as BamlStartElementNode, bamlPropertyNode.PropertyName);
                    result = (localizabilityComment != null && localizabilityComment.Readability == Readability.Readable);
                }
                return(result);
            }
            if (nodeType != BamlNodeType.LiteralContent)
            {
                return(true);
            }
            content = BamlResourceContentUtil.EscapeString(((BamlLiteralContentNode)currentNode).Content);
            return(true);
        }
        // Token: 0x06006EB8 RID: 28344 RVA: 0x001FD1C4 File Offset: 0x001FB3C4
        private void GetLocalizabilityForElementNode(BamlStartElementNode node, out LocalizabilityAttribute localizability, out string formattingTag)
        {
            localizability = null;
            formattingTag  = null;
            string assemblyName = node.AssemblyName;
            string typeFullName = node.TypeFullName;
            ElementLocalizability elementLocalizability = this._resolver.GetElementLocalizability(assemblyName, typeFullName);
            LocalizabilityGroup   localizabilityComment = this._resolver.GetLocalizabilityComment(node, "$Content");

            if (localizabilityComment != null)
            {
                localizability = localizabilityComment.Override(elementLocalizability.Attribute);
            }
            else
            {
                localizability = elementLocalizability.Attribute;
            }
            formattingTag = elementLocalizability.FormattingTag;
        }
Exemple #6
0
        //------------------------------
        // Private methods
        //------------------------------
        private static LocalizabilityGroup LookupAndSetLocalizabilityAttribute(string input)
        {
            //
            // For Localization.Attributes, values are seperated by spaces, e.g.
            // $Content (Modifiable Readable)
            // We are breaking the content and convert it to corresponding enum values.
            //
            LocalizabilityGroup attributeGroup = new LocalizabilityGroup();

            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < input.Length; i++)
            {
                if (Char.IsWhiteSpace(input[i]))
                {
                    if (builder.Length > 0)
                    {
                        ParseLocalizabilityString(
                            builder.ToString(),
                            attributeGroup
                            );

                        builder = new StringBuilder();
                    }
                }
                else
                {
                    builder.Append(input[i]);
                }
            }

            if (builder.Length > 0)
            {
                ParseLocalizabilityString(
                    builder.ToString(),
                    attributeGroup
                    );
            }

            return(attributeGroup);
        }
        // Token: 0x06006EB9 RID: 28345 RVA: 0x001FD22C File Offset: 0x001FB42C
        private void GetLocalizabilityForPropertyNode(BamlStartComplexPropertyNode node, out LocalizabilityAttribute localizability)
        {
            localizability = null;
            string assemblyName      = node.AssemblyName;
            string ownerTypeFullName = node.OwnerTypeFullName;
            string propertyName      = node.PropertyName;

            if (ownerTypeFullName == null || ownerTypeFullName.Length == 0)
            {
                string text;
                this.GetLocalizabilityForElementNode((BamlStartElementNode)node.Parent, out localizability, out text);
                return;
            }
            LocalizabilityGroup localizabilityComment = this._resolver.GetLocalizabilityComment((BamlStartElementNode)node.Parent, node.PropertyName);

            localizability = this._resolver.GetPropertyLocalizability(assemblyName, ownerTypeFullName, propertyName);
            if (localizabilityComment != null)
            {
                localizability = localizabilityComment.Override(localizability);
            }
        }
        private void GetLocalizabilityForPropertyNode(
            BamlStartComplexPropertyNode node,
            out LocalizabilityAttribute localizability
            )
        {
            localizability = null;

            string assemblyName      = node.AssemblyName;
            string className         = node.OwnerTypeFullName;
            string propertyLocalName = node.PropertyName;

            if (className == null || className.Length == 0)
            {
                // class name can be empty or null. For example, <Set PropertyPath="...">
                // We will use the parent node's value.
                string formattingTag;
                GetLocalizabilityForElementNode((BamlStartElementNode)node.Parent, out localizability, out formattingTag);
                return;
            }

            LocalizabilityGroup comment = _resolver.GetLocalizabilityComment(
                (BamlStartElementNode)node.Parent,
                node.PropertyName
                );

            localizability = _resolver.GetPropertyLocalizability(
                assemblyName,
                className,
                propertyLocalName
                );

            if (comment != null)
            {
                localizability = comment.Override(localizability);
            }
        }
        // Token: 0x06006EC2 RID: 28354 RVA: 0x001FD860 File Offset: 0x001FBA60
        private static void ParseLocalizabilityString(string value, LocalizabilityGroup attributeGroup)
        {
            int num;

            if (LocComments.ReadabilityIndexTable.TryGet(value, out num))
            {
                attributeGroup.Readability = (Readability)num;
                return;
            }
            if (LocComments.ModifiabilityIndexTable.TryGet(value, out num))
            {
                attributeGroup.Modifiability = (Modifiability)num;
                return;
            }
            if (LocComments.LocalizationCategoryIndexTable.TryGet(value, out num))
            {
                attributeGroup.Category = (LocalizationCategory)num;
                return;
            }
            throw new FormatException(SR.Get("InvalidLocalizabilityValue", new object[]
            {
                value
            }));
        }
        /// <summary>
        /// This builds the localizable string from the baml tree node
        /// </summary>
        /// <return>
        /// return true when the node has valid localizable content, false otherwise.
        /// </return>
        internal bool TryGetContent(BamlLocalizableResourceKey key, BamlTreeNode currentNode, out string content)
        {
            content = string.Empty;

            switch (currentNode.NodeType)
            {
            case BamlNodeType.Property:
            {
                bool             isValidContent = true;
                BamlPropertyNode propertyNode   = (BamlPropertyNode)currentNode;
                content = BamlResourceContentUtil.EscapeString(propertyNode.Value);

                //
                // Markup extensions are not localizable values, e.g. {x:Type SolidColorBrush}.
                // So if the string can be parsed as Markup extensions, we will exclude it unless
                // the user sets localization comments explicitly to localize this value.
                //
                string typeName, args;
                string tempContent = content;
                if (MarkupExtensionParser.GetMarkupExtensionTypeAndArgs(ref tempContent, out typeName, out args))
                {
                    // See if this value has been marked as localizable explicitly in comments
                    LocalizabilityGroup localizability = _resolver.GetLocalizabilityComment(
                        propertyNode.Parent as BamlStartElementNode,
                        propertyNode.PropertyName
                        );

                    isValidContent = (localizability != null && localizability.Readability == Readability.Readable);
                }
                return(isValidContent);
            }

            case BamlNodeType.LiteralContent:
            {
                content = BamlResourceContentUtil.EscapeString(
                    ((BamlLiteralContentNode)currentNode).Content
                    );
                return(true);    // succeed
            }

            case BamlNodeType.StartElement:
            {
                BamlStartElementNode elementNode = (BamlStartElementNode)currentNode;
                if (elementNode.Content == null)
                {
                    StringBuilder contentBuilder = new StringBuilder();
                    foreach (BamlTreeNode child in elementNode.Children)
                    {
                        // we only format element and text inline
                        // other nodes like property node we don't put them into the content of the element
                        switch (child.NodeType)
                        {
                        case BamlNodeType.StartElement:
                        {
                            string childContent;
                            if (TryFormatElementContent(key, (BamlStartElementNode)child, out childContent))
                            {
                                contentBuilder.Append(childContent);
                            }
                            else
                            {
                                return(false);       // failed to get content for children element
                            }

                            break;
                        }

                        case BamlNodeType.Text:
                        {
                            contentBuilder.Append(BamlResourceContentUtil.EscapeString(
                                                      ((BamlTextNode)child).Content)
                                                  );
                            break;
                        }
                        }
                    }

                    elementNode.Content = contentBuilder.ToString();
                }

                content = elementNode.Content;
                return(true);
            }

            default:
                return(true);
            }
        }
Exemple #11
0
        private static void ParseLocalizabilityString(
            string               value,
            LocalizabilityGroup  attributeGroup
            )
        {
            int enumValue;
            if (ReadabilityIndexTable.TryGet(value, out enumValue))
            {
                attributeGroup.Readability = (Readability) enumValue;
                return;
            }

            if (ModifiabilityIndexTable.TryGet(value, out enumValue))
            {
                attributeGroup.Modifiability = (Modifiability) enumValue;
                return;
            }

            if (LocalizationCategoryIndexTable.TryGet(value, out enumValue))
            {
                attributeGroup.Category = (LocalizationCategory) enumValue;
                return;
            }

            throw new FormatException(SR.Get(SRID.InvalidLocalizabilityValue, value));
        }
Exemple #12
0
        //------------------------------
        // Private methods
        //------------------------------
        private static LocalizabilityGroup LookupAndSetLocalizabilityAttribute(string input)
        {
            //
            // For Localization.Attributes, values are seperated by spaces, e.g.
            // $Content (Modifiable Readable)
            // We are breaking the content and convert it to corresponding enum values.
            //
            LocalizabilityGroup attributeGroup = new LocalizabilityGroup();

            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < input.Length; i ++)
            {
                if (Char.IsWhiteSpace(input[i]))
                {
                    if (builder.Length > 0)
                    {
                        ParseLocalizabilityString(
                            builder.ToString(),
                            attributeGroup
                            );

                        builder = new StringBuilder();
                    }
                }
                else
                {
                    builder.Append(input[i]);
                }
            }

            if (builder.Length > 0)
            {
                ParseLocalizabilityString(
                    builder.ToString(),
                    attributeGroup
                    );
            }

            return attributeGroup;
        }