π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Fix autoLanguage detection
Neeraj Guptae4647c07d50a
diff --git a/mobile/lib/app.dart b/mobile/lib/app.dartindex 1540a0d270..4f590e4399 100644--- a/mobile/lib/app.dart+++ b/mobile/lib/app.dart@@ -25,7 +25,7 @@ class EnteApp extends StatefulWidget {final Future<void> Function(String) runBackgroundTask;final Future<void> Function(String) killBackgroundTask;final AdaptiveThemeMode? savedThemeMode;- final Locale locale;+ final Locale? locale;const EnteApp(this.runBackgroundTask,@@ -46,7 +46,7 @@ class EnteApp extends StatefulWidget {class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {final _logger = Logger("EnteAppState");- late Locale locale;+ late Locale? locale;@overridevoid initState() {diff --git a/mobile/lib/l10n/l10n.dart b/mobile/lib/l10n/l10n.dartindex 0a74a7f1da..f45e26995c 100644--- a/mobile/lib/l10n/l10n.dart+++ b/mobile/lib/l10n/l10n.dart@@ -24,17 +24,26 @@ const List<Locale> appSupportedLocales = <Locale>[Locale("zh", "CN"),];+Locale? autoDetectedLocale;+Locale localResolutionCallBack(locales, supportedLocales) {for (Locale locale in locales) {- if (appSupportedLocales.contains(locale)) {- return locale;+ for (Locale supportedLocale in appSupportedLocales) {+ if (supportedLocale == locale) {+ autoDetectedLocale = supportedLocale;+ return supportedLocale;+ } else if (supportedLocale.languageCode == locale.languageCode) {+ autoDetectedLocale = supportedLocale;+ return supportedLocale;+ }}}- // if device language is not supported by the app, use en as defaultreturn const Locale('en');}-Future<Locale> getLocale() async {+Future<Locale?> getLocale({+ bool noFallback = false,+}) async {final String? savedValue =(await SharedPreferences.getInstance()).getString('locale');// if savedLocale is not null and is supported by the app, return it@@ -50,6 +59,12 @@ Future<Locale> getLocale() async {return savedLocale;}}+ if (autoDetectedLocale != null) {+ return autoDetectedLocale!;+ }+ if (noFallback) {+ return null;+ }return const Locale('en');}diff --git a/mobile/lib/main.dart b/mobile/lib/main.dartindex 9c9d42c6d8..5094502217 100644--- a/mobile/lib/main.dart+++ b/mobile/lib/main.dart@@ -95,7 +95,7 @@ Future<void> _runInForeground(AdaptiveThemeMode? savedThemeMode) async {return await _runWithLogs(() async {_logger.info("Starting app in foreground");await _init(false, via: 'mainMethod');- final Locale locale = await getLocale();+ Locale? locale = await getLocale(noFallback: true);runApp(AppLock(builder: (args) =>diff --git a/mobile/lib/ui/home/landing_page_widget.dart b/mobile/lib/ui/home/landing_page_widget.dartindex e341746ac6..cc19854ed6 100644--- a/mobile/lib/ui/home/landing_page_widget.dart+++ b/mobile/lib/ui/home/landing_page_widget.dart@@ -89,7 +89,7 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {child: Text("Lang"),),onTap: () async {- final locale = await getLocale();+ final locale = (await getLocale())!;// ignore: unawaited_futuresrouteToPage(context,diff --git a/mobile/lib/ui/settings/general_section_widget.dart b/mobile/lib/ui/settings/general_section_widget.dartindex ccc941b4ee..3532292551 100644--- a/mobile/lib/ui/settings/general_section_widget.dart+++ b/mobile/lib/ui/settings/general_section_widget.dart@@ -70,7 +70,7 @@ class GeneralSectionWidget extends StatelessWidget {trailingIcon: Icons.chevron_right_outlined,trailingIconIsMuted: true,onTap: () async {- final locale = await getLocale();+ final locale = (await getLocale())!;await routeToPage(context,LanguageSelectorPage(diff --git a/mobile/lib/ui/tools/app_lock.dart b/mobile/lib/ui/tools/app_lock.dartindex cbc716d7f8..19a718b7a0 100644--- a/mobile/lib/ui/tools/app_lock.dart+++ b/mobile/lib/ui/tools/app_lock.dart@@ -35,7 +35,7 @@ class AppLock extends StatefulWidget {final ThemeData? darkTheme;final ThemeData? lightTheme;final ThemeMode savedThemeMode;- final Locale locale;+ final Locale? locale;const AppLock({Key? key,@@ -43,7 +43,7 @@ class AppLock extends StatefulWidget {required this.lockScreen,required this.savedThemeMode,this.enabled = true,- this.locale = const Locale("en", "US"),+ this.locale,this.darkTheme,this.lightTheme,}) : super(key: key);diff --git a/mobile/lib/ui/viewer/file_details/creation_time_item_widget.dart b/mobile/lib/ui/viewer/file_details/creation_time_item_widget.dartindex d4f08a66f9..90b6ab9d58 100644--- a/mobile/lib/ui/viewer/file_details/creation_time_item_widget.dart+++ b/mobile/lib/ui/viewer/file_details/creation_time_item_widget.dart@@ -47,7 +47,7 @@ class _CreationTimeItemState extends State<CreationTimeItem> {}void _showDateTimePicker(EnteFile file) async {- final Locale locale = await getLocale();+ final Locale locale = (await getLocale())!;final localeType = getFromLocalString(locale);final dateResult = await DatePickerBdaya.showDatePicker(context,diff --git a/mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart b/mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dartindex 571b84424e..1dd6c5c8ab 100644--- a/mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart+++ b/mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart@@ -218,7 +218,7 @@ class AddPhotosPhotoWidget extends StatelessWidget {// This custom method is required to enforce English as the default fallback// instead of Chinese.Future<AssetPickerTextDelegate> _getAssetPickerTextDelegate() async {- final Locale locale = await getLocale();+ final Locale locale = (await getLocale())!;switch (locale.languageCode.toLowerCase()) {case "en":return const EnglishAssetPickerTextDelegate();