diff --git a/src/ui/flutter_app/lib/common/config.dart b/src/ui/flutter_app/lib/common/config.dart index d3d71c5f..c07ea070 100644 --- a/src/ui/flutter_app/lib/common/config.dart +++ b/src/ui/flutter_app/lib/common/config.dart @@ -45,6 +45,7 @@ class Config { static bool experimentsEnabled = false; // Display + static String language = "Default"; static bool standardNotationEnabled = true; static bool isPieceCountInHandShown = false; static bool isNotationsShown = false; @@ -105,6 +106,7 @@ class Config { Config.experimentsEnabled = settings['ExperimentsEnabled'] ?? false; // Display + Config.language = settings['Language'] ?? "Default"; Config.standardNotationEnabled = settings['StandardNotationEnabled'] ?? true; Config.isPieceCountInHandShown = @@ -185,6 +187,7 @@ class Config { settings['ExperimentsEnabled'] = Config.experimentsEnabled; // Display + settings['Language'] = Config.language; settings['StandardNotationEnabled'] = Config.standardNotationEnabled; settings['IsPieceCountInHandShown'] = Config.isPieceCountInHandShown; settings['IsNotationsShown'] = Config.isNotationsShown; diff --git a/src/ui/flutter_app/lib/l10n/intl_de.arb b/src/ui/flutter_app/lib/l10n/intl_de.arb index a32a01cf..60b7b1e5 100644 --- a/src/ui/flutter_app/lib/l10n/intl_de.arb +++ b/src/ui/flutter_app/lib/l10n/intl_de.arb @@ -943,5 +943,13 @@ "ossLicenses": "Open Source Lizenzen", "@ossLicenses": { "description": "Open source licenses" + }, + "language": "Sprache", + "@language": { + "description": "Languages" + }, + "defaultLanguage": "Standardsprache", + "@defaultLanguage": { + "description": "Default language" } } diff --git a/src/ui/flutter_app/lib/l10n/intl_en.arb b/src/ui/flutter_app/lib/l10n/intl_en.arb index 131a0fd1..45998cb7 100644 --- a/src/ui/flutter_app/lib/l10n/intl_en.arb +++ b/src/ui/flutter_app/lib/l10n/intl_en.arb @@ -943,5 +943,13 @@ "ossLicenses": "Open source licenses", "@ossLicenses": { "description": "Open source licenses" + }, + "language": "Language", + "@language": { + "description": "Languages" + }, + "defaultLanguage": "Default language", + "@defaultLanguage": { + "description": "Default language" } } diff --git a/src/ui/flutter_app/lib/l10n/intl_fa.arb b/src/ui/flutter_app/lib/l10n/intl_fa.arb index ad8f0268..c585780e 100644 --- a/src/ui/flutter_app/lib/l10n/intl_fa.arb +++ b/src/ui/flutter_app/lib/l10n/intl_fa.arb @@ -943,5 +943,13 @@ "ossLicenses": "Open Source Lizenzen", "@ossLicenses": { "description": "مجوزهای منبع آزاد" + }, + "language": "زبان", + "@language": { + "description": "Languages" + }, + "defaultLanguage": "زبان پیش فرض", + "@defaultLanguage": { + "description": "Default language" } } diff --git a/src/ui/flutter_app/lib/l10n/intl_hu.arb b/src/ui/flutter_app/lib/l10n/intl_hu.arb index 23e97b42..1ddbbef0 100644 --- a/src/ui/flutter_app/lib/l10n/intl_hu.arb +++ b/src/ui/flutter_app/lib/l10n/intl_hu.arb @@ -943,5 +943,13 @@ "ossLicenses": "Nyílt forráskódú licencek", "@ossLicenses": { "description": "Open source licenses" + }, + "language": "Nyelv", + "@language": { + "description": "Languages" + }, + "defaultLanguage": "Alapértelmezett nyelv", + "@defaultLanguage": { + "description": "Default language" } } diff --git a/src/ui/flutter_app/lib/l10n/intl_ro.arb b/src/ui/flutter_app/lib/l10n/intl_ro.arb index 4ea230ed..14800f3a 100644 --- a/src/ui/flutter_app/lib/l10n/intl_ro.arb +++ b/src/ui/flutter_app/lib/l10n/intl_ro.arb @@ -943,5 +943,13 @@ "ossLicenses": "Licențe open source", "@ossLicenses": { "description": "Open source licenses" + }, + "language": "Limba", + "@language": { + "description": "Languages" + }, + "defaultLanguage": "Limba implicita", + "@defaultLanguage": { + "description": "Default language" } } \ No newline at end of file diff --git a/src/ui/flutter_app/lib/l10n/intl_zh.arb b/src/ui/flutter_app/lib/l10n/intl_zh.arb index 008a3843..5fd004ff 100644 --- a/src/ui/flutter_app/lib/l10n/intl_zh.arb +++ b/src/ui/flutter_app/lib/l10n/intl_zh.arb @@ -235,5 +235,7 @@ "more": "更多", "experimental": "此仍属实验性功能。", "experiments": "实验性功能", - "ossLicenses": "开放源代码许可" + "ossLicenses": "开放源代码许可", + "language": "显示语言", + "defaultLanguage": "默认语言" } \ No newline at end of file diff --git a/src/ui/flutter_app/lib/l10n/resources.dart b/src/ui/flutter_app/lib/l10n/resources.dart index f48f5060..59ff17a9 100644 --- a/src/ui/flutter_app/lib/l10n/resources.dart +++ b/src/ui/flutter_app/lib/l10n/resources.dart @@ -18,6 +18,15 @@ import 'dart:io'; +Map languageMap = { + "de": "Deutsch", + "en": "English", + "fa": "فارسی", + "hu": "Magyar", + "ro": "Română", + "zh": "简体中文", +}; + /// Interface strings abstract class Strings { String get tapBackAgainToLeave; diff --git a/src/ui/flutter_app/lib/widgets/game_page.dart b/src/ui/flutter_app/lib/widgets/game_page.dart index e24fe8a8..0728ab8d 100644 --- a/src/ui/flutter_app/lib/widgets/game_page.dart +++ b/src/ui/flutter_app/lib/widgets/game_page.dart @@ -1647,24 +1647,34 @@ class _GamePageState extends State } @override - void didPush() { + void didPush() async { final route = ModalRoute.of(context)!.settings.name; print('$tag Game Page didPush route: $route'); - widget.engine.setOptions(); + await widget.engine.setOptions(); + if (Config.language != "Default") { + S.load(Locale(Config.language)); + setState(() {}); + } } @override - void didPopNext() { + void didPopNext() async { final route = ModalRoute.of(context)!.settings.name; print('$tag Game Page didPopNext route: $route'); - widget.engine.setOptions(); + await widget.engine.setOptions(); + if (Config.language != "Default") { + S.load(Locale(Config.language)); + } } @override - void didPushNext() { + void didPushNext() async { final route = ModalRoute.of(context)!.settings.name; print('$tag Game Page didPushNext route: $route'); - widget.engine.setOptions(); + await widget.engine.setOptions(); + if (Config.language != "Default") { + S.load(Locale(Config.language)); + } } @override diff --git a/src/ui/flutter_app/lib/widgets/game_settings_page.dart b/src/ui/flutter_app/lib/widgets/game_settings_page.dart index 9aefbe57..9f516c70 100644 --- a/src/ui/flutter_app/lib/widgets/game_settings_page.dart +++ b/src/ui/flutter_app/lib/widgets/game_settings_page.dart @@ -505,6 +505,16 @@ class _GameSettingsPageState extends State { // Display + setLanguage(String value) async { + setState(() { + Config.language = value; + }); + + print("[config] language: $value"); + + Config.save(); + } + setIsPieceCountInHandShown(bool value) async { setState(() { Config.isPieceCountInHandShown = value; diff --git a/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart b/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart index 1107baef..994a6a07 100644 --- a/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart +++ b/src/ui/flutter_app/lib/widgets/personalization_settings_page.dart @@ -16,10 +16,13 @@ along with this program. If not, see . */ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart'; import 'package:sanmill/common/config.dart'; import 'package:sanmill/generated/l10n.dart'; +import 'package:sanmill/l10n/resources.dart'; import 'package:sanmill/style/app_theme.dart'; import 'package:sanmill/widgets/settings_card.dart'; import 'package:sanmill/widgets/settings_list_tile.dart'; @@ -337,6 +340,14 @@ class _PersonalizationSettingsPageState SettingsCard( context: context, children: [ + SettingsListTile( + context: context, + titleString: S.of(context).language, + trailingString: + Config.language == "Default" ? "" : Config.language.toString(), + onTap: setLanguage, + ), + ListItemDivider(), SettingsSwitchListTile( context: context, value: Config.isPieceCountInHandShown, @@ -454,6 +465,93 @@ class _PersonalizationSettingsPageState // Display + setLanguage() async { + callback(var lang) async { + print("[config] language = $lang"); + + Navigator.of(context).pop(); + + setState(() { + Config.language = lang ?? "Default"; + + if (Config.language != "Default") { + S.load(Locale(Config.language)); + } else { + S.load(Locale(Platform.localeName.substring(0, 2))); + } + }); + + print("[config] Config.language: ${Config.language}"); + + Config.save(); + } + + showModalBottomSheet( + context: context, + builder: (BuildContext context) => Column( + mainAxisSize: MainAxisSize.min, + children: [ + RadioListTile( + activeColor: AppTheme.switchListTileActiveColor, + title: Text(S.of(context).defaultLanguage), + groupValue: Config.language, + value: "Default", + onChanged: callback, + ), + ListItemDivider(), + RadioListTile( + activeColor: AppTheme.switchListTileActiveColor, + title: Text(languageMap["de"]!), + groupValue: Config.language, + value: "de", + onChanged: callback, + ), + ListItemDivider(), + RadioListTile( + activeColor: AppTheme.switchListTileActiveColor, + title: Text(languageMap["en"]!), + groupValue: Config.language, + value: "en", + onChanged: callback, + ), + ListItemDivider(), + RadioListTile( + activeColor: AppTheme.switchListTileActiveColor, + title: Text(languageMap["fa"]!), + groupValue: Config.language, + value: "fa", + onChanged: callback, + ), + ListItemDivider(), + RadioListTile( + activeColor: AppTheme.switchListTileActiveColor, + title: Text(languageMap["hu"]!), + groupValue: Config.language, + value: "hu", + onChanged: callback, + ), + ListItemDivider(), + RadioListTile( + activeColor: AppTheme.switchListTileActiveColor, + title: Text(languageMap["ro"]!), + groupValue: Config.language, + value: "ro", + onChanged: callback, + ), + ListItemDivider(), + RadioListTile( + activeColor: AppTheme.switchListTileActiveColor, + title: Text(languageMap["zh"]!), + groupValue: Config.language, + value: "zh", + onChanged: callback, + ), + ListItemDivider(), + ], + ), + ); + } + setIsPieceCountInHandShown(bool value) async { setState(() { Config.isPieceCountInHandShown = value; diff --git a/src/ui/flutter_app/lib/widgets/settings_switch_list_tile.dart b/src/ui/flutter_app/lib/widgets/settings_switch_list_tile.dart index 1472f1fe..58599264 100644 --- a/src/ui/flutter_app/lib/widgets/settings_switch_list_tile.dart +++ b/src/ui/flutter_app/lib/widgets/settings_switch_list_tile.dart @@ -31,7 +31,7 @@ class SettingsSwitchListTile extends StatelessWidget { }) : super(key: key); final BuildContext context; - final bool value; + final value; final String titleString; final String? subtitleString; final onChanged; diff --git a/src/ui/flutter_app/pubspec.yaml b/src/ui/flutter_app/pubspec.yaml index 2c106b6a..03ceab68 100644 --- a/src/ui/flutter_app/pubspec.yaml +++ b/src/ui/flutter_app/pubspec.yaml @@ -26,6 +26,7 @@ dependencies: devicelocale: ^0.4.1 double_back_to_close_app: ^2.0.1 flutter_picker: ^2.0.1 + #pref: ^2.3.0 #screen_recorder: ^0.0.2 dev_dependencies: