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

resetLocal crashes if deviceLocale not in supportedLocales #670

Closed
bbsmartc opened this issue May 1, 2024 · 2 comments
Closed

resetLocal crashes if deviceLocale not in supportedLocales #670

bbsmartc opened this issue May 1, 2024 · 2 comments

Comments

@bbsmartc
Copy link
Contributor

bbsmartc commented May 1, 2024

resetLocale() crashes if deviceLocale not in supportedLocales, the deviceLocal is not checked before setLocale. currently, i use the following code out of the library

                if (context.supportedLocales.contains(context.deviceLocale)) {
                  context.resetLocale();
                } else {
                  context.setLocale(context.fallbackLocale!);
                }

it might be better to check that in the function resetLocale()

@bbsmartc
Copy link
Contributor Author

bbsmartc commented May 1, 2024

locale.supports() is defined in LocaleExtension on Locale in EasyLocalizationController, it's better to use supportedLocales.any((locale) =>locale.supports(deviceLocale)) instead of supportedLocales.contains(deviceLocale).
Because supportedLocales is not saved to local variable in EasyLocalizationController, i did not make a pull request to avoid disrupting the code. it's better to always use selectLocaleFrom(supportedLocale, inputLocale, fallbackLocale) to ensure a fallback, in resetLocale() in EasyLocalizationController, instead of directly assigning the deviceLocale to _local

@bbsmartc
Copy link
Contributor Author

bbsmartc commented May 1, 2024

i will make a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant