exit early when finding system locale on web
This commit is contained in:
parent
1e1cac7c54
commit
d30e2fc99c
@ -4,23 +4,27 @@ import 'package:intl/intl_standalone.dart';
|
||||
import 'package:wonders/common_libs.dart';
|
||||
|
||||
class LocaleLogic {
|
||||
final Locale _defaultLocal = Locale('en');
|
||||
|
||||
AppLocalizations? _strings;
|
||||
AppLocalizations get strings => _strings!;
|
||||
|
||||
bool get isLoaded => _strings != null;
|
||||
|
||||
bool get isEnglish => strings.localeName == 'en';
|
||||
|
||||
Future<void> load() async {
|
||||
final localeCode = settingsLogic.currentLocale.value ?? await findSystemLocale();
|
||||
Locale locale = Locale(localeCode.split('_')[0]);
|
||||
Locale locale = _defaultLocal;
|
||||
if (kIsWeb) return; // exit early on web as [findSystemLocale] throws errors as of Dec, 2022
|
||||
if (kDebugMode) {
|
||||
// Uncomment for testing in chinese
|
||||
// locale = Locale('zh');
|
||||
// locale = Locale('zh'); // uncomment to test chinese
|
||||
}
|
||||
final localeCode = settingsLogic.currentLocale.value ?? await findSystemLocale();
|
||||
// Try and find a supported locale
|
||||
locale = Locale(localeCode.split('_')[0]);
|
||||
// Fall back to default
|
||||
if (AppLocalizations.supportedLocales.contains(locale) == false) {
|
||||
locale = Locale('en');
|
||||
locale = _defaultLocal;
|
||||
}
|
||||
|
||||
settingsLogic.currentLocale.value = locale.languageCode;
|
||||
_strings = await AppLocalizations.delegate.load(locale);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user