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

Enhance FileAssetLoader and add FileSingleAssetLoader #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions lib/src/file_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, dynamic>> 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<Map<String, dynamic>> load(String path, Locale locale) async {
final file = File(path);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down