diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 3cdbf996d..6372f1850 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -62,5 +62,7 @@ Please allow auth to lock itself with FaceID or TouchID NSPhotoLibraryUsageDescription Please allow auth to pick a file to import data from - + UIApplicationSupportsIndirectInputEvents + + diff --git a/lib/app/view/app.dart b/lib/app/view/app.dart index 069ce5fb1..f4a0a6c5e 100644 --- a/lib/app/view/app.dart +++ b/lib/app/view/app.dart @@ -19,7 +19,8 @@ import "package:flutter/material.dart"; import 'package:flutter_localizations/flutter_localizations.dart'; class App extends StatefulWidget { - const App({Key key}); + final Locale locale; + const App({Key key, this.locale = const Locale("en")}) : super(key: key); @override State createState() => _AppState(); @@ -79,6 +80,7 @@ class _AppState extends State { theme: lightTheme, darkTheme: dartTheme, debugShowCheckedModeBanner: false, + locale: widget.locale, supportedLocales: appSupportedLocales, localeListResolutionCallback: localResolutionCallBack, localizationsDelegates: const [ @@ -97,6 +99,7 @@ class _AppState extends State { theme: lightThemeData, darkTheme: darkThemeData, debugShowCheckedModeBanner: false, + locale: widget.locale, supportedLocales: appSupportedLocales, localeListResolutionCallback: localResolutionCallBack, localizationsDelegates: const [ diff --git a/lib/locale.dart b/lib/locale.dart index f80090cfc..215631e65 100644 --- a/lib/locale.dart +++ b/lib/locale.dart @@ -1,13 +1,18 @@ -import 'dart:ui'; +import 'package:flutter/cupertino.dart'; +import 'package:shared_preferences/shared_preferences.dart'; // list of locales which are enabled for auth app. // Add more language to the list only when at least 90% of the strings are // translated in the corresponding language. const List appSupportedLocales = [ Locale('en'), + Locale('de'), + Locale('fr'), + Locale('fi'), ]; Locale localResolutionCallBack(locales, supportedLocales) { + // print call stacktrace to identify caller for (Locale locale in locales) { if (appSupportedLocales.contains(locale)) { return locale; @@ -16,3 +21,17 @@ Locale localResolutionCallBack(locales, supportedLocales) { // if device language is not supported by the app, use en as default return const Locale('en'); } + +Future getLocale() async { + final String? savedLocale = + (await SharedPreferences.getInstance()).getString('locale'); + if (savedLocale != null) { + return Locale(savedLocale); + } + return const Locale('en'); +} + +Future setLocale(Locale locale) async { + await (await SharedPreferences.getInstance()) + .setString('locale', locale.languageCode); +} diff --git a/lib/main.dart b/lib/main.dart index de3ce5472..f1a8c382a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:ente_auth/core/constants.dart'; import 'package:ente_auth/core/logging/super_logging.dart'; import 'package:ente_auth/core/network.dart'; import 'package:ente_auth/ente_theme_data.dart'; +import 'package:ente_auth/locale.dart'; import 'package:ente_auth/services/authenticator_service.dart'; import 'package:ente_auth/services/billing_service.dart'; import 'package:ente_auth/services/notification_service.dart'; @@ -31,12 +32,14 @@ Future _runInForeground() async { return await _runWithLogs(() async { _logger.info("Starting app in foreground"); await _init(false, via: 'mainMethod'); + final Locale locale = await getLocale(); UpdateService.instance.showUpdateNotification(); runApp( AppLock( - builder: (args) => const App(), + builder: (args) => App(locale: locale), lockScreen: const LockScreen(), enabled: Configuration.instance.shouldShowLockScreen(), + locale: locale, lightTheme: lightThemeData, darkTheme: darkThemeData, ), diff --git a/lib/ui/tools/app_lock.dart b/lib/ui/tools/app_lock.dart index ebafdb106..3e427e93d 100644 --- a/lib/ui/tools/app_lock.dart +++ b/lib/ui/tools/app_lock.dart @@ -36,6 +36,7 @@ class AppLock extends StatefulWidget { final Duration backgroundLockLatency; final ThemeData darkTheme; final ThemeData lightTheme; + final Locale locale; const AppLock({ Key key, @@ -45,6 +46,7 @@ class AppLock extends StatefulWidget { this.backgroundLockLatency = const Duration(seconds: 0), this.darkTheme, this.lightTheme, + this.locale, }) : super(key: key); static _AppLockState of(BuildContext context) => @@ -110,6 +112,7 @@ class _AppLockState extends State with WidgetsBindingObserver { themeMode: ThemeMode.system, theme: widget.lightTheme, darkTheme: widget.darkTheme, + locale: widget.locale, supportedLocales: appSupportedLocales, localeListResolutionCallback: localResolutionCallBack, localizationsDelegates: const [ diff --git a/test/app/view/app_test.dart b/test/app/view/app_test.dart index 89eda5bb6..b80fa4f53 100644 --- a/test/app/view/app_test.dart +++ b/test/app/view/app_test.dart @@ -1,10 +1,12 @@ +import "dart:ui"; + import "package:ente_auth/app/app.dart"; import "package:flutter_test/flutter_test.dart"; void main() { group("App", () { testWidgets("renders CounterPage", (tester) async { - await tester.pumpWidget(const App()); + await tester.pumpWidget(const App(Locale("en"))); // expect(find.byType(CounterPage), findsOneWidget); }); });