diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f4e7c1e..267f04ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ### [3.0.6] - add 'useFallbackTranslationsForEmptyResources' to be able to use fallback locales for empty resources. +- add _supportedLocales in EasyLocalizationController; log and check the deviceLocale when resetLocale; +- add scriptCode to desiredLocale if useOnlyLangCode is true. scriptCode is needed sometimes, for example zh-Hans, zh-Hant ### [3.0.5] diff --git a/lib/src/easy_localization_controller.dart b/lib/src/easy_localization_controller.dart index eda3cbe4..983fb265 100644 --- a/lib/src/easy_localization_controller.dart +++ b/lib/src/easy_localization_controller.dart @@ -12,6 +12,7 @@ class EasyLocalizationController extends ChangeNotifier { late Locale _locale; Locale? _fallbackLocale; + List? _supportedLocales; final Function(FlutterError e) onLoadError; final AssetLoader assetLoader; @@ -38,6 +39,7 @@ class EasyLocalizationController extends ChangeNotifier { Locale? forceLocale, // used for testing }) { _fallbackLocale = fallbackLocale; + _supportedLocales = supportedLocales; if (forceLocale != null) { _locale = forceLocale; } else if (_savedLocale == null && startLocale != null) { @@ -144,8 +146,9 @@ class EasyLocalizationController extends ChangeNotifier { final result = {}; final loaderFutures = ?>>[]; + // need scriptCode, it might be better to use ignoreCountryCode as the variable name of useOnlyLangCode final Locale desiredLocale = - useOnlyLangCode ? Locale(locale.languageCode) : locale; + useOnlyLangCode ? Locale.fromSubtags(languageCode: locale.languageCode, scriptCode: locale.scriptCode) : locale; List loaders = [ assetLoader, @@ -203,9 +206,10 @@ class EasyLocalizationController extends ChangeNotifier { Locale get deviceLocale => _deviceLocale; Future resetLocale() async { - EasyLocalization.logger('Reset locale to platform locale $_deviceLocale'); + final locale = selectLocaleFrom(_supportedLocales!, deviceLocale, fallbackLocale: _fallbackLocale); - await setLocale(_deviceLocale); + EasyLocalization.logger('Reset locale to $locale while the platform locale is $_deviceLocale and the fallback locale is $_fallbackLocale'); + await setLocale(locale); } }