Skip to content

Commit f432cbf

Browse files
le-vladFrankdroid7alexeyinkinbw-flagshipAbdulazizRasulbek
authored
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 <ibukunoladipo2015@gmail.com> Co-authored-by: Alexey Inkin <leha@inkin.ru> Co-authored-by: Benjamin Weber <89379862+bw-flagship@users.noreply.github.com> Co-authored-by: BW Personal <benjamin.weber@flagship-apps.de> Co-authored-by: Abdulaziz Rasulbek <nabiyevabdulaziz1@gmail.com>
1 parent 7c4abf7 commit f432cbf

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*.ipr
1515
*.iws
1616
.idea/
17+
.vscode/
1718

1819
# The .vscode folder contains launch configuration and tasks you configure in
1920
# VS Code which you may wish to be included in version control, so this line

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,19 @@ void main(){
5555
```
5656

5757
3. All done!.
58+
59+
60+
### Loaders Specification
61+
62+
#### HttpAssetLoader
63+
64+
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`
65+
66+
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.
67+
Example:
68+
69+
```
70+
translations/
71+
├── en-US.json
72+
└── uk-UA.json
73+
```

lib/src/http_asset_loader.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class HttpAssetLoader extends AssetLoader {
1212
Future<Map<String, dynamic>> load(String path, Locale locale) async {
1313
log('easy localization loader: load http $path');
1414
try {
15-
var url = Uri.parse(path);
15+
var url = Uri.parse('$path/${locale.toLanguageTag()}.json');
1616
return http
1717
.get(url)
18-
.then((response) => json.decode(response.body.toString()));
18+
.then((response) => json.decode(utf8.decode(response.bodyBytes)));
1919
} catch (e) {
2020
//Catch network exceptions
2121
return {};

0 commit comments

Comments
 (0)