Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add _supportedLocales in EasyLocalizationController; check the device… #672

Merged
merged 4 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/src/easy_localization_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class EasyLocalizationController extends ChangeNotifier {

late Locale _locale;
Locale? _fallbackLocale;
List<Locale>? _supportedLocales;

final Function(FlutterError e) onLoadError;
final AssetLoader assetLoader;
Expand All @@ -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) {
Expand Down Expand Up @@ -144,8 +146,9 @@ class EasyLocalizationController extends ChangeNotifier {
final result = <String, dynamic>{};
final loaderFutures = <Future<Map<String, dynamic>?>>[];

// 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<AssetLoader> loaders = [
assetLoader,
Expand Down Expand Up @@ -205,7 +208,8 @@ class EasyLocalizationController extends ChangeNotifier {
Future<void> resetLocale() async {
EasyLocalization.logger('Reset locale to platform locale $_deviceLocale');
bw-flagship marked this conversation as resolved.
Show resolved Hide resolved

await setLocale(_deviceLocale);
final locale = selectLocaleFrom(_supportedLocales!, deviceLocale, fallbackLocale: _fallbackLocale);
await setLocale(locale);
}
}

Expand Down
Loading