diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index c07764e32..3e08d1e0c 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -244,6 +244,31 @@ final ButtonStyle flatButtonStyle = TextButton.styleFrom( ), ); +List supportedLocales = const [ + // specify CN/TW to fix CJK issue in flutter + Locale('zh', 'CN'), + Locale('zh', 'TW'), + Locale('fr'), + Locale('de'), + Locale('it'), + Locale('ja'), + Locale('cs'), + Locale('pl'), + Locale('ko'), + Locale('hu'), + Locale('pt'), + Locale('ru'), + Locale('sk'), + Locale('id'), + Locale('da'), + Locale('eo'), + Locale('tr'), + Locale('vi'), + Locale('pl'), + Locale('kz'), + Locale('en', 'US'), +]; + String formatDurationToTime(Duration duration) { var totalTime = duration.inSeconds; final secs = totalTime % 60; diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 43069bf79..8f04846e9 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -8,6 +8,7 @@ import 'package:flutter_hbb/desktop/screen/desktop_file_transfer_screen.dart'; import 'package:flutter_hbb/desktop/screen/desktop_port_forward_screen.dart'; import 'package:flutter_hbb/desktop/screen/desktop_remote_screen.dart'; import 'package:flutter_hbb/utils/multi_window_manager.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -123,6 +124,12 @@ void runRemoteScreen(Map argument) async { home: DesktopRemoteScreen( params: argument, ), + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: supportedLocales, navigatorObservers: const [ // FirebaseAnalyticsObserver(analytics: analytics), ], @@ -141,6 +148,12 @@ void runFileTransferScreen(Map argument) async { darkTheme: MyTheme.darkTheme, themeMode: MyTheme.initialThemeMode(), home: DesktopFileTransferScreen(params: argument), + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: supportedLocales, navigatorObservers: const [ // FirebaseAnalyticsObserver(analytics: analytics), ], @@ -160,6 +173,12 @@ void runPortForwardScreen(Map argument) async { darkTheme: MyTheme.darkTheme, themeMode: MyTheme.initialThemeMode(), home: DesktopPortForwardScreen(params: argument), + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: supportedLocales, navigatorObservers: const [ // FirebaseAnalyticsObserver(analytics: analytics), ], @@ -178,14 +197,20 @@ void runConnectionManagerScreen() async { theme: MyTheme.lightTheme, darkTheme: MyTheme.darkTheme, themeMode: MyTheme.initialThemeMode(), + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: supportedLocales, home: const DesktopServerPage(), builder: _keepScaleBuilder())); windowManager.waitUntilReadyToShow(windowOptions, () async { - await windowManager.setAlignment(Alignment.topRight); - await windowManager.show(); - await windowManager.focus(); - await windowManager.setAlignment(Alignment.topRight); // ensure - }); + await windowManager.setAlignment(Alignment.topRight); + await windowManager.show(); + await windowManager.focus(); + await windowManager.setAlignment(Alignment.topRight); // ensure + }); } WindowOptions getHiddenTitleBarWindowOptions({Size? size}) { @@ -247,6 +272,12 @@ class _AppState extends State { navigatorObservers: const [ // FirebaseAnalyticsObserver(analytics: analytics), ], + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: supportedLocales, builder: isAndroid ? (context, child) => AccessibilityListener( child: MediaQuery( diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index 09025ad0e..9248fe80e 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -24,6 +24,8 @@ environment: dependencies: flutter: sdk: flutter + flutter_localizations: + sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.