From 37bbb9ba864db62e4df2d7a32db6233bcea62c7b Mon Sep 17 00:00:00 2001 From: shoothzj Date: Sat, 31 Jul 2021 17:00:45 +0800 Subject: [PATCH] Supported to change language in settings --- lib/ui/bk/bk_page.dart | 3 ++- lib/ui/pulsar/screen/pulsar_namespace.dart | 3 ++- lib/ui/pulsar/screen/pulsar_tenant.dart | 3 ++- lib/ui/pulsar/tab/pulsar_details.dart | 3 ++- lib/vm/general/settings_view_model.dart | 20 +++++++++++++++++++- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/ui/bk/bk_page.dart b/lib/ui/bk/bk_page.dart index 9622370..27a1132 100644 --- a/lib/ui/bk/bk_page.dart +++ b/lib/ui/bk/bk_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/generated/l10n.dart'; import 'package:paas_dashboard_flutter/ui/util/form_util.dart'; import 'package:paas_dashboard_flutter/vm/bk/bk_instance_list_view_model.dart'; import 'package:provider/provider.dart'; @@ -28,7 +29,7 @@ class _BkPageState extends State { vm.fetchBkInstances(); }); }, - child: Text('Refresh')); + child: Text(S.of(context).refresh)); var body = ListView( children: [ Container( diff --git a/lib/ui/pulsar/screen/pulsar_namespace.dart b/lib/ui/pulsar/screen/pulsar_namespace.dart index 0a428e9..b74a122 100644 --- a/lib/ui/pulsar/screen/pulsar_namespace.dart +++ b/lib/ui/pulsar/screen/pulsar_namespace.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/generated/l10n.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_topic.dart'; import 'package:paas_dashboard_flutter/route/page_route_const.dart'; import 'package:paas_dashboard_flutter/ui/util/alert_util.dart'; @@ -94,7 +95,7 @@ class PulsarNamespaceScreenState extends State { onPressed: () { vm.fetchTopics(); }, - child: Text('Refresh')); + child: Text(S.of(context).refresh)); var searchBox = Container( width: 300, child: TextField( diff --git a/lib/ui/pulsar/screen/pulsar_tenant.dart b/lib/ui/pulsar/screen/pulsar_tenant.dart index 7be7580..b89c934 100644 --- a/lib/ui/pulsar/screen/pulsar_tenant.dart +++ b/lib/ui/pulsar/screen/pulsar_tenant.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/generated/l10n.dart'; import 'package:paas_dashboard_flutter/route/page_route_const.dart'; import 'package:paas_dashboard_flutter/ui/pulsar/pulsar_const.dart'; import 'package:paas_dashboard_flutter/ui/util/alert_util.dart'; @@ -60,7 +61,7 @@ class PulsarTenantScreenState extends State { onPressed: () { vm.fetchNamespaces(); }, - child: Text('Refresh')); + child: Text(S.of(context).refresh)); var searchBox = Container( width: 300, child: TextField( diff --git a/lib/ui/pulsar/tab/pulsar_details.dart b/lib/ui/pulsar/tab/pulsar_details.dart index ed70646..c918c4e 100644 --- a/lib/ui/pulsar/tab/pulsar_details.dart +++ b/lib/ui/pulsar/tab/pulsar_details.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/generated/l10n.dart'; import 'package:paas_dashboard_flutter/route/page_route_const.dart'; import 'package:paas_dashboard_flutter/ui/util/alert_util.dart'; import 'package:paas_dashboard_flutter/ui/util/form_util.dart'; @@ -59,7 +60,7 @@ class PulsarTenantsState extends State { onPressed: () { vm.fetchTenants(); }, - child: Text('Refresh')); + child: Text(S.of(context).refresh)); var searchBox = Container( width: 300, child: TextField( diff --git a/lib/vm/general/settings_view_model.dart b/lib/vm/general/settings_view_model.dart index 1d2bf20..4362005 100644 --- a/lib/vm/general/settings_view_model.dart +++ b/lib/vm/general/settings_view_model.dart @@ -1,10 +1,28 @@ +import 'dart:io'; + +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/generated/l10n.dart'; class SettingsViewModel extends ChangeNotifier { - String language = 'en'; + String language = "zh"; + + SettingsViewModel() { + if (!kIsWeb) { + this.language = Platform.localeName.split("_")[0]; + } + } void setLan(String lan) { this.language = lan; + switch (lan) { + case "zh": + S.load(Locale('zh', 'CN')); + break; + case "en": + S.load(Locale('en', 'US')); + break; + } notifyListeners(); } }