// This tool takes CSV files from Microsoft's "sample" LocBaml localization tool and outputs sanitized, easily translatable Key-Value CSVs for Crowdin static void Main(string[] args) { using (var reader = new StreamReader("en-US.csv")) using (var csv = new CsvReader(reader)) { csv.Configuration.HasHeaderRecord = false; var records = csv.GetRecords <LocBamlLine>(); var localizable = new List <LocalizableLine>(); var locBamlLines = records as LocBamlLine[] ?? records.ToArray(); foreach (var locBamlLine in locBamlLines) { if (locBamlLine.LocalizerModifiable == true && locBamlLine.LocalizerModifiable == true && AllowedCategories.Contains(locBamlLine.Category) && !string.IsNullOrEmpty(locBamlLine.Value)) { Console.WriteLine($"{locBamlLine.ResourceKey}: {locBamlLine.Value}"); localizable.Add(new LocalizableLine { Key = locBamlLine.ResourceKey, Value = locBamlLine.Value }); } } using (var writer = new StreamWriter("localizable.csv")) using (var csvWriter = new CsvWriter(writer)) { csvWriter.WriteRecords(localizable); writer.Flush(); } Console.WriteLine($"\nWrote {localizable.Count} localizable strings."); Console.ReadLine(); if (File.Exists("localized.csv")) { using (var localizedReader = new StreamReader("localized.csv")) using (var localizedCsv = new CsvReader(localizedReader)) { localizedCsv.Configuration.HasHeaderRecord = false; var localizedRecords = localizedCsv.GetRecords <LocalizableLine>(); var localizedLines = localizedRecords as LocalizableLine[] ?? localizedRecords.ToArray(); foreach (var locBamlLine in locBamlLines) { var localizedLine = localizedLines.FirstOrDefault(x => x.Key == locBamlLine.ResourceKey); if (localizedLine != null) { locBamlLine.Value = localizedLine.Value; Console.WriteLine($"Modified line: {locBamlLine.ResourceKey}: {locBamlLine.Value}"); } } using (var writer = new StreamWriter("out.csv")) using (var csvWriter = new CsvWriter(writer)) { csvWriter.WriteRecords(locBamlLines); writer.Flush(); } Console.ReadLine(); } } } }
protected void Rebuild() { var key = ConsoleKey.A; var linesPerPage = TextLinesMax - HeaderTakesLine; var currentCategory = ""; var done = new List <Noun>(); List <ILinePresenter> page = null; m_pages.Clear(); var categories = m_descriptors.Select(_descriptor => _descriptor.Essence).OfType <Item>().Select(_item => _item.Category).Distinct().OrderBy(_category => _category); if (AllowedCategories.Any()) { categories = categories.Intersect(AllowedCategories).OrderBy(_category => _category); } foreach (var cat in categories) { var attribute = EssenceCategoryAttribute.GetAttribute(cat); if (m_currentFilter != '*' && attribute.C != m_currentFilter) { continue; } foreach (EssenceDescriptor descriptor in m_descriptors) { var item = descriptor.Essence as Item; var nm = descriptor.Essence.GetName(World.TheWorld.Avatar); if (item == null) { continue; } if (done.Contains(nm)) { continue; } done.Add(nm); if (page == null) { page = new List <ILinePresenter>(); m_pages.Add(m_pages.Count, page); currentCategory = ""; key = ConsoleKey.A; } var name = EALSentence.GENERAL.GetString(cat.AsNoun()); if (name != currentCategory) { page.Add(new EssenceCategoryPresenter(cat)); currentCategory = name; } page.Add(new EssencePresenter(key, descriptor, m_descriptors)); key++; if (page.Count == linesPerPage - 1) { page = null; } } } }