Skip to content

Commit

Permalink
Csv больше не выписывает пустые строки и строки начинающиеся с #
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazbek committed Feb 6, 2024
1 parent f955a29 commit 03f4eb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Src/Common/Utils/CsvUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static Stream SaveToStream(DataTable dataTable)
return ms;
}

public static void Save(DataTable dataTable, string path)
public static void Save(DataTable dataTable, string path, bool skipComments)
{
using (var textWriter = File.CreateText(path))
using (var csv = new CsvWriter(textWriter, new CsvConfiguration(CultureInfo.InvariantCulture) { Encoding = Encoding.UTF8 }))
Expand All @@ -84,6 +84,12 @@ public static void Save(DataTable dataTable, string path)
// Write row values
foreach (DataRow row in dataTable.Rows)
{
if (row.ItemArray.Length == 0)
continue;

if (skipComments && row[0] is string text && text.StartsWith("#"))
continue;

for (var i = 0; i < dataTable.Columns.Count; i++)
{
csv.WriteField(row[i]);
Expand Down
2 changes: 1 addition & 1 deletion Src/Localizer/Localizers/CsvGeneralLocalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static int Localize(string csvPath, CsvDictionary dictionary)
}
}

CsvUtils.Save(dataTable, csvPath);
CsvUtils.Save(dataTable, csvPath, true);

return translationCount;
}
Expand Down

0 comments on commit 03f4eb3

Please sign in to comment.