Language fix for #185

This commit is contained in:
Imran Remtulla
2022-12-22 07:57:21 -05:00
parent 0da7a36f1a
commit 45a23e9025
2 changed files with 11 additions and 3 deletions

View File

@@ -43,12 +43,16 @@ final globalNavigatorKey = GlobalKey<NavigatorState>();
Future<void> loadTranslations() async { Future<void> loadTranslations() async {
// See easy_localization/issues/210 // See easy_localization/issues/210
await EasyLocalizationController.initEasyLocation(); await EasyLocalizationController.initEasyLocation();
var s = SettingsProvider();
await s.initializeSettings();
var forceLocale = s.forcedLocale;
final controller = EasyLocalizationController( final controller = EasyLocalizationController(
saveLocale: true, saveLocale: true,
forceLocale: forceLocale != null ? Locale(forceLocale) : null,
fallbackLocale: fallbackLocale, fallbackLocale: fallbackLocale,
supportedLocales: supportedLocales, supportedLocales: supportedLocales,
assetLoader: const RootBundleAssetLoader(), assetLoader: const RootBundleAssetLoader(),
useOnlyLangCode: false, useOnlyLangCode: true,
useFallbackTranslations: true, useFallbackTranslations: true,
path: localeDir, path: localeDir,
onLoadError: (FlutterError e) { onLoadError: (FlutterError e) {
@@ -160,6 +164,7 @@ void main() async {
supportedLocales: supportedLocales, supportedLocales: supportedLocales,
path: localeDir, path: localeDir,
fallbackLocale: fallbackLocale, fallbackLocale: fallbackLocale,
useOnlyLangCode: true,
child: const Obtainium()), child: const Obtainium()),
)); ));
} }

View File

@@ -145,8 +145,11 @@ class _SettingsPageState extends State<SettingsPage> {
], ],
onChanged: (value) { onChanged: (value) {
settingsProvider.forcedLocale = value; settingsProvider.forcedLocale = value;
context.setLocale(Locale(settingsProvider.forcedLocale ?? if (value != null) {
context.fallbackLocale!.languageCode)); context.setLocale(Locale(value));
} else {
context.resetLocale();
}
}); });
var intervalDropdown = DropdownButtonFormField( var intervalDropdown = DropdownButtonFormField(