Skip to content

Commit

Permalink
Improving on HttpAssetLoader (#49)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Alexey Inkin <[email protected]>
Co-authored-by: Benjamin Weber <[email protected]>
Co-authored-by: BW Personal <[email protected]>
Co-authored-by: Abdulaziz Rasulbek <[email protected]>
  • Loading branch information
6 people authored Oct 30, 2023
1 parent 7c4abf7 commit f432cbf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 2 additions & 2 deletions lib/src/http_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class HttpAssetLoader extends AssetLoader {
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 {};
Expand Down

0 comments on commit f432cbf

Please sign in to comment.