Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bugfix in processing when encoding CSV #202

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions slang/lib/src/builder/utils/file_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,23 @@ class FileUtils {
return escaped;
}

Map<String, String> encodeRow({
void encodeCsvRows({
String key = '',
required dynamic value,
required Map<String, String> 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<String, Map<String, String>> columns = {};
Expand All @@ -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 = <String, String>{};
encodeCsvRows(result: result, value: e.value);

columns[e.key] = result;
}

// get all translation keys
Expand Down