L10nSheet constructor
Implementation
factory L10nSheet(Sheet sheet, List<List<String?>> data) {
final map = <String, DataRow>{};
List<String>? headers;
try {
headers = data.firstOrNull?.map((e) => e!).toList();
} catch (e) {
throw _SheetHeaderFormatError('$sheet');
}
if (headers == null) {
return const L10nSheet.empty();
}
if (headers case ['key', 'description', ...final List<String> languages]) {
for (var i = 1; i < data.length; i++) {
final row = data[i];
final key = row.firstOrNull;
if (key != null) {
if (map[key] != null) {
print(
'warning: Key "$key" in sheet "$sheet" is duplicated, '
'the latter one will be kept',
);
}
map[key] = DataRow(
source: sheet,
description: row[1],
data: {
for (var j = 2; j < row.length; j++) headers[j]: row[j],
},
);
} else {
print(
'warning: The key in row ${i + 1} of sheet "$sheet" is empty',
);
}
}
return L10nSheet.raw(map, languages);
}
throw _SheetHeaderFormatError('$sheet');
}