From cbec486ad17f12e6f7442922c61a88810feea09e Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Wed, 3 May 2023 18:00:24 -0400 Subject: [PATCH] Add language names and enable Spanish --- lib/main.dart | 25 +++++++++++++------------ lib/pages/settings.dart | 4 ++-- lib/providers/settings_provider.dart | 4 ++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1c7caa6..6fa333f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -27,15 +27,16 @@ const String currentReleaseTag = const int bgUpdateCheckAlarmId = 666; -const supportedLocales = [ - Locale('en'), - Locale('zh'), - Locale('it'), - Locale('ja'), - Locale('hu'), - Locale('de'), - Locale('fa'), - Locale('fr') +List> supportedLocales = const [ + MapEntry(Locale('en'), 'English'), + MapEntry(Locale('zh'), '汉语'), + MapEntry(Locale('it'), 'Italiano'), + MapEntry(Locale('ja'), '日本語'), + MapEntry(Locale('hu'), 'Magyar'), + MapEntry(Locale('de'), 'Deutsch'), + MapEntry(Locale('fa'), 'فارسی'), + MapEntry(Locale('fr'), 'Français'), + MapEntry(Locale('es'), 'Español'), ]; const fallbackLocale = Locale('en'); const localeDir = 'assets/translations'; @@ -52,7 +53,7 @@ Future loadTranslations() async { saveLocale: true, forceLocale: forceLocale != null ? Locale(forceLocale) : null, fallbackLocale: fallbackLocale, - supportedLocales: supportedLocales, + supportedLocales: supportedLocales.map((e) => e.key).toList(), assetLoader: const RootBundleAssetLoader(), useOnlyLangCode: true, useFallbackTranslations: true, @@ -171,7 +172,7 @@ void main() async { Provider(create: (context) => LogsProvider()) ], child: EasyLocalization( - supportedLocales: supportedLocales, + supportedLocales: supportedLocales.map((e) => e.key).toList(), path: localeDir, fallbackLocale: fallbackLocale, useOnlyLangCode: true, @@ -221,7 +222,7 @@ class _ObtainiumState extends State { ], onlyIfExists: false); } if (!supportedLocales - .map((e) => e.languageCode) + .map((e) => e.key.languageCode) .contains(context.locale.languageCode) || settingsProvider.forcedLocale == null && context.deviceLocale.languageCode != diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index a3808e8..988fe85 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -144,8 +144,8 @@ class _SettingsPageState extends State { child: Text(tr('followSystem')), ), ...supportedLocales.map((e) => DropdownMenuItem( - value: e.toLanguageTag(), - child: Text(e.toLanguageTag().toUpperCase()), + value: e.key.toLanguageTag(), + child: Text(e.value), )) ], onChanged: (value) { diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index 872a083..2f03dfb 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -216,7 +216,7 @@ class SettingsProvider with ChangeNotifier { String? get forcedLocale { var fl = prefs?.getString('forcedLocale'); return supportedLocales - .where((element) => element.toLanguageTag() == fl) + .where((element) => element.key.toLanguageTag() == fl) .isNotEmpty ? fl : null; @@ -226,7 +226,7 @@ class SettingsProvider with ChangeNotifier { if (fl == null) { prefs?.remove('forcedLocale'); } else if (supportedLocales - .where((element) => element.toLanguageTag() == fl) + .where((element) => element.key.toLanguageTag() == fl) .isNotEmpty) { prefs?.setString('forcedLocale', fl); }