diff --git a/.gitignore b/.gitignore index 5b89f90..e37c091 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index 9d66a8b..6d70ba6 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/lib/src/http_asset_loader.dart b/lib/src/http_asset_loader.dart index 56a37f0..ecfe8c3 100644 --- a/lib/src/http_asset_loader.dart +++ b/lib/src/http_asset_loader.dart @@ -12,10 +12,10 @@ class HttpAssetLoader extends AssetLoader { Future> 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 {};