Skip to content

Commit 1f9f028

Browse files
authored
fix: if inside string ignore text-delimiters (#66)
* fix: if inside string ignore text-delimiters * test cases added * added useAutodetect as optional parameter
1 parent eb9ab5f commit 1f9f028

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/src/csv_asset_loader.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ import 'package:flutter/services.dart';
1111
//
1212
class CsvAssetLoader extends AssetLoader {
1313
CSVParser? csvParser;
14+
final bool useAutodetect;
15+
16+
CsvAssetLoader({
17+
this.useAutodetect = true,
18+
});
1419

1520
@override
1621
Future<Map<String, dynamic>> load(String path, Locale locale) async {
1722
if (csvParser == null) {
1823
log('easy localization loader: load csv file $path');
19-
csvParser = CSVParser(await rootBundle.loadString(path));
24+
csvParser = CSVParser(
25+
await rootBundle.loadString(path),
26+
useAutodetect: useAutodetect,
27+
);
2028
} else {
2129
log('easy localization loader: CSV parser already loaded, read cache');
2230
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ environment:
1111

1212
dependencies:
1313
connectivity_plus: ^5.0.1
14-
csv: ^5.0.1
14+
csv: ^6.0.0
1515
easy_localization: ^3.0.3
1616
flutter: { sdk: flutter }
1717
http: ^1.1.0

test/easy_localization_loader_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ void main() {
1313
'str\ten_US\t$localeName\r\nscreen_language\tInterface language\tЯзык интерфейса\r\n';
1414
const testCommaCRLFString =
1515
'str,en_US,$localeName\r\nscreen_language,Interface language,Язык интерфейса\r\n';
16+
const testCommaQuotesInsideCRLFString =
17+
'str,en_US,$localeName\r\nscreen_language,"Interface language, Test","Язык интерфейса, Тест"\r\n';
1618

1719
Map<String, dynamic> getResult(
1820
String testString,
@@ -45,6 +47,11 @@ void main() {
4547
{'screen_language': 'Язык интерфейса'},
4648
getResult(testCommaCRLFString, localeName),
4749
);
50+
output(
51+
'testCommaQuotesInsideCRLFString'.toUpperCase(),
52+
{'screen_language': 'Язык интерфейса, Тест'},
53+
getResult(testCommaQuotesInsideCRLFString, localeName, false),
54+
);
4855
output(
4956
'testTabLFString, autodetect = false'.toUpperCase(),
5057
{},

0 commit comments

Comments
 (0)