From 1f9f028204698bcad4e143af0c352a396ce64b38 Mon Sep 17 00:00:00 2001 From: nafiskabbo Date: Tue, 7 May 2024 18:27:52 +0600 Subject: [PATCH] fix: if inside string ignore text-delimiters (#66) * fix: if inside string ignore text-delimiters * test cases added * added useAutodetect as optional parameter --- lib/src/csv_asset_loader.dart | 10 +++++++++- pubspec.yaml | 2 +- test/easy_localization_loader_test.dart | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/src/csv_asset_loader.dart b/lib/src/csv_asset_loader.dart index e363570..2a7ecfb 100644 --- a/lib/src/csv_asset_loader.dart +++ b/lib/src/csv_asset_loader.dart @@ -11,12 +11,20 @@ import 'package:flutter/services.dart'; // class CsvAssetLoader extends AssetLoader { CSVParser? csvParser; + final bool useAutodetect; + + CsvAssetLoader({ + this.useAutodetect = true, + }); @override Future> 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'); } diff --git a/pubspec.yaml b/pubspec.yaml index f4e9b0c..fa54fa9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/easy_localization_loader_test.dart b/test/easy_localization_loader_test.dart index 184340f..10b2bdb 100644 --- a/test/easy_localization_loader_test.dart +++ b/test/easy_localization_loader_test.dart @@ -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 getResult( String testString, @@ -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(), {},