Browse Source

neon: fix unsupported locale

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/286/head
Nikolas Rimikis 2 years ago
parent
commit
9ff5e56e1f
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 15
      packages/neon/neon/lib/src/utils/localizations.dart

15
packages/neon/neon/lib/src/utils/localizations.dart

@ -1,7 +1,14 @@
part of '../../neon.dart';
Future<AppLocalizations> appLocalizationsFromSystem() async {
final parts =
(await findSystemLocale()).split('_').map((final a) => a.split('.')).reduce((final a, final b) => [...a, ...b]);
return AppLocalizations.delegate.load(Locale(parts[0], parts.length > 1 ? parts[1] : null));
/// Loads the [AppLocalizations] for the system [Locale].
///
/// When the system locale is not supported [fallbackLocale] will be used.
Future<AppLocalizations> appLocalizationsFromSystem([final Locale fallbackLocale = const Locale('en', 'US')]) async {
final systemLocale = await findSystemLocale();
final parts = systemLocale.split('_').map((final a) => a.split('.')).reduce((final a, final b) => [...a, ...b]);
final locale = Locale(parts[0], parts.length > 1 ? parts[1] : null);
final isSupported = AppLocalizations.delegate.isSupported(locale);
return AppLocalizations.delegate.load(isSupported ? locale : fallbackLocale);
}

Loading…
Cancel
Save