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

Improving on HttpAssetLoader #49

Merged
merged 26 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8a9837b
Update README.md
Frankdroid7 Apr 19, 2023
faf8b48
chore(): upgraded deps
le-vlad May 19, 2023
20b917d
chore(): load concrete location
le-vlad May 19, 2023
b1fe112
fix(): correct decoding of cyrillic chars
le-vlad May 19, 2023
2b6c0be
chore(): updated readme. added HttpAssetLoader doc
le-vlad May 19, 2023
3d9edbd
fix(doc): update dir structure
le-vlad May 19, 2023
b24e85c
Delete local AssetLoader class, update dependencies (#46)
alexeyinkin Jun 26, 2023
93f83d9
Undo the breaking change of file names (#46)
alexeyinkin Jun 27, 2023
efca208
Merge pull request #50 from alexeyinkin/issue46_update-dependencies
bw-flagship Jul 4, 2023
8fea719
contributing.md
bw-flagship Sep 29, 2023
c484454
added pipelines
bw-flagship Sep 29, 2023
897ed8d
fix linting problems
bw-flagship Sep 29, 2023
3407c17
changelog
bw-flagship Sep 29, 2023
3bf6e59
devversion
bw-flagship Sep 29, 2023
8e60e2e
execute now
bw-flagship Sep 29, 2023
eaa2da1
revert temp changes
bw-flagship Sep 29, 2023
edb9c5c
Add Release pipeline
bw-flagship Sep 29, 2023
6cfc31a
Fix Typos
bw-flagship Sep 29, 2023
5f5139f
update connectivity_plus, easy_localization, http and path_provider p…
AbdulazizRasulbek Oct 26, 2023
7c4abf7
Merge pull request #56 from AbdulazizRasulbek/master
bw-flagship Oct 26, 2023
f0be467
chore(): upgraded deps
le-vlad May 19, 2023
8be6742
chore(): load concrete location
le-vlad May 19, 2023
08fdb68
fix(): correct decoding of cyrillic chars
le-vlad May 19, 2023
79a8969
chore(): updated readme. added HttpAssetLoader doc
le-vlad May 19, 2023
65d79ba
fix(doc): update dir structure
le-vlad May 19, 2023
dde7542
Merge branch 'master' of github.com:wewego-co/easy_localization_loader
le-vlad Oct 26, 2023
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
11 changes: 11 additions & 0 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: PR Check

on:
workflow_dispatch:
pull_request:

jobs:
test:
name: Test
uses: ./.github/workflows/test.yml
secrets: inherit
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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**: 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`
- Fixed deprecations

## 0.0.1

- Initial release.
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies:

```

2. Change assetLoader and patch
2. Change assetLoader and path

```dart
...
Expand All @@ -54,4 +54,20 @@ void main(){
...
```

3. All done!.
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
```
12 changes: 5 additions & 7 deletions lib/easy_localization_loader.dart
Original file line number Diff line number Diff line change
@@ -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';
27 changes: 0 additions & 27 deletions lib/src/asset_loader.dart

This file was deleted.

3 changes: 1 addition & 2 deletions lib/src/csv_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
8 changes: 3 additions & 5 deletions lib/src/file_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, dynamic>> load(String path, Locale locale) async {
final file = File(path);
Expand Down
15 changes: 6 additions & 9 deletions lib/src/http_asset_loader.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
//
//
//
//
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<Map<String, dynamic>> 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 Future.value();
return {};
}
}
}
7 changes: 4 additions & 3 deletions lib/src/json_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.toStringWithSeparator(separator: "-")}.json';
}

@override
Expand Down
3 changes: 1 addition & 2 deletions lib/src/smart_network_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions lib/src/tests_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, dynamic>> load(String path, Locale locale) async {
final byteData = await rootBundle.load(path);
Expand Down
9 changes: 5 additions & 4 deletions lib/src/xml_asset_loader.dart
Original file line number Diff line number Diff line change
@@ -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.toStringWithSeparator(separator: "-")}.xml';
}

@override
Expand Down Expand Up @@ -50,7 +51,7 @@ Map<String, dynamic> 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());
Expand Down
7 changes: 4 additions & 3 deletions lib/src/yaml_asset_loader.dart
Original file line number Diff line number Diff line change
@@ -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.toStringWithSeparator(separator: "-")}.yaml';
}

@override
Expand Down
17 changes: 8 additions & 9 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ^5.0.1
csv: ^5.0.1
yaml: ^3.1.1
easy_localization: ^3.0.3
flutter: { sdk: flutter }
http: ^1.1.0
path_provider: ^2.1.1
xml: ^6.1.0
flutter:
sdk: flutter
connectivity_plus: ^2.3.7
path_provider: ^2.0.11
yaml: ^3.1.1

dev_dependencies:
pedantic: ^1.11.1
test: ^1.21.6

Loading