Skip to content

Commit

Permalink
Fix csv export for menu files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-muffin committed Nov 21, 2024
1 parent 5c2f7c8 commit 66faa8c
Showing 1 changed file with 61 additions and 44 deletions.
105 changes: 61 additions & 44 deletions TranslationLib/XMLFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,43 +131,60 @@ public void SaveToDisk()

public void SaveAsCsv(string path)
{
bool hasSpeakers = Speakers != null;
using (StreamWriter writer = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.Write), new System.Text.UTF8Encoding(true)))
{
writer.WriteLine("File,Line Number,Section,Status,Speaker JP,Text JP,Speaker EN,Text EN,Comment");
writer.WriteLine(
Name + ".xml" + "," +
"," +
"Friendly Name" + "," +
"," +
"," +
"\"" + (FriendlyName ?? "").Replace("\"", "\"\"") + "\"" + "," +
"," +
"\"" + (FriendlyName ?? "").Replace("\"", "\"\"") + "\"" + ","
);

// header
writer.Write("File,");
writer.Write("Line Number,");
writer.Write("Section,");
writer.Write("Status,");
if (hasSpeakers) writer.Write("Speaker JP,");
writer.Write("Text JP,");
if (hasSpeakers) writer.Write("Speaker EN,");
writer.Write("Text EN,");
writer.Write("Comment");
writer.WriteLine();

// ident
writer.Write(Name + ".xml" + ",");
writer.Write(",");
writer.Write("Friendly Name,");
writer.Write(",");
if (hasSpeakers) writer.Write(",");
writer.Write("\"" + (FriendlyName ?? "<null>").Replace("\"", "\"\"") + "\"" + ",");
if (hasSpeakers) writer.Write(",");
writer.Write("\"" + (FriendlyName ?? "<null>").Replace("\"", "\"\"") + "\"" + ",");
writer.Write("");
writer.WriteLine();

// Speakers
Dictionary<int, string> en_names = new Dictionary<int, string>();
Dictionary<int, string> jp_names = new Dictionary<int, string>();
foreach (XMLEntry entry in Speakers)
if (hasSpeakers)
{
string en_name = (entry.EnglishText ?? "").Replace("\"", "\"\"");
string jp_name = (entry.JapaneseText ?? "").Replace("\"", "\"\"");
writer.WriteLine(
Name + ".xml" + "," +
entry.Id + "," +
"Speaker" + "," +
"," +
"," +
"\"" + jp_name + "\"" + "," +
"" + "," +
"\"" + en_name + "\"" + "," +
"\"" + entry.Notes + "\""
);

en_names.Add(entry.Id.Value, en_name);
jp_names.Add(entry.Id.Value, jp_name);
foreach (XMLEntry entry in Speakers)
{
string en_name = (entry.EnglishText ?? "<null>").Replace("\"", "\"\"");
string jp_name = (entry.JapaneseText ?? "<null>").Replace("\"", "\"\"");
writer.WriteLine(
Name + ".xml" + "," +
entry.Id + "," +
"Speaker" + "," +
entry.Status + "," +
"," +
"\"" + jp_name + "\"" + "," +
"" + "," +
"\"" + en_name + "\"" + "," +
"\"" + entry.Notes + "\""
);

en_names.Add(entry.Id.Value, en_name);
jp_names.Add(entry.Id.Value, jp_name);
}
}


// Text lines
foreach (XMLSection section in Sections.Where(s => s.Name != "All strings"))
{
foreach (XMLEntry entry in section.Entries)
Expand All @@ -194,20 +211,20 @@ public void SaveAsCsv(string path)
jp_name += "[" + string.Join(" / ", jp).Replace("\"", "\"\"") + "]";
}

string en_text = entry.EnglishText ?? "";
string jp_text = entry.JapaneseText ?? "";

writer.WriteLine(
Name + ".xml" + "," +
entry.Id + "," +
"\"" + section.Name.Replace("\"", "\"\"") + "\"" + "," +
entry.Status + "," +
"\"" + jp_name + "\"" + "," +
"\"" + jp_text.Replace("\"", "\"\"") + "\"" + "," +
"\"" + en_name + "\"" + "," +
"\"" + en_text.Replace("\"", "\"\"") + "\"" + "," +
"\"" + entry.Notes + "\""
);
string en_text = entry.EnglishText ?? "<null>";
string jp_text = entry.JapaneseText ?? "<null>";

// ident
writer.Write(Name + ".xml" + ",");
writer.Write(entry.Id + ",");
writer.Write("\"" + section.Name.Replace("\"", "\"\"") + "\"" + ",");
writer.Write(entry.Status + ",");
if (hasSpeakers) writer.Write("\"" + jp_name + "\"" + ",");
writer.Write("\"" + jp_text.Replace("\"", "\"\"") + "\"" + ",");
if (hasSpeakers) writer.Write("\"" + en_name + "\"" + ",");
writer.Write("\"" + en_text.Replace("\"", "\"\"") + "\"" + ",");
writer.Write("\"" + entry.Notes + "\"");
writer.WriteLine();
}
}
}
Expand Down

0 comments on commit 66faa8c

Please sign in to comment.