Fix: fallback to device locale on language only match

This commit is contained in:
Neeraj Gupta
2025-05-13 14:25:20 +05:30
parent b08d8de1c8
commit c0fd71a668
2 changed files with 18 additions and 4 deletions

View File

@@ -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');
}

View File

@@ -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(