/// <summary> /// Method to write a markdown file /// </summary> /// <param name="items">List of translation items</param> /// <param name="comments">Optional list of comments (can be empty)</param> /// <param name="fileName">File name of the markdown file</param> /// <param name="writeTranslation">If true, the translation column will be written, other wise left blank</param> public static void WriteMarkdownTable(List <TranslationItem> items, List <TranslationItem> comments, string fileName, bool writeTranslation) { List <string> keys = new List <string>(GetTranslationKeys()); // With system default for (int i = 0; i < items.Count; i++) { string defaultTerm = keys.SingleOrDefault(s => s == items[i].Key); if (defaultTerm == null) { items[i].DefaultValue = ""; } else { items[i].DefaultValue = MediaExtractor.Properties.Resources.ResourceManager.GetString(defaultTerm); } string comment = items[i].Comment; if (comments != null && comments.Count > 0) { TranslationItem item = comments.First(x => x.Key == items[i].Key); if (item == null && string.IsNullOrEmpty(comment)) { comment = ""; } else if (item != null) { comment = item.Comment; } } items[i].Comment = comment; } try { using (StreamWriter sw = new StreamWriter(fileName, false)) { sw.WriteLine("| Name (mandatory) | Default Text | Translation | Comment |"); sw.WriteLine("| --- | --- | --- | --- |"); foreach (TranslationItem item in items) { if (writeTranslation) { sw.Write("| " + item.Key + " | " + EscapeMarkdown(item.DefaultValue) + " | " + EscapeMarkdown(item.TranslatedValue) + " | " + EscapeMarkdown(item.Comment) + " |\n"); } else { sw.Write("| " + item.Key + " | " + EscapeMarkdown(item.DefaultValue) + " | | " + EscapeMarkdown(item.Comment) + " |\n"); } } } Console.WriteLine("Markdown file written: '" + fileName + "'"); } catch (Exception ex) { Console.WriteLine("Could not write markdown file '" + fileName + "'"); Console.WriteLine(ex.Message); } }
/// <summary> /// Method to read a row from a comment table /// </summary> /// <param name="worksheet">Worksheet object as reference</param> /// <param name="items">Translation item list as reference</param> /// <param name="row">Current row number of the table</param> private static void ReadCommentRow(Worksheet worksheet, List <TranslationItem> items, int row) { TranslationItem item = new TranslationItem(); if (worksheet.HasCell(0, row)) { item.Key = worksheet.GetCell(0, row).Value.ToString(); } if (worksheet.HasCell(1, row)) { item.Comment = worksheet.GetCell(1, row).Value.ToString(); } items.Add(item); }