From f3ff671f12356b15a38a4cad8dfc5cbb330c7a73 Mon Sep 17 00:00:00 2001 From: Fikret Onur Esen Date: Wed, 4 Dec 2024 14:17:52 +0300 Subject: [PATCH 1/3] Enhance FileAssetLoader to support locale-specific paths and add FileSingleAssetLoader --- lib/src/file_asset_loader.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/src/file_asset_loader.dart b/lib/src/file_asset_loader.dart index 8346843..e8dec42 100644 --- a/lib/src/file_asset_loader.dart +++ b/lib/src/file_asset_loader.dart @@ -8,6 +8,23 @@ import 'package:easy_localization/easy_localization.dart'; class FileAssetLoader extends AssetLoader { const FileAssetLoader(); + String getLocalePath(String basePath, Locale locale) { + return '$basePath/${locale.toStringWithSeparator(separator: "-")}.json'; + } + + @override + Future> load(String path, Locale locale) async { + var localePath = getLocalePath(path, locale); + final file = File(localePath); + log('easy localization loader: load file $localePath'); + + return json.decode(await file.readAsString()); + } +} + +class FileSingleAssetLoader extends AssetLoader { + const FileSingleAssetLoader(); + @override Future> load(String path, Locale locale) async { final file = File(path); From a7d58057efdd052a236a491f1e20ba7b318a72b3 Mon Sep 17 00:00:00 2001 From: Fikret Onur Esen Date: Wed, 4 Dec 2024 14:38:28 +0300 Subject: [PATCH 2/3] Update version and changelog for FileAssetLoader enhancements --- CHANGELOG.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eec925..6093877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ +## 3.0.0 + +- **BREAKING**: Updated `FileAssetLoader` to use `getLocalePath`, which dynamically constructs locale-specific file paths. Previous usage requiring direct file paths must adapt to the new format. +- Added `FileSingleAssetLoader` class for handling single translation files. +- Improved logging for better debugging. + ## 2.0.2 + - Update connectivity_plus package to ^6.0.3 - Update easy_localization package to ^3.0.7 @@ -13,12 +20,12 @@ - **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` + - `FileAssetLoader` + - `HttpAssetLoader` + - `JsonAssetLoader` + - `TestsAssetLoader` + - `XmlAssetLoader` + - `YamlAssetLoader` - Fixed deprecations ## 0.0.1 From 6a35fbe9b5484d9e4227965db0f50dcf6db17130 Mon Sep 17 00:00:00 2001 From: Fikret Onur Esen Date: Wed, 4 Dec 2024 14:45:53 +0300 Subject: [PATCH 3/3] Update version in pubspec --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5aa1389..bea8ce3 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.2 +version: 3.0.0 environment: sdk: '>=2.12.0 <4.0.0'