From d70c7b3d50856110f1abe20b057e36debd8efd50 Mon Sep 17 00:00:00 2001 From: nikaera Date: Sun, 17 Mar 2024 16:36:55 +0900 Subject: [PATCH] fix: bugfix in processing when encoding CSV --- slang/lib/src/builder/utils/file_utils.dart | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/slang/lib/src/builder/utils/file_utils.dart b/slang/lib/src/builder/utils/file_utils.dart index 01e4452b..079d33f4 100644 --- a/slang/lib/src/builder/utils/file_utils.dart +++ b/slang/lib/src/builder/utils/file_utils.dart @@ -52,22 +52,23 @@ class FileUtils { return escaped; } - Map encodeRow({ + void encodeCsvRows({ String key = '', required dynamic value, + required Map result, }) { if (value is Map) { - final keyPrefix = key.isEmpty ? '' : '$key.'; - return value.map((k, v) { - final map = encodeRow(key: '$keyPrefix$k', value: v); - final mapEntry = map.entries.first; - - return MapEntry(mapEntry.key, mapEntry.value); - }); + for (final k in value.keys) { + final prefix = key.isEmpty ? '' : '$key.'; + encodeCsvRows( + key: '$prefix$k', + value: value[k], + result: result, + ); + } } else if (value is String) { - return {key: escapeRow(value)}; + result[key] = escapeRow(value); } - return {}; } final Map> columns = {}; @@ -76,7 +77,10 @@ class FileUtils { columns[INFO_KEY] = {INFO_KEY: escapeRow(info.join('\\n'))}; } for (final e in content.entries) { - columns[e.key] = encodeRow(value: e.value); + final result = {}; + encodeCsvRows(result: result, value: e.value); + + columns[e.key] = result; } // get all translation keys