public static bool IsLocalizable(BamlLocalizableResourceKey resourceKey, BamlLocalizableResource resource) { if (String.IsNullOrEmpty(resource.Content)) { return(false); } if (resource.Category == LocalizationCategory.NeverLocalize) { return(false); } if (resource.Category != LocalizationCategory.None) { return(true); } if (resourceKey.ClassName == "System.Windows.Setter" && resourceKey.PropertyName == "Value") { return(true); } if (resourceKey.PropertyName == "$Content") { if (resource.Content.StartsWith("#") && resource.Content.EndsWith(";")) { return(false); } return(true); } return(false); }
public void Write(string bamlName, BamlLocalizableResourceKey resourceKey, BamlLocalizableResource resource) { writer.WriteColumn(bamlName); // column 2: localizable resource key writer.WriteColumn(ResourceKeyToString(resourceKey)); // column 3: localizable resource's category writer.WriteColumn(resource.Category.ToString()); // column 4: localizable resource's readability writer.WriteColumn(resource.Readable.ToString()); // column 5: localizable resource's modifiability writer.WriteColumn(resource.Modifiable.ToString()); // column 6: localizable resource's localization comments writer.WriteColumn(resource.Comments); // column 7: localizable resource's content writer.WriteColumn(resource.Content); // Done. finishing the line writer.EndLine(); }
// 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); }
public BamlLocalizableResource FindCorrespondence(BamlLocalizableResourceKey key, BamlLocalizationDictionary dictionary) { if (dictionary.Contains(key)) { return(dictionary[key]); } return(null); }
// Token: 0x06006E1E RID: 28190 RVA: 0x001FB183 File Offset: 0x001F9383 internal BamlTreeNode MapKeyToBamlTreeNode(BamlLocalizableResourceKey key, BamlTree tree) { if (this._keyToBamlNodeIndexMap.Contains(key)) { return(tree[(int)this._keyToBamlNodeIndexMap[key]]); } return(null); }
// 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); }
/// <summary> /// Write the localizable key-value pairs /// </summary> /// <param name="options"></param> internal static void Write(LocBamlOptions options) { InputBamlStreamList bamlStreamList = new InputBamlStreamList(options); using (ITranslationWriter writer = options.GetTranslationWriter()) { options.WriteLine(StringLoader.Get("WriteBamlValues")); for (int i = 0; i < bamlStreamList.Count; i++) { options.Write(" "); options.Write(StringLoader.Get("ProcessingBaml", bamlStreamList[i].Name)); // Search for comment file in the same directory. The comment file has the extension to be // "loc". string commentFile = Path.ChangeExtension(bamlStreamList[i].Name, "loc"); TextReader commentStream = null; try { if (File.Exists(commentFile)) { commentStream = new StreamReader(commentFile); } // create the baml localizer BamlLocalizer mgr = new BamlLocalizer( bamlStreamList[i].Stream, new BamlLocalizabilityByReflection(options.Assemblies), commentStream ); // extract localizable resource from the baml stream BamlLocalizationDictionary dict = mgr.ExtractResources(); // write out each resource foreach (DictionaryEntry entry in dict) { BamlLocalizableResourceKey key = (BamlLocalizableResourceKey)entry.Key; BamlLocalizableResource resource = (BamlLocalizableResource)entry.Value; writer.WriteResource(bamlStreamList[i].Name, LocBamlConst.ResourceKeyToString(key), resource); } options.WriteLine(StringLoader.Get("Done")); } finally { if (commentStream != null) { commentStream.Close(); } } } // close all the baml input streams, output stream is closed by writer. bamlStreamList.Close(); } }
internal TranslationDictionariesReader(List <BamlString> bamlStrings) { // hash key is case insensitive strings _table = new Hashtable(); // we read each Row int rowNumber = 0; foreach (BamlString bamlString in bamlStrings) { rowNumber++; // field #1 is the baml name. string bamlName = bamlString.BamlFile; // it can't be null if (bamlName == null) { throw new ApplicationException(StringLoader.Get("EmptyRowEncountered")); } // field #2: key to the localizable resource string key = bamlString.ResourceKey; if (key == null) { throw new ApplicationException(StringLoader.Get("NullBamlKeyNameInRow")); } BamlLocalizableResourceKey resourceKey = LocBamlConst.StringToResourceKey(key); // get the dictionary BamlLocalizationDictionary dictionary = this[bamlName]; if (dictionary == null) { // we create one if it is not there yet. dictionary = new BamlLocalizationDictionary(); this[bamlName] = dictionary; } BamlLocalizableResource resource; // the rest of the fields are either all null, // or all non-null. If all null, it means the resource entry is deleted. resource = new BamlLocalizableResource(); resource.Category = bamlString.Category; resource.Readable = (bool)BoolTypeConverter.ConvertFrom(bamlString.Readability); resource.Modifiable = (bool)BoolTypeConverter.ConvertFrom(bamlString.Modifiable); resource.Comments = bamlString.Comments; // in case content being the last column, consider null as empty. resource.Content = bamlString.Content ?? string.Empty; // at this point, we are good. // add to the dictionary. dictionary.Add(resourceKey, resource); } }
// Token: 0x06008D43 RID: 36163 RVA: 0x0025906C File Offset: 0x0025726C internal void AddBamlTreeNode(string uid, BamlLocalizableResourceKey key, BamlTreeNode node) { this._tree.AddTreeNode(node); if (uid != null) { this._uidToNewBamlNodeIndexMap[uid] = this._tree.Size - 1; } this._keyToNewBamlNodeIndexMap[key] = this._tree.Size - 1; }
internal static List <BamlString> ExtractBamlStrings(Assembly assembly) { InputBamlStreamList bamlStreamList = new InputBamlStreamList(assembly); List <BamlString> resultingList = new List <BamlString>(); for (int i = 0; i < bamlStreamList.Count; i++) { // Search for comment file in the same directory. The comment file has the extension to be // "loc". // string commentFile = Path.ChangeExtension(bamlStreamList[i].Name, "loc"); TextReader commentStream = null; try { //if (File.Exists(commentFile)) //{ // commentStream = new StreamReader(commentFile); //} // create the baml localizer BamlLocalizer mgr = new BamlLocalizer( bamlStreamList[i].Stream, new BamlLocalizabilityByReflection(new Assembly[] { assembly }), commentStream ); // extract localizable resource from the baml stream BamlLocalizationDictionary dict = mgr.ExtractResources(); // write out each resource foreach (DictionaryEntry entry in dict) { BamlLocalizableResourceKey key = (BamlLocalizableResourceKey)entry.Key; BamlLocalizableResource resource = (BamlLocalizableResource)entry.Value; resultingList.Add(new BamlString(bamlStreamList[i].Name, LocBamlConst.ResourceKeyToString(key), resource)); } } finally { if (commentStream != null) { commentStream.Close(); } } } // close all the baml input streams, output stream is closed by writer. bamlStreamList.Close(); // options.WriteLine(StringLoader.Get("Done")); return(resultingList); }
private static IList <BamlTreeNode> SplitXmlContent( BamlLocalizableResourceKey key, string content, BamlTreeUpdateMap bamlTreeMap ) { // process each translation as a piece of xml content because of potential formatting tag inside StringBuilder xmlContent = new StringBuilder(); xmlContent.Append("<ROOT>"); xmlContent.Append(content); xmlContent.Append("</ROOT>"); IList <BamlTreeNode> list = new List <BamlTreeNode>(4); XmlDocument doc = new XmlDocument(); bool succeed = true; try { doc.LoadXml(xmlContent.ToString()); XmlElement root = doc.FirstChild as XmlElement; if (root != null && root.HasChildNodes) { for (int i = 0; i < root.ChildNodes.Count && succeed; i++) { succeed = GetBamlTreeNodeFromXmlNode( key, root.ChildNodes[i], bamlTreeMap, list ); } } } catch (XmlException) { // The content can't be parse as Xml. bamlTreeMap.Resolver.RaiseErrorNotifyEvent( new BamlLocalizerErrorNotifyEventArgs( key, BamlLocalizerError.SubstitutionAsPlaintext ) ); // Apply the substitution as plain text succeed = GetBamlTreeNodeFromText( key, content, bamlTreeMap, list ); } return(succeed ? list : null); }
internal static string ResourceKeyToString(BamlLocalizableResourceKey key) { return(string.Format( CultureInfo.InvariantCulture, "{0}:{1}.{2}", key.Uid, key.ClassName, key.PropertyName )); }
// Token: 0x06008D40 RID: 36160 RVA: 0x00258FB8 File Offset: 0x002571B8 internal BamlTreeNode MapKeyToBamlTreeNode(BamlLocalizableResourceKey key) { BamlTreeNode bamlTreeNode = this._originalMap.MapKeyToBamlTreeNode(key, this._tree); if (bamlTreeNode == null && this._keyToNewBamlNodeIndexMap.Contains(key)) { bamlTreeNode = this._tree[(int)this._keyToNewBamlNodeIndexMap[key]]; } return(bamlTreeNode); }
private static string GenerateBamlStream(Stream input, Stream output, BamlLocalizationDictionary dictionary, LocBamlOptions options) { string commentFile = Path.ChangeExtension(options.Input, "loc"); TextReader commentStream = null; try { if (File.Exists(commentFile)) { commentStream = new StreamReader(commentFile); } // create a localizabilty resolver based on reflection BamlLocalizabilityByReflection localizabilityReflector = new BamlLocalizabilityByReflection(options.Assemblies); // create baml localizer BamlLocalizer mgr = new BamlLocalizer( input, localizabilityReflector, commentStream ); // get the resources BamlLocalizationDictionary source = mgr.ExtractResources(); BamlLocalizationDictionary translations = new BamlLocalizationDictionary(); foreach (DictionaryEntry entry in dictionary) { BamlLocalizableResourceKey key = (BamlLocalizableResourceKey)entry.Key; // filter out unchanged items if (!source.Contains(key) || entry.Value == null || source[key].Content != ((BamlLocalizableResource)entry.Value).Content) { translations.Add(key, (BamlLocalizableResource)entry.Value); } } // update baml mgr.UpdateBaml(output, translations); } catch (Exception ex) { return(ex.Message); } finally { if (commentStream != null) { commentStream.Close(); } } return(null); }
public void Write(string bamlName, BamlLocalizableResourceKey resourceKey, BamlLocalizableResource resource) { if (!BamlResourceCsvWriter.IsLocalizable(resourceKey, resource)) { return; } resourceFile.SetResource( GetResourceKey(bamlName, resourceKey), resource.Content, resource.Comments); }
public BamlLocalizableResource FindCorrespondence(BamlLocalizableResourceKey key) { foreach (var dictionary in dictionariesList) { var resource = bamlResourceFinder.FindCorrespondence(key, dictionary); if (resource != null && !String.IsNullOrEmpty(resource.Content)) { return(resource); } } return(null); }
public static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("this.exe [resource.dll]"); return; } Assembly assembly = Assembly.LoadFrom(args[0]); foreach (string resourceName in assembly.GetManifestResourceNames()) { Stream resourceStream = assembly.GetManifestResourceStream(resourceName); using (ResourceReader reader = new ResourceReader(resourceStream)) { foreach (DictionaryEntry entry in reader) { string name = entry.Key as string; if (Path.GetExtension(name).ToUpperInvariant() == ".BAML") { Console.WriteLine("Processing baml {0}", name); // <Snippet1> // Obtain the BAML stream. Stream source = entry.Value as Stream; // Create a BamlLocalizer on the stream. BamlLocalizer localizer = new BamlLocalizer(source); BamlLocalizationDictionary resources = localizer.ExtractResources(); // Write out all the localizable resources in the BAML. foreach (DictionaryEntry resourceEntry in resources) { BamlLocalizableResourceKey key = resourceEntry.Key as BamlLocalizableResourceKey; BamlLocalizableResource value = resourceEntry.Value as BamlLocalizableResource; Console.WriteLine( " {0}.{1}.{2} = {3}", key.Uid, key.ClassName, key.PropertyName, value.Content ); } // </Snippet1> Console.WriteLine("Done"); } } } } }
// Token: 0x06006E21 RID: 28193 RVA: 0x001FB3C4 File Offset: 0x001F95C4 internal static BamlLocalizableResourceKey GetKey(BamlTreeNode node) { BamlLocalizableResourceKey result = null; BamlNodeType nodeType = node.NodeType; if (nodeType != BamlNodeType.StartElement) { if (nodeType != BamlNodeType.Property) { if (nodeType == BamlNodeType.LiteralContent) { BamlLiteralContentNode bamlLiteralContentNode = (BamlLiteralContentNode)node; BamlStartElementNode bamlStartElementNode = (BamlStartElementNode)node.Parent; if (bamlStartElementNode.Uid != null) { result = new BamlLocalizableResourceKey(bamlStartElementNode.Uid, bamlStartElementNode.TypeFullName, "$LiteralContent", bamlStartElementNode.AssemblyName); } } } else { BamlPropertyNode bamlPropertyNode = (BamlPropertyNode)node; BamlStartElementNode bamlStartElementNode2 = (BamlStartElementNode)bamlPropertyNode.Parent; if (bamlStartElementNode2.Uid != null) { string uid; if (bamlPropertyNode.Index <= 0) { uid = bamlStartElementNode2.Uid; } else { uid = string.Format(TypeConverterHelper.InvariantEnglishUS, "{0}.{1}_{2}", new object[] { bamlStartElementNode2.Uid, bamlPropertyNode.PropertyName, bamlPropertyNode.Index }); } result = new BamlLocalizableResourceKey(uid, bamlPropertyNode.OwnerTypeFullName, bamlPropertyNode.PropertyName, bamlPropertyNode.AssemblyName); } } } else { BamlStartElementNode bamlStartElementNode3 = (BamlStartElementNode)node; if (bamlStartElementNode3.Uid != null) { result = new BamlLocalizableResourceKey(bamlStartElementNode3.Uid, bamlStartElementNode3.TypeFullName, "$Content", bamlStartElementNode3.AssemblyName); } } return(result); }
public BamlLocalizableResourceKey FindCorrespondenceKey(BamlLocalizableResourceKey key, BamlLocalizationDictionary dictionary) { foreach (var entry in dictionary) { var entryKey = (BamlLocalizableResourceKey)entry.Key; if (entryKey.Uid == key.Uid && entryKey.PropertyName == key.PropertyName) { return(entryKey); } } return(null); }
internal BamlTreeNode MapKeyToBamlTreeNode(BamlLocalizableResourceKey key) { BamlTreeNode node = _originalMap.MapKeyToBamlTreeNode(key, _tree); if (node == null) { // find it in the new nodes if (_keyToNewBamlNodeIndexMap.Contains(key)) { node = _tree[(int)_keyToNewBamlNodeIndexMap[key]]; } } return(node); }
internal void AddBamlTreeNode( string uid, BamlLocalizableResourceKey key, BamlTreeNode node ) { // add to node _tree.AddTreeNode(node); // remember the tree node index if (uid != null) { _uidToNewBamlNodeIndexMap[uid] = _tree.Size - 1; } _keyToNewBamlNodeIndexMap[key] = _tree.Size - 1; }
internal TranslationDictionariesReader(XliffObject xliff) { // hash key is case insensitive strings _table = new Hashtable(); foreach (File file in xliff.Files) { string bamlName = file.Original; // get the dictionary BamlLocalizationDictionary dictionary = this[bamlName]; if (dictionary == null) { // we create one if it is not there yet. dictionary = new BamlLocalizationDictionary(); this[bamlName] = dictionary; } Body body = file.Body; // There should only be one group, but go through any that exist for good measure foreach (Group group in body.Groups) { foreach (TranslationUnit transUnit in group.TranslationUnits) { string key = transUnit.Id; BamlLocalizableResourceKey resourceKey = LocBamlConst.StringToResourceKey(key); BamlLocalizableResource resource = new BamlLocalizableResource(); resource.Category = (LocalizationCategory)StringCatConverter.ConvertFrom(transUnit.ResourceType); /* * resource.Readable = (bool)BoolTypeConverter.ConvertFrom(reader.GetColumn(3)); * resource.Modifiable = (bool)BoolTypeConverter.ConvertFrom(reader.GetColumn(4)); */ Note comment = transUnit.Notes.FirstOrDefault(n => n.From == "MultilingualBuild"); if (comment != null) { resource.Comments = comment.Text; } resource.Content = transUnit.Target.Content ?? string.Empty; dictionary.Add(resourceKey, resource); } } } }
public bool MoveNext() { while (reader.ReadRow()) { // field #1 is the baml name. string bamlName = reader.GetColumn(0); // it can't be null if (bamlName == null) { throw new ApplicationException("Empty Row Encountered"); } if (string.IsNullOrEmpty(bamlName)) { // allow for comment lines in csv file. // each comment line starts with ",". It will make the first entry as String.Empty. // and we will skip the whole line. continue; // if the first column is empty, take it as a comment line } CurrentBamlName = bamlName; // field #2: Uid to the localizable resource string uid = reader.GetColumn(1); if (uid == null) { throw new ApplicationException("Null Baml Key Name In Row"); } // field #3: Property to the localizable resource string property = reader.GetColumn(2); if (property == null) { throw new ApplicationException("Null Baml Key Name In Row"); } CurrentResourceKey = new BamlLocalizableResourceKey(uid, "", property); ParseResource(); return(true); } return(false); }
public bool MoveNext() { curIndex++; if (curIndex >= resourceFile.Resources.Count) { CurrentBamlName = null; CurrentResourceKey = null; CurrentResource = null; return(false); } string key = resourceFile.Resources.Keys[curIndex]; int fp = key.IndexOf(':'); int lp = key.LastIndexOf(':'); if (fp < 0 || lp < 0 || fp == lp) { throw new FormatException("Invalid format of BAML key " + key); //return MoveNext(); } CurrentBamlName = key.Substring(0, fp); var uid = key.Substring(fp + 1, lp - fp - 1); var property = key.Substring(lp + 1); CurrentResourceKey = new BamlLocalizableResourceKey(uid, "", property); var resource = new BamlLocalizableResource(); // field #4: Content resource.Content = resourceFile.GetStringValue(key); // in case content being the last column, consider null as empty. if (resource.Content == null) { resource.Content = string.Empty; } CurrentResource = resource; return(true); }
public void Add(XamlFileDescription xamlFileDescription, UidCollector uidCollector) { if (uidCollector == null) { return; } List <BamlResourceEntry> list; if (!resources.TryGetValue(xamlFileDescription.ProjectDescription.UniqueName, out list)) { list = new List <BamlResourceEntry>(); resources.Add(xamlFileDescription.ProjectDescription.UniqueName, list); } var bamlName = GetBamlName(xamlFileDescription); for (int i = 0; i < uidCollector.Count; i++) { var uid = uidCollector[i]; if (uid.Status != UidStatus.Valid) { continue; } if (uid.Entries != null) { foreach (var entry in uid.Entries) { var key = new BamlLocalizableResourceKey(uid.Value, uid.ElementName, GetPropertyName(entry)); var resource = new BamlLocalizableResource { Content = entry.LocalizableString, Category = LocalizationCategory.Text }; list.Add(new BamlResourceEntry(bamlName, key, resource)); } } } }
private static void ReArrangeChildren( BamlLocalizableResourceKey key, BamlTreeNode node, string translation, BamlTreeUpdateMap treeMap ) { // // Split the translation into a list of BamlNodes. // IList <BamlTreeNode> nodes = SplitXmlContent( key, translation, treeMap ); // merge the nodes from translation with the source nodes MergeChildrenList(key, treeMap, node, nodes); }
public void Write(string bamlName, BamlLocalizableResourceKey resourceKey, BamlLocalizableResource resource) { if (!IsLocalizable(resourceKey, resource)) { return; } // column 1: baml name writer.WriteColumn(bamlName); // column 2: localizable resource key writer.WriteColumn(resourceKey.Uid); // column 3: localizable resource property writer.WriteColumn(resourceKey.PropertyName); // column 4: localizable resource's content writer.WriteColumn(resource.Content); // Done. finishing the line writer.EndLine(); }
// Token: 0x06006EB2 RID: 28338 RVA: 0x001FCC7C File Offset: 0x001FAE7C private static bool GetBamlTreeNodeFromText(BamlLocalizableResourceKey key, string content, BamlTreeUpdater.BamlTreeUpdateMap bamlTreeMap, IList <BamlTreeNode> newChildrenList) { BamlStringToken[] array = BamlResourceContentUtil.ParseChildPlaceholder(content); if (array == null) { bamlTreeMap.Resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.IncompleteElementPlaceholder)); return(false); } bool result = true; for (int i = 0; i < array.Length; i++) { BamlStringToken.TokenType type = array[i].Type; if (type != BamlStringToken.TokenType.Text) { if (type == BamlStringToken.TokenType.ChildPlaceHolder) { BamlTreeNode bamlTreeNode = bamlTreeMap.MapUidToBamlTreeElementNode(array[i].Value); if (bamlTreeNode != null) { newChildrenList.Add(bamlTreeNode); } else { bamlTreeMap.Resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(new BamlLocalizableResourceKey(array[i].Value, string.Empty, string.Empty), BamlLocalizerError.InvalidUid)); result = false; } } } else { BamlTreeNode item = new BamlTextNode(array[i].Value); newChildrenList.Add(item); } } return(result); }
// Token: 0x06006EAB RID: 28331 RVA: 0x001FC55C File Offset: 0x001FA75C private static void CreateMissingBamlTreeNode(BamlLocalizationDictionary dictionary, BamlTreeUpdater.BamlTreeUpdateMap treeMap) { BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { BamlLocalizableResourceKey key = enumerator.Key; BamlLocalizableResource value = enumerator.Value; if (treeMap.MapKeyToBamlTreeNode(key) == null) { if (key.PropertyName == "$Content") { if (treeMap.MapUidToBamlTreeElementNode(key.Uid) == null) { BamlStartElementNode bamlStartElementNode = new BamlStartElementNode(treeMap.Resolver.ResolveAssemblyFromClass(key.ClassName), key.ClassName, false, false); bamlStartElementNode.AddChild(new BamlDefAttributeNode("Uid", key.Uid)); BamlTreeUpdater.TryAddContentPropertyToNewElement(treeMap, bamlStartElementNode); bamlStartElementNode.AddChild(new BamlEndElementNode()); treeMap.AddBamlTreeNode(key.Uid, key, bamlStartElementNode); } } else { BamlTreeNode node; if (key.PropertyName == "$LiteralContent") { node = new BamlLiteralContentNode(value.Content); } else { node = new BamlPropertyNode(treeMap.Resolver.ResolveAssemblyFromClass(key.ClassName), key.ClassName, key.PropertyName, value.Content, BamlAttributeUsage.Default); } treeMap.AddBamlTreeNode(null, key, node); } } } }
// Token: 0x06006EB0 RID: 28336 RVA: 0x001FCA0C File Offset: 0x001FAC0C private static IList <BamlTreeNode> SplitXmlContent(BamlLocalizableResourceKey key, string content, BamlTreeUpdater.BamlTreeUpdateMap bamlTreeMap) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<ROOT>"); stringBuilder.Append(content); stringBuilder.Append("</ROOT>"); IList <BamlTreeNode> list = new List <BamlTreeNode>(4); XmlDocument xmlDocument = new XmlDocument(); bool flag = true; try { xmlDocument.LoadXml(stringBuilder.ToString()); XmlElement xmlElement = xmlDocument.FirstChild as XmlElement; if (xmlElement != null && xmlElement.HasChildNodes) { int num = 0; while (num < xmlElement.ChildNodes.Count && flag) { flag = BamlTreeUpdater.GetBamlTreeNodeFromXmlNode(key, xmlElement.ChildNodes[num], bamlTreeMap, list); num++; } } } catch (XmlException) { bamlTreeMap.Resolver.RaiseErrorNotifyEvent(new BamlLocalizerErrorNotifyEventArgs(key, BamlLocalizerError.SubstitutionAsPlaintext)); flag = BamlTreeUpdater.GetBamlTreeNodeFromText(key, content, bamlTreeMap, list); } if (!flag) { return(null); } return(list); }