// Token: 0x06006EB7 RID: 28343 RVA: 0x001FD064 File Offset: 0x001FB264 private bool TryFormatElementContent(BamlLocalizableResourceKey key, BamlStartElementNode node, out string content) { content = string.Empty; LocalizabilityAttribute localizabilityAttribute; string text; this.GetLocalizabilityForElementNode(node, out localizabilityAttribute, out text); localizabilityAttribute = this.CombineAndPropagateInheritanceValues(node, localizabilityAttribute); if (text != null && localizabilityAttribute.Category != LocalizationCategory.NeverLocalize && localizabilityAttribute.Category != LocalizationCategory.Ignore && localizabilityAttribute.Modifiability == Modifiability.Modifiable && localizabilityAttribute.Readability == Readability.Readable) { StringBuilder stringBuilder = new StringBuilder(); if (node.Uid != null) { stringBuilder.AppendFormat(TypeConverterHelper.InvariantEnglishUS, "<{0} {1}=\"{2}\">", new object[] { text, "Uid", BamlResourceContentUtil.EscapeString(node.Uid) }); } else { stringBuilder.AppendFormat(TypeConverterHelper.InvariantEnglishUS, "<{0}>", new object[] { text }); } string value; bool flag = this.TryGetContent(key, node, out value); if (flag) { stringBuilder.Append(value); stringBuilder.AppendFormat(TypeConverterHelper.InvariantEnglishUS, "</{0}>", new object[] { text }); node.Formatted = true; content = stringBuilder.ToString(); } return(flag); } bool result = true; if (node.Uid != null) { content = string.Format(TypeConverterHelper.InvariantEnglishUS, "{0}{1}{2}", new object[] { '#', BamlResourceContentUtil.EscapeString(node.Uid), ';' }); } else { this._resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.UidMissingOnChildElement)); result = false; } return(result); }
// 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); }
private bool TryFormatElementContent( BamlLocalizableResourceKey key, BamlStartElementNode node, out string content ) { content = string.Empty; string formattingTag; LocalizabilityAttribute attribute; GetLocalizabilityForElementNode(node, out attribute, out formattingTag); attribute = CombineAndPropagateInheritanceValues(node, attribute); if (formattingTag != null && attribute.Category != LocalizationCategory.NeverLocalize && attribute.Category != LocalizationCategory.Ignore && attribute.Modifiability == Modifiability.Modifiable && attribute.Readability == Readability.Readable ) { // this node should be formatted inline StringBuilder contentBuilder = new StringBuilder(); // write opening tag if (node.Uid != null) { contentBuilder.AppendFormat( TypeConverterHelper.InvariantEnglishUS, "<{0} {1}=\"{2}\">", formattingTag, XamlReaderHelper.DefinitionUid, BamlResourceContentUtil.EscapeString(node.Uid) ); } else { contentBuilder.AppendFormat(TypeConverterHelper.InvariantEnglishUS, "<{0}>", formattingTag); } // recurisively call down to format the content string childContent; bool succeed = TryGetContent(key, node, out childContent); if (succeed) { contentBuilder.Append(childContent); // write closing tag contentBuilder.AppendFormat(TypeConverterHelper.InvariantEnglishUS, "</{0}>", formattingTag); // remeber that we format this element so that we don't format the value again. // e.g. <Text x:Uid="t"> <Bold x:Uid="b"> ... </Bold> </Text> // if <Bold> is already inlined in Text element's contennt, we don't need to // have a seperate entry for <Bold> anymore node.Formatted = true; content = contentBuilder.ToString(); } return(succeed); } else { // this node should be represented by place holder. bool succeed = true; if (node.Uid != null) { content = string.Format( TypeConverterHelper.InvariantEnglishUS, "{0}{1}{2}", BamlConst.ChildStart, BamlResourceContentUtil.EscapeString(node.Uid), BamlConst.ChildEnd ); } else { // we want to enforce the rule that all children element // must have UID defined. _resolver.RaiseErrorNotifyEvent( new BamlLocalizerErrorNotifyEventArgs( key, BamlLocalizerError.UidMissingOnChildElement ) ); succeed = false; // failed } return(succeed); } }
/// <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); } }