From 45a23e9025a22dfa631515ef830e61e62ce88031 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Thu, 22 Dec 2022 07:57:21 -0500 Subject: [PATCH] Language fix for #185 --- lib/main.dart | 7 ++++++- lib/pages/settings.dart | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 8c4cd51..c66a53b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -43,12 +43,16 @@ final globalNavigatorKey = GlobalKey(); Future loadTranslations() async { // See easy_localization/issues/210 await EasyLocalizationController.initEasyLocation(); + var s = SettingsProvider(); + await s.initializeSettings(); + var forceLocale = s.forcedLocale; final controller = EasyLocalizationController( saveLocale: true, + forceLocale: forceLocale != null ? Locale(forceLocale) : null, fallbackLocale: fallbackLocale, supportedLocales: supportedLocales, assetLoader: const RootBundleAssetLoader(), - useOnlyLangCode: false, + useOnlyLangCode: true, useFallbackTranslations: true, path: localeDir, onLoadError: (FlutterError e) { @@ -160,6 +164,7 @@ void main() async { supportedLocales: supportedLocales, path: localeDir, fallbackLocale: fallbackLocale, + useOnlyLangCode: true, child: const Obtainium()), )); } diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index 2e107ba..ecf1d5b 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -145,8 +145,11 @@ class _SettingsPageState extends State { ], onChanged: (value) { settingsProvider.forcedLocale = value; - context.setLocale(Locale(settingsProvider.forcedLocale ?? - context.fallbackLocale!.languageCode)); + if (value != null) { + context.setLocale(Locale(value)); + } else { + context.resetLocale(); + } }); var intervalDropdown = DropdownButtonFormField(