Skip to content

Commit

Permalink
Changed how line endings are handled in import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
thesupersonic16 committed Sep 8, 2024
1 parent c91b993 commit 622e0d6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions DALTools/DALLib/ImportExport/TranslationCSVFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public string[] ReadCSVRow()
// Next column
if (!escape && _buffer[_bufferIndex] == ',')
{
splits.Add(buffer.Replace("\r", "").Replace("\n", "\\n"));
splits.Add(buffer.Replace("\r", "").Replace("\\n", "\n"));
buffer = "";
continue;
}
Expand All @@ -100,7 +100,7 @@ public string[] ReadCSVRow()
{
_bufferIndex = _bufferIndex + 1;
// Escape the LF and add the last column
splits.Add(buffer.Replace("\r", "").Replace("\n", "\\n"));
splits.Add(buffer.Replace("\r", "").Replace("\\n", "\n"));
break;
}
// Add char
Expand All @@ -113,9 +113,9 @@ public string AddRow(params string[] fields)
{
for (int i = 0; i < fields.Length; ++i)
{
// Add double-quotes if field contains an escaped line feed
if (fields[i].Length > 0 && fields[i][0] != '"' && fields[i].Contains("\\n"))
fields[i] = $"\"{fields[i].Replace("\\n", LINEBREAK)}\"";
if (fields[i].Length > 0 && fields[i][0] != '"' &&
(fields[i].Contains("\n") || fields[i].Contains(",")))
fields[i] = $"\"{fields[i].Replace("\n", "\\n")}\"";
}
return string.Join(",", fields) + LINEBREAK;
}
Expand Down
6 changes: 3 additions & 3 deletions DALTools/DALLib/ImportExport/TranslationPOFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public override TranslationLine[] ImportTranslation(string data)
continue;

if (line.StartsWith("msgid"))
id = line.Substring(7, line.Length - 8).Replace("\\\"", "\"");
id = line.Substring(7, line.Length - 8).Replace("\\\"", "\"").Replace("\\n", "\n");
if (line.StartsWith("msgstr"))
{
str = line.Substring(8, line.Length - 9).Replace("\\\"", "\"");
str = line.Substring(8, line.Length - 9).Replace("\\\"", "\"").Replace("\\n", "\n");
lines.Add(new TranslationLine("", "", id, str));
}
}
Expand All @@ -48,7 +48,7 @@ public override string ExportTranslation(TranslationLine[] lines)

// Fields
foreach (var translation in lines)
AddEntry(translation.Comment, translation.Key);
AddEntry(translation.Comment, translation.Key.Replace("\n", "\\n"));

return FinaliseExport();
}
Expand Down
4 changes: 2 additions & 2 deletions DALTools/DALLib/ImportExport/TranslationSTSCHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public static TranslationLine[] ExportTranslationLines(STSC2File script, Diction
break;
case "Mes":
// Add Entry to file
string name = names.ContainsKey(nameID) ? names[nameID] : $"0x{nameID:X2}";
lines.Add(new TranslationLine("Message", $"Unknown [{name}]", line.arguments[3] as string));
string name = names.ContainsKey(nameID) ? names[nameID] : $"Unknown 0x{nameID:X2}";
lines.Add(new TranslationLine("Message", name, line.arguments[3] as string));
break;
case "Choice":
case "SetChoice":
Expand Down
10 changes: 5 additions & 5 deletions DALTools/DALLib/ImportExport/TranslationTSVFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public string[] ReadTSVRow()
// Next column
if (!escape && _buffer[_bufferIndex] == '\t')
{
splits.Add(buffer.Replace("\r", "").Replace("\n", "\\n"));
splits.Add(buffer.Replace("\r", "").Replace("\\n", "\n"));
buffer = "";
continue;
}
Expand All @@ -100,7 +100,7 @@ public string[] ReadTSVRow()
{
_bufferIndex = _bufferIndex + 1;
// Escape the LF and add the last column
splits.Add(buffer.Replace("\r", "").Replace("\n", "\\n"));
splits.Add(buffer.Replace("\r", "").Replace("\\n", "\n"));
break;
}
// Add char
Expand All @@ -113,9 +113,9 @@ public string AddRow(params string[] fields)
{
for (int i = 0; i < fields.Length; ++i)
{
// Add double-quotes if field contains an escaped line feed
if (fields[i].Length > 0 && fields[i][0] != '"' && fields[i].Contains("\\n"))
fields[i] = $"\"{fields[i].Replace("\\n", LINEBREAK)}\"";
if (fields[i].Length > 0 && fields[i][0] != '"' &&
(fields[i].Contains("\n")))
fields[i] = $"\"{fields[i].Replace("\n", "\\n")}\"";
}
return string.Join("\t", fields) + LINEBREAK;
}
Expand Down

0 comments on commit 622e0d6

Please sign in to comment.