private IEnumerable<XmlResource> GetGlobalizableResources() { string globDirName = context.ProjectConfiguration.PathTemplates.GlobalizedDirectory.Replace("/", string.Empty).Replace("\\", string.Empty); string[] skipDirs = new[] { "dictionary", globDirName }; var files = new List<string>(Directory.GetFiles(categoryPath, "*.xml", SearchOption.AllDirectories)) .Where(f => !f.ContainsAnyOf(skipDirs)); List<XmlResource> result = new List<XmlResource>(); foreach (string filePath in files) { XmlResource resource = new XmlResource(filePath, context); XmlDocument sourceDoc = resource.LoadSourceDocument(context.Locale); if (resource.IsGlobalizable(sourceDoc) && result.Count(r => r.Name.Signature == resource.Name.Signature) == 0) result.Add(resource); } return result; }
/// <summary> /// Initializes a new instance of the <see cref="InternationalizationSummary"/> class, using the specified file path and category info. /// </summary> /// <param name="resource">The xml resource that was globalized.</param> /// <param name="categoryInfo">The <see cref="CategoryInfo"/> of the category the resource belongs to.</param> internal InternationalizationSummary(XmlResource resource, CategoryInfo categoryInfo) { this.Resource = resource; this.PhraseSummary = new Dictionary<string, XmlDocument>(); this.Dependencies = new Dictionary<string, IEnumerable<string>>(); }
/// <summary> /// Internationalizes the specified resource. /// </summary> /// <param name="resource">The resource.</param> /// <returns> /// The summary information about the internationalization of the specified <paramref name="resource"/>. /// </returns> /// <exception cref="ApplicationException"> /// One of the locales configured for the category being processed doesn't have any dictionary files. /// </exception> public InternationalizationSummary Internationalize(XmlResource resource) { if (resource == null) throw new ArgumentNullException("resource"); if (!Directory.Exists(resource.TargetDirectory)) { Directory.CreateDirectory(resource.TargetDirectory); File.SetAttributes(resource.TargetDirectory, FileAttributes.Hidden); } DictionaryFileCollection coll = Internationalizer.GetTranslationDictionaryCollection(context); CategoryInfo categoryInfo = context.ProjectConfiguration.Categories[context.Category]; InternationalizationSummary summary = new InternationalizationSummary(resource, categoryInfo); Stopwatch sw = new Stopwatch(); sw.Start(); foreach (string locale in coll.Locales) { if (coll.Dictionaries[locale].Document == null) throw new InternationalizationError(string.Format( "The locale '{0}' in category '{1}' doesn't have any dictionary files", locale, coll.Category)); CacheableXmlDocument input; try { input = resource.LoadLocalizedSourceDocument(locale); } catch (FileNotFoundException ex) { log.ErrorFormat("Could not internationalize resource '{0}' to locale '{1}': {2}", resource.Name.Signature, locale, ex.Message); continue; } XmlWriterSettings settings = new XmlWriterSettings { Indent = true }; string outputPath = resource.GetInternationalizedName(locale, true); XmlWriter translateWriter = XmlWriter.Create(outputPath, settings); StringBuilder builder = new StringBuilder(); XmlWriter diagnoseWriter = XmlWriter.Create(builder, settings); try { this.Transform(input, coll, locale, translateWriter, InternationalizeType.Translate); this.Transform(input, coll, locale, diagnoseWriter, InternationalizeType.Diagnose); } finally { translateWriter.Close(); diagnoseWriter.Close(); } XmlDocument diagnostics = new XmlDocument(); diagnostics.LoadXml(builder.ToString()); summary.AddPhraseSummary(locale, diagnostics); summary.AddDependencies(locale, input.Dependencies); } sw.Stop(); summary.Duration = sw.ElapsedMilliseconds; log.InfoFormat("Internationalized xml resource '{0}' into {1} locales in {2}ms", resource.Name.Signature, coll.Locales.Count, sw.ElapsedMilliseconds); return summary; }
private static CacheableXmlDocument LoadGlobalizedDocument(string path, SageContext context) { XmlResource resource = new XmlResource(path, context); CacheableXmlDocument result = resource.Load(context.Locale); return result; }