forked from ilteoood/flutter_i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,4 +251,7 @@ Support for toml format | |
Fix for #173 | ||
|
||
## [0.31.0] | ||
Fix for #179 | ||
Fix for #179 | ||
|
||
## [0.31.1] | ||
Fix for #184 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
import 'file_translation_loader.dart'; | ||
|
||
/// Loads translations from the remote resource | ||
class NetworkFileTranslationLoader extends FileTranslationLoader { | ||
late AssetBundle networkAssetBundle; | ||
final Uri baseUri; | ||
|
||
NetworkFileTranslationLoader( | ||
{required this.baseUri, | ||
forcedLocale, | ||
fallbackFile = "en", | ||
useCountryCode = false, | ||
useScriptCode = false, | ||
decodeStrategies}) | ||
forcedLocale, | ||
fallbackFile = "en", | ||
useCountryCode = false, | ||
useScriptCode = false, | ||
decodeStrategies}) | ||
: super( | ||
fallbackFile: fallbackFile, | ||
useCountryCode: useCountryCode, | ||
forcedLocale: forcedLocale, | ||
decodeStrategies: decodeStrategies) { | ||
networkAssetBundle = NetworkAssetBundle(baseUri); | ||
} | ||
fallbackFile: fallbackFile, | ||
useCountryCode: useCountryCode, | ||
forcedLocale: forcedLocale, | ||
decodeStrategies: decodeStrategies); | ||
|
||
/// Load the file using the AssetBundle networkAssetBundle | ||
/// Load the file using an http client | ||
@override | ||
Future<String> loadString(final String fileName, final String extension) { | ||
return networkAssetBundle.loadString('$fileName.$extension'); | ||
Future<String> loadString(final String fileName, final String extension) async { | ||
final resolvedUri = resolveUri(fileName, extension); | ||
final result = await http.get(resolvedUri); | ||
return result.body; | ||
} | ||
|
||
Uri resolveUri(final String fileName, final String extension) { | ||
return baseUri.resolve('$fileName.$extension'); | ||
} | ||
} |
Oops, something went wrong.