Fix: fallback to device locale on language only match
This commit is contained in:
@@ -34,18 +34,22 @@ Locale? autoDetectedLocale;
|
||||
|
||||
Locale localResolutionCallBack(deviceLocales, supportedLocales) {
|
||||
_onDeviceLocales = deviceLocales;
|
||||
debugPrint("onDeviceLocales: ${_onDeviceLocales.toString()}");
|
||||
Locale? firstLangeuageMatch;
|
||||
for (Locale deviceLocale in deviceLocales) {
|
||||
for (Locale supportedLocale in appSupportedLocales) {
|
||||
if (supportedLocale == deviceLocale) {
|
||||
autoDetectedLocale = supportedLocale;
|
||||
return supportedLocale;
|
||||
} else if (supportedLocale.languageCode == deviceLocale.languageCode) {
|
||||
autoDetectedLocale = supportedLocale;
|
||||
return supportedLocale;
|
||||
}
|
||||
if (firstLangeuageMatch == null &&
|
||||
supportedLocale.languageCode == deviceLocale.languageCode) {
|
||||
firstLangeuageMatch = deviceLocale;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (firstLangeuageMatch != null) {
|
||||
autoDetectedLocale = firstLangeuageMatch;
|
||||
}
|
||||
return autoDetectedLocale ?? const Locale('en');
|
||||
}
|
||||
|
||||
|
||||
@@ -98,11 +98,21 @@ class _ItemsWidgetState extends State<ItemsWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
items.clear();
|
||||
bool foundMatch = false;
|
||||
for (Locale locale in widget.supportedLocales) {
|
||||
if (currentLocale == locale) {
|
||||
foundMatch = true;
|
||||
}
|
||||
items.add(
|
||||
_menuItemForPicker(locale),
|
||||
);
|
||||
}
|
||||
if (!foundMatch && kDebugMode) {
|
||||
items.insert(
|
||||
0,
|
||||
Text("(i) Locale : ${currentLocale.toString()}"),
|
||||
);
|
||||
}
|
||||
items = addSeparators(
|
||||
items,
|
||||
DividerWidget(
|
||||
|
||||
Reference in New Issue
Block a user