From 03f4eb30ed8bab06b3d64a546b3a2bf129a43858 Mon Sep 17 00:00:00 2001 From: Kazbek Date: Tue, 6 Feb 2024 03:49:24 +0300 Subject: [PATCH] =?UTF-8?q?Csv=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=B2=D1=8B=D0=BF=D0=B8=D1=81=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BF=D1=83=D1=81=D1=82=D1=8B=D0=B5=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D0=B8=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8=20=D0=BD=D0=B0=D1=87=D0=B8=D0=BD=D0=B0=D1=8E?= =?UTF-8?q?=D1=89=D0=B8=D0=B5=D1=81=D1=8F=20=D1=81=20#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Common/Utils/CsvUtils.cs | 8 +++++++- Src/Localizer/Localizers/CsvGeneralLocalizer.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Src/Common/Utils/CsvUtils.cs b/Src/Common/Utils/CsvUtils.cs index 7104c6b..53d768c 100644 --- a/Src/Common/Utils/CsvUtils.cs +++ b/Src/Common/Utils/CsvUtils.cs @@ -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 })) @@ -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]); diff --git a/Src/Localizer/Localizers/CsvGeneralLocalizer.cs b/Src/Localizer/Localizers/CsvGeneralLocalizer.cs index 58e9ff0..ded4eef 100644 --- a/Src/Localizer/Localizers/CsvGeneralLocalizer.cs +++ b/Src/Localizer/Localizers/CsvGeneralLocalizer.cs @@ -53,7 +53,7 @@ public static int Localize(string csvPath, CsvDictionary dictionary) } } - CsvUtils.Save(dataTable, csvPath); + CsvUtils.Save(dataTable, csvPath, true); return translationCount; }