settings: Support set language
Known issue: String "Welcome" is shown as default language.
This commit is contained in:
parent
8cc0d2cea9
commit
f456fecea3
|
@ -45,6 +45,7 @@ class Config {
|
||||||
static bool experimentsEnabled = false;
|
static bool experimentsEnabled = false;
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
|
static String language = "Default";
|
||||||
static bool standardNotationEnabled = true;
|
static bool standardNotationEnabled = true;
|
||||||
static bool isPieceCountInHandShown = false;
|
static bool isPieceCountInHandShown = false;
|
||||||
static bool isNotationsShown = false;
|
static bool isNotationsShown = false;
|
||||||
|
@ -105,6 +106,7 @@ class Config {
|
||||||
Config.experimentsEnabled = settings['ExperimentsEnabled'] ?? false;
|
Config.experimentsEnabled = settings['ExperimentsEnabled'] ?? false;
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
|
Config.language = settings['Language'] ?? "Default";
|
||||||
Config.standardNotationEnabled =
|
Config.standardNotationEnabled =
|
||||||
settings['StandardNotationEnabled'] ?? true;
|
settings['StandardNotationEnabled'] ?? true;
|
||||||
Config.isPieceCountInHandShown =
|
Config.isPieceCountInHandShown =
|
||||||
|
@ -185,6 +187,7 @@ class Config {
|
||||||
settings['ExperimentsEnabled'] = Config.experimentsEnabled;
|
settings['ExperimentsEnabled'] = Config.experimentsEnabled;
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
|
settings['Language'] = Config.language;
|
||||||
settings['StandardNotationEnabled'] = Config.standardNotationEnabled;
|
settings['StandardNotationEnabled'] = Config.standardNotationEnabled;
|
||||||
settings['IsPieceCountInHandShown'] = Config.isPieceCountInHandShown;
|
settings['IsPieceCountInHandShown'] = Config.isPieceCountInHandShown;
|
||||||
settings['IsNotationsShown'] = Config.isNotationsShown;
|
settings['IsNotationsShown'] = Config.isNotationsShown;
|
||||||
|
|
|
@ -943,5 +943,13 @@
|
||||||
"ossLicenses": "Open Source Lizenzen",
|
"ossLicenses": "Open Source Lizenzen",
|
||||||
"@ossLicenses": {
|
"@ossLicenses": {
|
||||||
"description": "Open source licenses"
|
"description": "Open source licenses"
|
||||||
|
},
|
||||||
|
"language": "Sprache",
|
||||||
|
"@language": {
|
||||||
|
"description": "Languages"
|
||||||
|
},
|
||||||
|
"defaultLanguage": "Standardsprache",
|
||||||
|
"@defaultLanguage": {
|
||||||
|
"description": "Default language"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -943,5 +943,13 @@
|
||||||
"ossLicenses": "Open source licenses",
|
"ossLicenses": "Open source licenses",
|
||||||
"@ossLicenses": {
|
"@ossLicenses": {
|
||||||
"description": "Open source licenses"
|
"description": "Open source licenses"
|
||||||
|
},
|
||||||
|
"language": "Language",
|
||||||
|
"@language": {
|
||||||
|
"description": "Languages"
|
||||||
|
},
|
||||||
|
"defaultLanguage": "Default language",
|
||||||
|
"@defaultLanguage": {
|
||||||
|
"description": "Default language"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -943,5 +943,13 @@
|
||||||
"ossLicenses": "Open Source Lizenzen",
|
"ossLicenses": "Open Source Lizenzen",
|
||||||
"@ossLicenses": {
|
"@ossLicenses": {
|
||||||
"description": "مجوزهای منبع آزاد"
|
"description": "مجوزهای منبع آزاد"
|
||||||
|
},
|
||||||
|
"language": "زبان",
|
||||||
|
"@language": {
|
||||||
|
"description": "Languages"
|
||||||
|
},
|
||||||
|
"defaultLanguage": "زبان پیش فرض",
|
||||||
|
"@defaultLanguage": {
|
||||||
|
"description": "Default language"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -943,5 +943,13 @@
|
||||||
"ossLicenses": "Nyílt forráskódú licencek",
|
"ossLicenses": "Nyílt forráskódú licencek",
|
||||||
"@ossLicenses": {
|
"@ossLicenses": {
|
||||||
"description": "Open source licenses"
|
"description": "Open source licenses"
|
||||||
|
},
|
||||||
|
"language": "Nyelv",
|
||||||
|
"@language": {
|
||||||
|
"description": "Languages"
|
||||||
|
},
|
||||||
|
"defaultLanguage": "Alapértelmezett nyelv",
|
||||||
|
"@defaultLanguage": {
|
||||||
|
"description": "Default language"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -943,5 +943,13 @@
|
||||||
"ossLicenses": "Licențe open source",
|
"ossLicenses": "Licențe open source",
|
||||||
"@ossLicenses": {
|
"@ossLicenses": {
|
||||||
"description": "Open source licenses"
|
"description": "Open source licenses"
|
||||||
|
},
|
||||||
|
"language": "Limba",
|
||||||
|
"@language": {
|
||||||
|
"description": "Languages"
|
||||||
|
},
|
||||||
|
"defaultLanguage": "Limba implicita",
|
||||||
|
"@defaultLanguage": {
|
||||||
|
"description": "Default language"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -235,5 +235,7 @@
|
||||||
"more": "更多",
|
"more": "更多",
|
||||||
"experimental": "此仍属实验性功能。",
|
"experimental": "此仍属实验性功能。",
|
||||||
"experiments": "实验性功能",
|
"experiments": "实验性功能",
|
||||||
"ossLicenses": "开放源代码许可"
|
"ossLicenses": "开放源代码许可",
|
||||||
|
"language": "显示语言",
|
||||||
|
"defaultLanguage": "默认语言"
|
||||||
}
|
}
|
|
@ -18,6 +18,15 @@
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
Map<String, String> languageMap = {
|
||||||
|
"de": "Deutsch",
|
||||||
|
"en": "English",
|
||||||
|
"fa": "فارسی",
|
||||||
|
"hu": "Magyar",
|
||||||
|
"ro": "Română",
|
||||||
|
"zh": "简体中文",
|
||||||
|
};
|
||||||
|
|
||||||
/// Interface strings
|
/// Interface strings
|
||||||
abstract class Strings {
|
abstract class Strings {
|
||||||
String get tapBackAgainToLeave;
|
String get tapBackAgainToLeave;
|
||||||
|
|
|
@ -1647,24 +1647,34 @@ class _GamePageState extends State<GamePage>
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didPush() {
|
void didPush() async {
|
||||||
final route = ModalRoute.of(context)!.settings.name;
|
final route = ModalRoute.of(context)!.settings.name;
|
||||||
print('$tag Game Page didPush route: $route');
|
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
|
@override
|
||||||
void didPopNext() {
|
void didPopNext() async {
|
||||||
final route = ModalRoute.of(context)!.settings.name;
|
final route = ModalRoute.of(context)!.settings.name;
|
||||||
print('$tag Game Page didPopNext route: $route');
|
print('$tag Game Page didPopNext route: $route');
|
||||||
widget.engine.setOptions();
|
await widget.engine.setOptions();
|
||||||
|
if (Config.language != "Default") {
|
||||||
|
S.load(Locale(Config.language));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didPushNext() {
|
void didPushNext() async {
|
||||||
final route = ModalRoute.of(context)!.settings.name;
|
final route = ModalRoute.of(context)!.settings.name;
|
||||||
print('$tag Game Page didPushNext route: $route');
|
print('$tag Game Page didPushNext route: $route');
|
||||||
widget.engine.setOptions();
|
await widget.engine.setOptions();
|
||||||
|
if (Config.language != "Default") {
|
||||||
|
S.load(Locale(Config.language));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -505,6 +505,16 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
|
|
||||||
|
setLanguage(String value) async {
|
||||||
|
setState(() {
|
||||||
|
Config.language = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
print("[config] language: $value");
|
||||||
|
|
||||||
|
Config.save();
|
||||||
|
}
|
||||||
|
|
||||||
setIsPieceCountInHandShown(bool value) async {
|
setIsPieceCountInHandShown(bool value) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
Config.isPieceCountInHandShown = value;
|
Config.isPieceCountInHandShown = value;
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||||||
import 'package:sanmill/common/config.dart';
|
import 'package:sanmill/common/config.dart';
|
||||||
import 'package:sanmill/generated/l10n.dart';
|
import 'package:sanmill/generated/l10n.dart';
|
||||||
|
import 'package:sanmill/l10n/resources.dart';
|
||||||
import 'package:sanmill/style/app_theme.dart';
|
import 'package:sanmill/style/app_theme.dart';
|
||||||
import 'package:sanmill/widgets/settings_card.dart';
|
import 'package:sanmill/widgets/settings_card.dart';
|
||||||
import 'package:sanmill/widgets/settings_list_tile.dart';
|
import 'package:sanmill/widgets/settings_list_tile.dart';
|
||||||
|
@ -337,6 +340,14 @@ class _PersonalizationSettingsPageState
|
||||||
SettingsCard(
|
SettingsCard(
|
||||||
context: context,
|
context: context,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
SettingsListTile(
|
||||||
|
context: context,
|
||||||
|
titleString: S.of(context).language,
|
||||||
|
trailingString:
|
||||||
|
Config.language == "Default" ? "" : Config.language.toString(),
|
||||||
|
onTap: setLanguage,
|
||||||
|
),
|
||||||
|
ListItemDivider(),
|
||||||
SettingsSwitchListTile(
|
SettingsSwitchListTile(
|
||||||
context: context,
|
context: context,
|
||||||
value: Config.isPieceCountInHandShown,
|
value: Config.isPieceCountInHandShown,
|
||||||
|
@ -454,6 +465,93 @@ class _PersonalizationSettingsPageState
|
||||||
|
|
||||||
// Display
|
// 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: <Widget>[
|
||||||
|
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 {
|
setIsPieceCountInHandShown(bool value) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
Config.isPieceCountInHandShown = value;
|
Config.isPieceCountInHandShown = value;
|
||||||
|
|
|
@ -31,7 +31,7 @@ class SettingsSwitchListTile extends StatelessWidget {
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final BuildContext context;
|
final BuildContext context;
|
||||||
final bool value;
|
final value;
|
||||||
final String titleString;
|
final String titleString;
|
||||||
final String? subtitleString;
|
final String? subtitleString;
|
||||||
final onChanged;
|
final onChanged;
|
||||||
|
|
|
@ -26,6 +26,7 @@ dependencies:
|
||||||
devicelocale: ^0.4.1
|
devicelocale: ^0.4.1
|
||||||
double_back_to_close_app: ^2.0.1
|
double_back_to_close_app: ^2.0.1
|
||||||
flutter_picker: ^2.0.1
|
flutter_picker: ^2.0.1
|
||||||
|
#pref: ^2.3.0
|
||||||
#screen_recorder: ^0.0.2
|
#screen_recorder: ^0.0.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
Loading…
Reference in New Issue