Skip to content

Commit

Permalink
fix: if inside string ignore text-delimiters (#66)
Browse files Browse the repository at this point in the history
* fix: if inside string ignore text-delimiters

* test cases added

* added useAutodetect as optional parameter
  • Loading branch information
nafiskabbo authored May 7, 2024
1 parent eb9ab5f commit 1f9f028
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/src/csv_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ import 'package:flutter/services.dart';
//
class CsvAssetLoader extends AssetLoader {
CSVParser? csvParser;
final bool useAutodetect;

CsvAssetLoader({
this.useAutodetect = true,
});

@override
Future<Map<String, dynamic>> load(String path, Locale locale) async {
if (csvParser == null) {
log('easy localization loader: load csv file $path');
csvParser = CSVParser(await rootBundle.loadString(path));
csvParser = CSVParser(
await rootBundle.loadString(path),
useAutodetect: useAutodetect,
);
} else {
log('easy localization loader: CSV parser already loaded, read cache');
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:

dependencies:
connectivity_plus: ^5.0.1
csv: ^5.0.1
csv: ^6.0.0
easy_localization: ^3.0.3
flutter: { sdk: flutter }
http: ^1.1.0
Expand Down
7 changes: 7 additions & 0 deletions test/easy_localization_loader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ void main() {
'str\ten_US\t$localeName\r\nscreen_language\tInterface language\tЯзык интерфейса\r\n';
const testCommaCRLFString =
'str,en_US,$localeName\r\nscreen_language,Interface language,Язык интерфейса\r\n';
const testCommaQuotesInsideCRLFString =
'str,en_US,$localeName\r\nscreen_language,"Interface language, Test","Язык интерфейса, Тест"\r\n';

Map<String, dynamic> getResult(
String testString,
Expand Down Expand Up @@ -45,6 +47,11 @@ void main() {
{'screen_language': 'Язык интерфейса'},
getResult(testCommaCRLFString, localeName),
);
output(
'testCommaQuotesInsideCRLFString'.toUpperCase(),
{'screen_language': 'Язык интерфейса, Тест'},
getResult(testCommaQuotesInsideCRLFString, localeName, false),
);
output(
'testTabLFString, autodetect = false'.toUpperCase(),
{},
Expand Down

0 comments on commit 1f9f028

Please sign in to comment.