public Load ( string filename, SageContext context ) : void | ||
filename | string | URL for the file containing the XML document to load. The URL can be either a local /// file or an HTTP URL (a Web address). |
context | SageContext | The context under which the code is being invoked. |
return | void |
private static CacheableXmlDocument LoadSourceDocument(string path, SageContext context) { UrlResolver resolver = new UrlResolver(context); CacheableXmlDocument result = new CacheableXmlDocument(); result.Load(path, context); result.AddDependencies(path); result.AddDependencies(resolver.Dependencies.ToArray()); return result; }
private XmlDocument CombineVariations() { constituents = new List<string>(); LocaleInfo localeInfo; if (!context.ProjectConfiguration.Locales.TryGetValue(this.Locale, out localeInfo)) throw new UnconfiguredLocaleException(this.Locale); // locales contains the list of locales ordered by priority (high to low) List<string> names = new List<string>(localeInfo.DictionaryNames); // documents are orderered as defined in the configuration, from high to low priority OrderedDictionary<string, List<CacheableXmlDocument>> allDictionaries = new OrderedDictionary<string, List<CacheableXmlDocument>>(); foreach (string locale in names) { List<CacheableXmlDocument> langDictionaries = new List<CacheableXmlDocument>(); string documentPath = context.Path.GetDictionaryPath(locale, context.Category); // add extension dictionaries for the current locale // langDictionaries.AddRange(Application.Extensions.GetDictionaries(context, locale)); // add the project dictionary for the current locale if (File.Exists(documentPath)) { CacheableXmlDocument cacheable = new CacheableXmlDocument(); cacheable.Load(documentPath); this.Dependencies.AddRange(cacheable.Dependencies); langDictionaries.Add(cacheable); } if (langDictionaries.Count != 0) allDictionaries.Add(locale, langDictionaries); } if (allDictionaries.Count == 0) { log.Error( string.Format("There are no dictionary files for locale '{0}' in category '{1}'.\n", this.Locale, context.Category)); return null; } // now create a combined document, adding items from each document starting with high priority // and moving through the lower priority ones string firstLocale = allDictionaries.Keys.First(); XmlDocument result = allDictionaries[firstLocale][0]; XmlElement rootNode = result.DocumentElement; XmlNodeList dictNodes = rootNode.SelectNodes("*"); foreach (XmlElement phrase in dictNodes) phrase.SetAttribute("source", firstLocale); foreach (string locale in allDictionaries.Keys) { for (int i = 0; i < allDictionaries[locale].Count; i++) { if (locale == firstLocale && i == 0) continue; dictNodes = allDictionaries[locale][i].DocumentElement.SelectNodes("*"); foreach (XmlElement node in dictNodes) { string phraseID = node.GetAttribute("id"); XmlNode existingNode = result.SelectSingleNode(string.Format("/*/*[@id='{0}']", phraseID.Replace("'", "'"))); if (existingNode == null) { XmlElement phrase = rootNode.AppendElement(result.ImportNode(node, true)); phrase.SetAttribute("source", locale); } } } } foreach (XmlElement phraseNode in rootNode.SelectNodes("*")) { string itemId = phraseNode.GetAttribute("id"); string itemText = phraseNode.InnerText; if (this.Items.ContainsKey(itemId)) { this.Items[itemId] = itemText; } else this.Items.Add(itemId, itemText); } return result; }
internal CacheableXmlDocument LoadLocalizedSourceDocument(string locale) { string fullPath = this.GetSourcePath(locale); CacheableXmlDocument document = new CacheableXmlDocument(); document.Load(fullPath, context); return document; }
internal CacheableXmlDocument LoadSourceDocument(string locale) { string fullPath = context.Path.Localize(this.FilePath, locale, true); if (UrlResolver.GetScheme(fullPath) == "file" && !File.Exists(fullPath)) { throw new FileNotFoundException(string.Format("The resource file '{0}' could not be opened using locale '{1}'", this.FilePath, locale)); } CacheableXmlDocument document = new CacheableXmlDocument(); document.Load(fullPath, context); return document; }
internal CacheableXmlDocument LoadGlobalizedDocument(string locale) { string fullPath = this.GetInternationalizedName(locale, true); CacheableXmlDocument document = new CacheableXmlDocument(); document.Load(fullPath, context); return document; }