Skip to content

Commit

Permalink
Fix for ilteoood#184
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Jan 15, 2022
1 parent 6bddf40 commit fd6df23
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 68 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions example/lib/network_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class CustomNetworkFileTranslationLoader extends NetworkFileTranslationLoader {
CustomNetworkFileTranslationLoader({required baseUri})
: super(baseUri: baseUri, decodeStrategies: [JsonDecodeStrategy()]);

Future<String> loadString(final String fileName, final String extension) {
return networkAssetBundle.loadString("");
Uri resolveUri(final String fileName, final String extension) {
return baseUri;
}
}

Expand Down
82 changes: 48 additions & 34 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "30.0.0"
version: "31.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "2.7.0"
version: "2.8.0"
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.2"
version: "3.1.6"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.3.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -49,7 +49,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
Expand All @@ -63,7 +63,7 @@ packages:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3"
version: "0.3.5"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -105,7 +105,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "1.0.4"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -177,14 +177,14 @@ packages:
name: glob
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.2"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.3"
version: "0.13.4"
http_multi_server:
dependency: transitive
description:
Expand Down Expand Up @@ -238,7 +238,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
Expand All @@ -252,7 +252,7 @@ packages:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.1"
node_preamble:
dependency: transitive
description:
Expand All @@ -266,7 +266,7 @@ packages:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.2"
path:
dependency: transitive
description:
Expand All @@ -280,35 +280,49 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.8"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
path_provider_ios:
dependency: transitive
description:
name: path_provider_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.7"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.1.5"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.5"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.3"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.5"
pedantic:
dependency: transitive
description:
Expand All @@ -322,21 +336,21 @@ packages:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
version: "4.4.0"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
version: "3.0.2"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.1.2"
pool:
dependency: transitive
description:
Expand All @@ -350,21 +364,21 @@ packages:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.3"
version: "4.2.4"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
version: "3.0.1+1"
shelf:
dependency: transitive
description:
Expand Down Expand Up @@ -460,21 +474,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.17.10"
version: "1.17.12"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.3"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
version: "0.4.2"
toml:
dependency: transitive
description:
Expand All @@ -495,21 +509,21 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "7.1.1"
version: "7.3.0"
watcher:
dependency: transitive
description:
name: watcher
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.1"
web_socket_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -537,7 +551,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.9"
version: "2.3.3"
xdg_directories:
dependency: transitive
description:
Expand All @@ -551,14 +565,14 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.2"
version: "5.3.1"
xml2json:
dependency: transitive
description:
name: xml2json
url: "https://pub.dartlang.org"
source: hosted
version: "5.3.1"
version: "5.3.2"
yaml:
dependency: transitive
description:
Expand All @@ -568,4 +582,4 @@ packages:
version: "3.1.0"
sdks:
dart: ">=2.14.0 <3.0.0"
flutter: ">=2.0.0"
flutter: ">=2.5.0"
35 changes: 19 additions & 16 deletions lib/loaders/network_file_translation_loader.dart
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');
}
}
Loading

0 comments on commit fd6df23

Please sign in to comment.