diff --git a/lib/main.dart b/lib/main.dart index da13c5a..72b1129 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,17 +16,49 @@ import 'package:dynamic_color/dynamic_color.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart'; import 'package:easy_localization/easy_localization.dart'; +// ignore: implementation_imports +import 'package:easy_localization/src/easy_localization_controller.dart'; +// ignore: implementation_imports +import 'package:easy_localization/src/localization.dart'; -const String currentVersion = '0.8.4'; +const String currentVersion = '0.8.5'; const String currentReleaseTag = 'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES const int bgUpdateCheckAlarmId = 666; +const supportedLocales = [Locale('en')]; +const fallbackLocale = Locale('en'); +const localeDir = 'assets/translations'; + +Future loadTranslations() async { + // See easy_localization/issues/210 + await EasyLocalizationController.initEasyLocation(); + final controller = EasyLocalizationController( + saveLocale: true, + fallbackLocale: fallbackLocale, + supportedLocales: supportedLocales, + assetLoader: const RootBundleAssetLoader(), + useOnlyLangCode: false, + useFallbackTranslations: true, + path: localeDir, + onLoadError: (FlutterError e) { + throw e; + }, + ); + await controller.loadTranslations(); + Localization.load(controller.locale, + translations: controller.translations, + fallbackTranslations: controller.fallbackTranslations); +} + @pragma('vm:entry-point') Future bgUpdateCheck(int taskId, Map? params) async { WidgetsFlutterBinding.ensureInitialized(); await EasyLocalization.ensureInitialized(); + + await loadTranslations(); + LogsProvider logs = LogsProvider(); logs.add(tr('startedBgUpdateTask')); int? ignoreAfterMicroseconds = params?['ignoreAfterMicroseconds']; @@ -116,9 +148,9 @@ void main() async { Provider(create: (context) => LogsProvider()) ], child: EasyLocalization( - supportedLocales: const [Locale('en')], - path: 'assets/translations', - fallbackLocale: const Locale('en'), + supportedLocales: supportedLocales, + path: localeDir, + fallbackLocale: fallbackLocale, child: const Obtainium()), )); } diff --git a/pubspec.yaml b/pubspec.yaml index 2db2896..4f5b03c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 0.8.4+67 # When changing this, update the tag in main() accordingly +version: 0.8.5+68 # When changing this, update the tag in main() accordingly environment: sdk: '>=2.18.2 <3.0.0'