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: if inside string ignore text-delimiters #66

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
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
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
Loading