mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
fix: Locale selection issue with country-specific locales (#383)
This commit is contained in:
parent
3d7a654096
commit
f3e920ac79
3 changed files with 19 additions and 9 deletions
|
|
@ -288,13 +288,15 @@ class _MainState extends ConsumerState<Main> with WindowListener, WidgetsBinding
|
||||||
),
|
),
|
||||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||||
supportedLocales: AppLocalizations.supportedLocales,
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
builder: (context, child) => Localizations.override(
|
locale: language,
|
||||||
context: context,
|
localeResolutionCallback: (locale, supportedLocales) {
|
||||||
locale: AppLocalizations.supportedLocales.firstWhere(
|
if (locale == null || !supportedLocales.contains(locale)) {
|
||||||
(element) => element.languageCode == language.languageCode,
|
return const Locale('en');
|
||||||
orElse: () => const Locale('en', "GB"),
|
}
|
||||||
),
|
return locale;
|
||||||
child: LocalizationContextWrapper(child: ScaffoldMessenger(child: child ?? Container())),
|
},
|
||||||
|
builder: (context, child) => LocalizationContextWrapper(
|
||||||
|
child: ScaffoldMessenger(child: child ?? Container()),
|
||||||
),
|
),
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
darkTheme: darkTheme.copyWith(
|
darkTheme: darkTheme.copyWith(
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ List<Widget> buildClientSettingsVisual(
|
||||||
context: context,
|
context: context,
|
||||||
locale: ref.watch(clientSettingsProvider.select((value) => (value.selectedLocale ?? currentLocale))),
|
locale: ref.watch(clientSettingsProvider.select((value) => (value.selectedLocale ?? currentLocale))),
|
||||||
child: Builder(builder: (context) {
|
child: Builder(builder: (context) {
|
||||||
String language = "Unknown";
|
String language = "English";
|
||||||
try {
|
try {
|
||||||
language = context.localized.nativeName;
|
language = context.localized.nativeName;
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|
@ -46,7 +46,7 @@ List<Widget> buildClientSettingsVisual(
|
||||||
context: context,
|
context: context,
|
||||||
locale: entry,
|
locale: entry,
|
||||||
child: Builder(builder: (context) {
|
child: Builder(builder: (context) {
|
||||||
return Text("${context.localized.nativeName} (${entry.languageCode.toUpperCase()})");
|
return Text("${context.localized.nativeName} (${entry.toDisplayCode()})");
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
onTap: () => ref
|
onTap: () => ref
|
||||||
|
|
|
||||||
|
|
@ -31,3 +31,11 @@ class _LocalizationContextWrapperState extends ConsumerState<LocalizationContext
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => widget.child;
|
Widget build(BuildContext context) => widget.child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension LocaleDisplayCodeExtension on Locale {
|
||||||
|
String toDisplayCode() {
|
||||||
|
return countryCode != null && countryCode!.isNotEmpty
|
||||||
|
? "${languageCode.toUpperCase()}-${countryCode!.toUpperCase()}"
|
||||||
|
: languageCode.toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue