From 8a9837be03d69148a54fe83f964f541379132bf5 Mon Sep 17 00:00:00 2001 From: Frankdroid7 Date: Wed, 19 Apr 2023 15:19:38 +0100 Subject: [PATCH 01/16] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a1413d7..9d66a8b 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ dependencies: ``` -2. Change assetLoader and patch +2. Change assetLoader and path ```dart ... @@ -54,4 +54,4 @@ void main(){ ... ``` -3. All done!. \ No newline at end of file +3. All done!. From b24e85cb6f631ca559c255aadf1c3b96a6a57125 Mon Sep 17 00:00:00 2001 From: Alexey Inkin Date: Mon, 26 Jun 2023 13:51:06 +0400 Subject: [PATCH 02/16] Delete local AssetLoader class, update dependencies (#46) --- CHANGELOG.md | 19 +++++++++++++++-- lib/easy_localization_loader.dart | 12 +++++------ lib/src/asset_loader.dart | 27 ------------------------- lib/src/csv_asset_loader.dart | 3 +-- lib/src/file_asset_loader.dart | 8 +++----- lib/src/http_asset_loader.dart | 9 +++------ lib/src/json_asset_loader.dart | 7 ++++--- lib/src/smart_network_asset_loader.dart | 3 +-- lib/src/tests_asset_loader.dart | 5 +++-- lib/src/xml_asset_loader.dart | 7 ++++--- lib/src/yaml_asset_loader.dart | 7 ++++--- pubspec.yaml | 17 ++++++++-------- 12 files changed, 53 insertions(+), 71 deletions(-) delete mode 100644 lib/src/asset_loader.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index b0a20b7..2454fdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ -## [0.0.1] +## 2.0.0 -- initial release +- **BREAKING**: The local `AssetLoader` class deleted, now using the one from + [easy_localization](https://pub.dev/documentation/easy_localization/latest/easy_localization/AssetLoader-class.html) itself. +- **BREAKING**: `JsonAssetLoader`, `XmlAssetLoader`, and `YamlAssetLoader` now use `_` instead of `-` when converting a locale to a file name. +- **BREAKING**: Depends on [connectivity_plus](https://pub.dev/packages/connectivity_plus) ^4.0.0 + and [http](https://pub.dev/packages/http) ^1.0.0. +- Const constructors in: + - `FileAssetLoader` + - `HttpAssetLoader` + - `JsonAssetLoader` + - `TestsAssetLoader` + - `XmlAssetLoader` + - `YamlAssetLoader` + +## 0.0.1 + +- Initial release. diff --git a/lib/easy_localization_loader.dart b/lib/easy_localization_loader.dart index 70d7b8e..683b29e 100644 --- a/lib/easy_localization_loader.dart +++ b/lib/easy_localization_loader.dart @@ -1,10 +1,8 @@ -library easy_localization_loader; - +export 'package:easy_localization_loader/src/csv_asset_loader.dart'; export 'package:easy_localization_loader/src/file_asset_loader.dart'; -export 'package:easy_localization_loader/src/json_asset_loader.dart'; export 'package:easy_localization_loader/src/http_asset_loader.dart'; -export 'package:easy_localization_loader/src/csv_asset_loader.dart'; -export 'package:easy_localization_loader/src/yaml_asset_loader.dart'; -export 'package:easy_localization_loader/src/xml_asset_loader.dart'; -export 'package:easy_localization_loader/src/tests_asset_loader.dart'; +export 'package:easy_localization_loader/src/json_asset_loader.dart'; export 'package:easy_localization_loader/src/smart_network_asset_loader.dart'; +export 'package:easy_localization_loader/src/tests_asset_loader.dart'; +export 'package:easy_localization_loader/src/xml_asset_loader.dart'; +export 'package:easy_localization_loader/src/yaml_asset_loader.dart'; diff --git a/lib/src/asset_loader.dart b/lib/src/asset_loader.dart deleted file mode 100644 index 9e6015d..0000000 --- a/lib/src/asset_loader.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'dart:ui'; - -// show AssetLoader; - -abstract class AssetLoader { - const AssetLoader(); - Future> load(String path, Locale locale); -} - -Locale localeFromString(String localeString) { - final localeList = localeString.split('_'); - switch (localeList.length) { - case 2: - return Locale(localeList.first, localeList.last); - case 3: - return Locale.fromSubtags( - languageCode: localeList.first, - scriptCode: localeList[1], - countryCode: localeList.last); - default: - return Locale(localeList.first); - } -} - -String localeToString(Locale locale, {String separator = '_'}) { - return locale.toString().split('_').join(separator); -} diff --git a/lib/src/csv_asset_loader.dart b/lib/src/csv_asset_loader.dart index 7c2c483..612f012 100644 --- a/lib/src/csv_asset_loader.dart +++ b/lib/src/csv_asset_loader.dart @@ -3,10 +3,9 @@ import 'dart:ui'; import 'package:csv/csv.dart'; import 'package:csv/csv_settings_autodetection.dart'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/services.dart'; -import 'asset_loader.dart'; - // // load example/resources/langs/langs.csv // diff --git a/lib/src/file_asset_loader.dart b/lib/src/file_asset_loader.dart index c52989d..8346843 100644 --- a/lib/src/file_asset_loader.dart +++ b/lib/src/file_asset_loader.dart @@ -3,13 +3,11 @@ import 'dart:developer'; import 'dart:io'; import 'dart:ui'; -import 'asset_loader.dart'; +import 'package:easy_localization/easy_localization.dart'; -// -// -// -// class FileAssetLoader extends AssetLoader { + const FileAssetLoader(); + @override Future> load(String path, Locale locale) async { final file = File(path); diff --git a/lib/src/http_asset_loader.dart b/lib/src/http_asset_loader.dart index 6e31e14..1687294 100644 --- a/lib/src/http_asset_loader.dart +++ b/lib/src/http_asset_loader.dart @@ -1,16 +1,13 @@ -// -// -// -// import 'dart:convert'; import 'dart:developer'; import 'dart:ui'; +import 'package:easy_localization/easy_localization.dart'; import 'package:http/http.dart' as http; -import 'asset_loader.dart'; - class HttpAssetLoader extends AssetLoader { + const HttpAssetLoader(); + @override Future> load(String path, Locale locale) async { log('easy localization loader: load http $path'); diff --git a/lib/src/json_asset_loader.dart b/lib/src/json_asset_loader.dart index aee968a..dc9f62c 100644 --- a/lib/src/json_asset_loader.dart +++ b/lib/src/json_asset_loader.dart @@ -2,13 +2,14 @@ import 'dart:convert'; import 'dart:developer'; import 'dart:ui'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/services.dart'; -import 'asset_loader.dart'; - class JsonAssetLoader extends AssetLoader { + const JsonAssetLoader(); + String getLocalePath(String basePath, Locale locale) { - return '$basePath/${localeToString(locale, separator: "-")}.json'; + return '$basePath/$locale.json'; } @override diff --git a/lib/src/smart_network_asset_loader.dart b/lib/src/smart_network_asset_loader.dart index bbe7e0c..315dabe 100644 --- a/lib/src/smart_network_asset_loader.dart +++ b/lib/src/smart_network_asset_loader.dart @@ -2,13 +2,12 @@ import 'dart:convert'; import 'dart:io'; import 'dart:ui'; import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:easy_localization/easy_localization.dart'; import 'package:http/http.dart' as http; import 'package:path_provider/path_provider.dart' as paths; import 'package:flutter/services.dart'; -import 'asset_loader.dart'; - /// ```dart /// SmartNetworkAssetLoader( /// assetsPath: 'assets/translations', diff --git a/lib/src/tests_asset_loader.dart b/lib/src/tests_asset_loader.dart index f17c1fa..60958da 100644 --- a/lib/src/tests_asset_loader.dart +++ b/lib/src/tests_asset_loader.dart @@ -2,14 +2,15 @@ import 'dart:convert'; import 'dart:ui'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/services.dart'; -import 'asset_loader.dart'; - // asset loader to be used when doing integration tests // default AssetLoader suffers from this issue // https://github.com/flutter/flutter/issues/44182 class TestsAssetLoader extends AssetLoader { + const TestsAssetLoader(); + @override Future> load(String path, Locale locale) async { final byteData = await rootBundle.load(path); diff --git a/lib/src/xml_asset_loader.dart b/lib/src/xml_asset_loader.dart index 68b265b..8900ff0 100644 --- a/lib/src/xml_asset_loader.dart +++ b/lib/src/xml_asset_loader.dart @@ -1,15 +1,16 @@ import 'dart:developer'; import 'dart:ui'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/services.dart'; import 'package:xml/xml.dart'; -import 'asset_loader.dart'; - //Loader for multiple xml files class XmlAssetLoader extends AssetLoader { + const XmlAssetLoader(); + String getLocalePath(String basePath, Locale locale) { - return '$basePath/${localeToString(locale, separator: "-")}.xml'; + return '$basePath/$locale.xml'; } @override diff --git a/lib/src/yaml_asset_loader.dart b/lib/src/yaml_asset_loader.dart index 52135b8..e9c79cb 100644 --- a/lib/src/yaml_asset_loader.dart +++ b/lib/src/yaml_asset_loader.dart @@ -1,15 +1,16 @@ import 'dart:developer'; import 'dart:ui'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/services.dart'; import 'package:yaml/yaml.dart'; -import 'asset_loader.dart'; - //Loader for multiple yaml files class YamlAssetLoader extends AssetLoader { + const YamlAssetLoader(); + String getLocalePath(String basePath, Locale locale) { - return '$basePath/${localeToString(locale, separator: "-")}.yaml'; + return '$basePath/$locale.yaml'; } @override diff --git a/pubspec.yaml b/pubspec.yaml index 32a118c..810fa34 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,22 +4,21 @@ description: Easy Localization Loader custom assets loaders for easy_localizatio homepage: https://github.com/aissat/easy_localization_loader issue_tracker: https://github.com/aissat/easy_localization_loader/issues -version: 1.0.1+1 +version: 2.0.0 environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.12.0 <4.0.0' dependencies: - http: ^0.13.5 + connectivity_plus: ^4.0.0 csv: ^5.0.1 - yaml: ^3.1.1 - xml: ^6.1.0 - flutter: - sdk: flutter - connectivity_plus: ^2.3.7 + easy_localization: ^3.0.2 + flutter: { sdk: flutter } + http: ^1.0.0 path_provider: ^2.0.11 + xml: ^6.1.0 + yaml: ^3.1.1 dev_dependencies: pedantic: ^1.11.1 test: ^1.21.6 - From 93f83d9853c0d5fb1a72ef86eb9f8fc913cb388a Mon Sep 17 00:00:00 2001 From: Alexey Inkin Date: Tue, 27 Jun 2023 16:46:56 +0400 Subject: [PATCH 03/16] Undo the breaking change of file names (#46) --- CHANGELOG.md | 1 - lib/src/json_asset_loader.dart | 2 +- lib/src/xml_asset_loader.dart | 2 +- lib/src/yaml_asset_loader.dart | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2454fdf..10fd070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ - **BREAKING**: The local `AssetLoader` class deleted, now using the one from [easy_localization](https://pub.dev/documentation/easy_localization/latest/easy_localization/AssetLoader-class.html) itself. -- **BREAKING**: `JsonAssetLoader`, `XmlAssetLoader`, and `YamlAssetLoader` now use `_` instead of `-` when converting a locale to a file name. - **BREAKING**: Depends on [connectivity_plus](https://pub.dev/packages/connectivity_plus) ^4.0.0 and [http](https://pub.dev/packages/http) ^1.0.0. - Const constructors in: diff --git a/lib/src/json_asset_loader.dart b/lib/src/json_asset_loader.dart index dc9f62c..08e1cc5 100644 --- a/lib/src/json_asset_loader.dart +++ b/lib/src/json_asset_loader.dart @@ -9,7 +9,7 @@ class JsonAssetLoader extends AssetLoader { const JsonAssetLoader(); String getLocalePath(String basePath, Locale locale) { - return '$basePath/$locale.json'; + return '$basePath/${locale.toStringWithSeparator(separator: "-")}.json'; } @override diff --git a/lib/src/xml_asset_loader.dart b/lib/src/xml_asset_loader.dart index 8900ff0..15f9279 100644 --- a/lib/src/xml_asset_loader.dart +++ b/lib/src/xml_asset_loader.dart @@ -10,7 +10,7 @@ class XmlAssetLoader extends AssetLoader { const XmlAssetLoader(); String getLocalePath(String basePath, Locale locale) { - return '$basePath/$locale.xml'; + return '$basePath/${locale.toStringWithSeparator(separator: "-")}.xml'; } @override diff --git a/lib/src/yaml_asset_loader.dart b/lib/src/yaml_asset_loader.dart index e9c79cb..a4ddbf2 100644 --- a/lib/src/yaml_asset_loader.dart +++ b/lib/src/yaml_asset_loader.dart @@ -10,7 +10,7 @@ class YamlAssetLoader extends AssetLoader { const YamlAssetLoader(); String getLocalePath(String basePath, Locale locale) { - return '$basePath/$locale.yaml'; + return '$basePath/${locale.toStringWithSeparator(separator: "-")}.yaml'; } @override From 8fea7191d01aa86dd1b631593840f3f2bbea11a4 Mon Sep 17 00:00:00 2001 From: BW Personal Date: Fri, 29 Sep 2023 09:43:16 +0200 Subject: [PATCH 04/16] contributing.md --- CONTRIBUTING.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..4570e50 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,11 @@ +# Contributing + +## Release process + + 1. Make sure that the changelog is updated + + 2. Make sure that the version in pubspec.yaml is correct + + 3. Create a release in the github UI. Name the release like the version, but with a v (3.7.5 -> v3.7.5). Name the tag like the release + + 4. A pipeline will run and deploy the new version to pub.dev From c48445426419a851895df12bdd39348873f45d95 Mon Sep 17 00:00:00 2001 From: BW Personal Date: Fri, 29 Sep 2023 09:44:06 +0200 Subject: [PATCH 05/16] added pipelines --- .github/workflows/pr_check.yml | 11 ++++++++++ .github/workflows/release.yml | 39 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 29 +++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 .github/workflows/pr_check.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml new file mode 100644 index 0000000..b1fca1b --- /dev/null +++ b/.github/workflows/pr_check.yml @@ -0,0 +1,11 @@ +name: PR Check + +on: + workflow_dispatch: + pull_request: + +jobs: + test: + name: Test + uses: ./.github/workflows/test.yml + secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..053bd2b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Release to pub.dev + +on: + workflow_dispatch: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' + +jobs: + test: + name: Test + uses: ./.github/workflows/test.yml + secrets: inherit + + publish: + needs: [test] + name: Publish + permissions: + id-token: write # This is required for authentication using OIDC + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v3 + + - uses: dart-lang/setup-dart@v1 + + - uses: subosito/flutter-action@v2 + with: + channel: "stable" + + - name: Install dependencies + run: dart pub get + + - name: code format + run: dart format lib/*/*.dart lib/*.dart + + - name: Publish + run: dart pub publish --force diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ab11363 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: Test + +on: + workflow_call: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: '12.x' + - uses: subosito/flutter-action@v1 + with: + channel: 'stable' + + - name: Install packages dependencies + run: flutter pub get + + - name: Analyze the project's Dart code + run: flutter analyze + + - name: Run tests + run: flutter test + + - name: Run tests coverage + run: flutter test --coverage \ No newline at end of file From 897ed8dac7e60d4d51eb22ff3acd8aa46fe56f53 Mon Sep 17 00:00:00 2001 From: BW Personal Date: Fri, 29 Sep 2023 09:48:44 +0200 Subject: [PATCH 06/16] fix linting problems --- lib/src/http_asset_loader.dart | 2 +- lib/src/xml_asset_loader.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/http_asset_loader.dart b/lib/src/http_asset_loader.dart index 1687294..56a37f0 100644 --- a/lib/src/http_asset_loader.dart +++ b/lib/src/http_asset_loader.dart @@ -18,7 +18,7 @@ class HttpAssetLoader extends AssetLoader { .then((response) => json.decode(response.body.toString())); } catch (e) { //Catch network exceptions - return Future.value(); + return {}; } } } diff --git a/lib/src/xml_asset_loader.dart b/lib/src/xml_asset_loader.dart index 15f9279..a30a148 100644 --- a/lib/src/xml_asset_loader.dart +++ b/lib/src/xml_asset_loader.dart @@ -51,7 +51,7 @@ Map convertXmlNodeToMap(XmlNode xmlNode) { if (entry is XmlElement) { switch (entry.children.length) { case 1: - map[entry.name.toString()] = entry.text; + map[entry.name.toString()] = entry.value; break; case 0: print(entry.name.toString()); From 3407c175134bdf555ffdccdd15a4ba48748efc1d Mon Sep 17 00:00:00 2001 From: BW Personal Date: Fri, 29 Sep 2023 09:54:15 +0200 Subject: [PATCH 07/16] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10fd070..c12409e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - `TestsAssetLoader` - `XmlAssetLoader` - `YamlAssetLoader` +- Fixed deprecations ## 0.0.1 From 3bf6e591ba7462e8fb409c303115c9e54e2782e9 Mon Sep 17 00:00:00 2001 From: BW Personal Date: Fri, 29 Sep 2023 09:56:11 +0200 Subject: [PATCH 08/16] devversion --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 810fa34..1e4220d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: Easy Localization Loader custom assets loaders for easy_localizatio homepage: https://github.com/aissat/easy_localization_loader issue_tracker: https://github.com/aissat/easy_localization_loader/issues -version: 2.0.0 +version: 2.0.0-dev.1 environment: sdk: '>=2.12.0 <4.0.0' From 8e60e2e114354a7a759c18ab6b7215915d408ed0 Mon Sep 17 00:00:00 2001 From: BW Personal Date: Fri, 29 Sep 2023 09:56:26 +0200 Subject: [PATCH 09/16] execute now --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 053bd2b..cd2174c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,8 @@ name: Release to pub.dev on: workflow_dispatch: push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+*' + # tags: + # - 'v[0-9]+.[0-9]+.[0-9]+*' jobs: test: From eaa2da1058d4102c2eb90e1f0276808886f4e01b Mon Sep 17 00:00:00 2001 From: BW Personal Date: Fri, 29 Sep 2023 10:09:20 +0200 Subject: [PATCH 10/16] revert temp changes --- .github/workflows/release.yml | 4 ++-- pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cd2174c..053bd2b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,8 @@ name: Release to pub.dev on: workflow_dispatch: push: - # tags: - # - 'v[0-9]+.[0-9]+.[0-9]+*' + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' jobs: test: diff --git a/pubspec.yaml b/pubspec.yaml index 1e4220d..810fa34 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: Easy Localization Loader custom assets loaders for easy_localizatio homepage: https://github.com/aissat/easy_localization_loader issue_tracker: https://github.com/aissat/easy_localization_loader/issues -version: 2.0.0-dev.1 +version: 2.0.0 environment: sdk: '>=2.12.0 <4.0.0' From 5f5139fdc08a20ce85cfb9310ad40d0eab155f2c Mon Sep 17 00:00:00 2001 From: Abdulaziz Rasulbek Date: Thu, 26 Oct 2023 18:43:18 +0500 Subject: [PATCH 11/16] update connectivity_plus, easy_localization, http and path_provider packages to latest version --- pubspec.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 810fa34..778c07e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,12 +10,12 @@ environment: sdk: '>=2.12.0 <4.0.0' dependencies: - connectivity_plus: ^4.0.0 + connectivity_plus: ^5.0.1 csv: ^5.0.1 - easy_localization: ^3.0.2 + easy_localization: ^3.0.3 flutter: { sdk: flutter } - http: ^1.0.0 - path_provider: ^2.0.11 + http: ^1.1.0 + path_provider: ^2.1.1 xml: ^6.1.0 yaml: ^3.1.1 From f432cbf391857673ae1e892f72950e9d67e11e70 Mon Sep 17 00:00:00 2001 From: Vladyslav Len Date: Mon, 30 Oct 2023 09:12:23 +0100 Subject: [PATCH 12/16] Improving on HttpAssetLoader (#49) * Update README.md * chore(): upgraded deps * chore(): load concrete location * fix(): correct decoding of cyrillic chars * chore(): updated readme. added HttpAssetLoader doc * fix(doc): update dir structure * Delete local AssetLoader class, update dependencies (#46) * Undo the breaking change of file names (#46) * contributing.md * added pipelines * fix linting problems * changelog * devversion * execute now * revert temp changes * update connectivity_plus, easy_localization, http and path_provider packages to latest version * chore(): upgraded deps * chore(): load concrete location * fix(): correct decoding of cyrillic chars * chore(): updated readme. added HttpAssetLoader doc * fix(doc): update dir structure --------- Co-authored-by: Frankdroid7 Co-authored-by: Alexey Inkin Co-authored-by: Benjamin Weber <89379862+bw-flagship@users.noreply.github.com> Co-authored-by: BW Personal Co-authored-by: Abdulaziz Rasulbek --- .gitignore | 1 + README.md | 16 ++++++++++++++++ lib/src/http_asset_loader.dart | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5b89f90..e37c091 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ *.ipr *.iws .idea/ +.vscode/ # The .vscode folder contains launch configuration and tasks you configure in # VS Code which you may wish to be included in version control, so this line diff --git a/README.md b/README.md index 9d66a8b..6d70ba6 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,19 @@ void main(){ ``` 3. All done!. + + +### Loaders Specification + +#### HttpAssetLoader + +In order to use HttpAssetLoader you must provide a path to a folder (i.e. base path) where all your translations are placed like `https://example.com/translations` + +Your translations should be created as separate files with `.json` extension. Placing translations as individual files reduces the size of the file to load on application init. +Example: + +``` +translations/ +├── en-US.json +└── uk-UA.json +``` diff --git a/lib/src/http_asset_loader.dart b/lib/src/http_asset_loader.dart index 56a37f0..ecfe8c3 100644 --- a/lib/src/http_asset_loader.dart +++ b/lib/src/http_asset_loader.dart @@ -12,10 +12,10 @@ class HttpAssetLoader extends AssetLoader { Future> load(String path, Locale locale) async { log('easy localization loader: load http $path'); try { - var url = Uri.parse(path); + var url = Uri.parse('$path/${locale.toLanguageTag()}.json'); return http .get(url) - .then((response) => json.decode(response.body.toString())); + .then((response) => json.decode(utf8.decode(response.bodyBytes))); } catch (e) { //Catch network exceptions return {}; From e8f2ddc50b900de05f3ad44f16229d3f63a1ff41 Mon Sep 17 00:00:00 2001 From: Mutlu Simsek Date: Sun, 17 Dec 2023 12:17:18 +0300 Subject: [PATCH 13/16] extended delimiters (#57) * Update csv_asset_loader.dart with additional delimiters Update csv_asset_loader.dart with additional field delimiters, text delimiters, text end delimiters. * update to single quotes update to single quotes in lines 63 & 64 --- lib/src/csv_asset_loader.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/csv_asset_loader.dart b/lib/src/csv_asset_loader.dart index 612f012..e363570 100644 --- a/lib/src/csv_asset_loader.dart +++ b/lib/src/csv_asset_loader.dart @@ -59,8 +59,10 @@ class CSVParser { csvSettingsDetector: useAutodetect && fieldDelimiter == null && eol == null ? FirstOccurrenceSettingsDetector( + fieldDelimiters: [',', ';', '\t'], + textDelimiters: ['"', "'", '”'], + textEndDelimiters: ['"', "'", '”'], eols: ['\r\n', '\n'], - fieldDelimiters: [',', '\t'], ) : null, ); From 32bfdae9468431ae637e7ef09a7a75b4874a714b Mon Sep 17 00:00:00 2001 From: Benjamin Weber <89379862+bw-flagship@users.noreply.github.com> Date: Sun, 17 Dec 2023 10:33:56 +0100 Subject: [PATCH 14/16] increase version to 2.0.1 (#58) --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 778c07e..f4e9b0c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: Easy Localization Loader custom assets loaders for easy_localizatio homepage: https://github.com/aissat/easy_localization_loader issue_tracker: https://github.com/aissat/easy_localization_loader/issues -version: 2.0.0 +version: 2.0.1 environment: sdk: '>=2.12.0 <4.0.0' From eb9ab5f3e88785413300303611b9955af75fad0c Mon Sep 17 00:00:00 2001 From: BW Personal Date: Sun, 17 Dec 2023 10:35:53 +0100 Subject: [PATCH 15/16] Fill changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c12409e..67a9e97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.1 + +- Extend delimiters for csv loader + ## 2.0.0 - **BREAKING**: The local `AssetLoader` class deleted, now using the one from From 1f9f028204698bcad4e143af0c352a396ce64b38 Mon Sep 17 00:00:00 2001 From: nafiskabbo Date: Tue, 7 May 2024 18:27:52 +0600 Subject: [PATCH 16/16] 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(), {},