Browse Source

add l10n in device page and fix language better show

pull/6/head
Sun 4 years ago
parent
commit
143dab9638
  1. 12
      lib/l10n/localizations.dart
  2. 24
      lib/l10n/localizations_en.dart
  3. 24
      lib/l10n/localizations_zh.dart
  4. 8
      lib/options.dart
  5. 2
      lib/pages/account_generate.dart
  6. 97
      lib/pages/device.dart
  7. 2
      lib/pages/setting/preference.dart
  8. 12
      lib/utils/mnemonic.dart

12
lib/l10n/localizations.dart

@ -84,8 +84,6 @@ abstract class AppLocalizations { @@ -84,8 +84,6 @@ abstract class AppLocalizations {
// langs
String get lang;
String get langEn;
String get langZh;
// security page (did)
String get loginChooseAccount;
@ -140,6 +138,16 @@ abstract class AppLocalizations { @@ -140,6 +138,16 @@ abstract class AppLocalizations {
String get deviceLocal;
String get deviceQrcode;
String get deviceQrcodeIntro;
String get addDevice;
String get reconnect;
String get status;
String get uptime;
String get days;
String get hours;
String get minutes;
String get memory;
String get swap;
String get disk;
String get openSource;
String get tdnBased;
String get donate;

24
lib/l10n/localizations_en.dart

@ -88,10 +88,6 @@ class AppLocalizationsEn extends AppLocalizations { @@ -88,10 +88,6 @@ class AppLocalizationsEn extends AppLocalizations {
// langs
@override
String get lang => 'Language';
@override
String get langEn => 'English';
@override
String get langZh => 'Chinese';
// security page (did)
@override
@ -191,6 +187,26 @@ class AppLocalizationsEn extends AppLocalizations { @@ -191,6 +187,26 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get deviceQrcode => 'Device QR Code';
@override
String get addDevice => 'Add Device';
@override
String get reconnect => 'Re-Connect';
@override
String get status => 'View Status';
@override
String get uptime => 'Uptime';
@override
String get days => 'Days';
@override
String get hours => 'Hours';
@override
String get minutes => 'Minutes';
@override
String get memory => 'Memory';
@override
String get swap => 'Swap';
@override
String get disk => 'Disk';
@override
String get deviceQrcodeIntro => 'Tips: Scan to Login and sync, use it with care, and do not tell others';
@override
String get openSource => 'Open Source Power By CympleTech.';

24
lib/l10n/localizations_zh.dart

@ -88,10 +88,6 @@ class AppLocalizationsZh extends AppLocalizations { @@ -88,10 +88,6 @@ class AppLocalizationsZh extends AppLocalizations {
// langs
@override
String get lang => '语言';
@override
String get langEn => '英语';
@override
String get langZh => '简体中文';
// security page (did)
@override
@ -191,6 +187,26 @@ class AppLocalizationsZh extends AppLocalizations { @@ -191,6 +187,26 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get deviceQrcode => '设备二维码';
@override
String get addDevice => '添加设备';
@override
String get reconnect => '重连';
@override
String get status => '查看状态';
@override
String get uptime => '已运行';
@override
String get days => '';
@override
String get hours => '小时';
@override
String get minutes => '分钟';
@override
String get memory => '内存';
@override
String get swap => '虚拟内存';
@override
String get disk => '硬盘';
@override
String get deviceQrcodeIntro => '扫码登陆与同步账户,小心使用,请勿告知他人';
@override
String get openSource => '开源代码由 CympleTech 公司组织开发。';

8
lib/options.dart

@ -95,14 +95,14 @@ extension ThemeTypeExtension on ThemeMode { @@ -95,14 +95,14 @@ extension ThemeTypeExtension on ThemeMode {
}
extension LocaleTypeExtension on Locale {
String localizations(BuildContext context) {
String localizations() {
switch (this) {
case Locale('en'):
return AppLocalizations.of(context).langEn;
return 'English';
case Locale('zh'):
return AppLocalizations.of(context).langZh;
return '简体中文';
default:
return AppLocalizations.of(context).langEn;
return 'English';
}
}

2
lib/pages/account_generate.dart

@ -259,7 +259,7 @@ class _AccountGeneratePageState extends State<AccountGeneratePage> { @@ -259,7 +259,7 @@ class _AccountGeneratePageState extends State<AccountGeneratePage> {
items: MNEMONIC_LANGS.map((MnemonicLang m) {
return DropdownMenuItem<int>(
value: m.toInt(),
child: Text(m.localizations(context),
child: Text(m.localizations(),
style: TextStyle(fontSize: 16)));
}).toList(),
)),

97
lib/pages/device.dart

@ -10,6 +10,7 @@ import 'package:esse/models/device.dart'; @@ -10,6 +10,7 @@ import 'package:esse/models/device.dart';
import 'package:esse/widgets/shadow_dialog.dart';
import 'package:esse/widgets/input_text.dart';
import 'package:esse/widgets/button_text.dart';
import 'package:esse/widgets/show_pin.dart';
import 'package:esse/provider/device.dart';
import 'package:esse/provider/account.dart';
import 'package:esse/global.dart';
@ -25,10 +26,10 @@ class _DevicesPageState extends State<DevicesPage> { @@ -25,10 +26,10 @@ class _DevicesPageState extends State<DevicesPage> {
FocusNode _addrFocus = FocusNode();
_inputAddress(lang) {
showShadowDialog(context, Icons.qr_code_rounded, lang.deviceQrcode,
showShadowDialog(context, Icons.devices_rounded, lang.addDevice,
Column(
children: [
InputText(icon: Icons.location_on, text: lang.address,
InputText(icon: Icons.location_on, text: "${lang.address} (0x...)",
controller: this._addrController, focus: this._addrFocus),
const SizedBox(height: 32.0),
ButtonText(
@ -110,9 +111,9 @@ class _DevicesPageState extends State<DevicesPage> { @@ -110,9 +111,9 @@ class _DevicesPageState extends State<DevicesPage> {
// TODO
}
Widget deviceWidget(ColorScheme color, Device device, String local, bool isDesktop, double widgetWidth) {
Widget deviceWidget(ColorScheme color, Device device, bool isDesktop, double widgetWidth, lang) {
final bool isLocal = '0x' + device.addr == Global.addr;
final String name = isLocal ? (device.name + " (${local})") : device.name;
final String name = isLocal ? (device.name + " (${lang.deviceLocal})") : device.name;
return Container(
width: widgetWidth,
@ -138,14 +139,14 @@ class _DevicesPageState extends State<DevicesPage> { @@ -138,14 +139,14 @@ class _DevicesPageState extends State<DevicesPage> {
children: <Widget>[
if (!isLocal && !device.online)
TextButton(
child: const Text('RE-CONNECT'),
child: Text(lang.reconnect),
onPressed: () {
Provider.of<DeviceProvider>(context, listen: false).connect(device.addr);
},
),
if (isLocal || device.online)
TextButton(
child: const Text('VIEW DETAIL'),
child: Text(lang.status),
onPressed: () {
Provider.of<DeviceProvider>(context, listen: false).updateActived(device.id);
final widget = DeviceListenPage();
@ -158,10 +159,9 @@ class _DevicesPageState extends State<DevicesPage> { @@ -158,10 +159,9 @@ class _DevicesPageState extends State<DevicesPage> {
),
if (!isLocal)
TextButton(
child: const Text('DELETE', style: TextStyle(color: Colors.red)),
child: Text(lang.delete, style: TextStyle(color: Colors.red)),
onPressed: () {},
),
//const SizedBox(width: 10.0),
],
),
],
@ -181,9 +181,8 @@ class _DevicesPageState extends State<DevicesPage> { @@ -181,9 +181,8 @@ class _DevicesPageState extends State<DevicesPage> {
widgetWidth = (MediaQuery.of(context).size.width - 450) / 2;
}
final localDevice = lang.deviceLocal;
final List<Widget> devicesWidgets = provider.devices.values.map((device) {
return deviceWidget(color, device, localDevice, isDesktop, widgetWidth);
return deviceWidget(color, device, isDesktop, widgetWidth, lang);
}).toList();
return Scaffold(
@ -214,31 +213,55 @@ class _DevicesPageState extends State<DevicesPage> { @@ -214,31 +213,55 @@ class _DevicesPageState extends State<DevicesPage> {
// input address to connect.
_inputAddress(lang);
} else if (value == 1) {
// input fields.
_scanQrCode();
} else if (value == 2) {
// show qrcode.
final account = Provider.of<AccountProvider>(context, listen: false).activedAccount;
_showQrCode(
account.name,
account.id,
Global.addr,
account.lock,
color,
lang,
);
final account = Provider.of<AccountProvider>(
context, listen: false).activedAccount;
showShadowDialog(
context,
Icons.security_rounded,
lang.verifyPin,
PinWords(
hashPin: account.lock,
callback: (_key, _hash) async {
Navigator.of(context).pop();
_showQrCode(
account.name,
account.id,
Global.addr,
account.lock,
color,
lang,
);
}));
}
},
itemBuilder: (context) {
return <PopupMenuEntry<int>>[
PopupMenuItem<int>(value: 0,
child: Text(lang.address, style: TextStyle(color: Colors.black)),
child: Row(
children: [
Container(
padding: const EdgeInsets.only(right: 10.0),
width: 30.0,
height: 30.0,
child: Icon(Icons.add_rounded, color: color.primary),
),
Text(lang.addDevice, style: TextStyle(color: Colors.black)),
]
)
),
PopupMenuItem<int>(value: 1,
child: Text(lang.scan, style: TextStyle(color: Colors.black)),
),
PopupMenuItem<int>(value: 2,
child: Text(lang.deviceQrcode, style: TextStyle(color: Colors.black)),
child: Row(
children: [
Container(
padding: const EdgeInsets.only(right: 10.0),
width: 30.0,
height: 30.0,
child: Icon(Icons.qr_code_rounded, color: color.primary),
),
Text(lang.deviceQrcode, style: TextStyle(color: Colors.black)),
]
)
),
];
}
@ -296,18 +319,6 @@ class _DeviceListenPageState extends State<DeviceListenPage> { @@ -296,18 +319,6 @@ class _DeviceListenPageState extends State<DeviceListenPage> {
);
}
Widget memoryWidget() {
return Text('Memory');
}
Widget swapWidget() {
return Text('Swap');
}
Widget diskWidget() {
return Text('Disk');
}
@override
Widget build(BuildContext context) {
final color = Theme.of(context).colorScheme;
@ -353,7 +364,7 @@ class _DeviceListenPageState extends State<DeviceListenPage> { @@ -353,7 +364,7 @@ class _DeviceListenPageState extends State<DeviceListenPage> {
),
Expanded(
child: Text(
"Uptime: ${uptimes[0]} Days, ${uptimes[1]} Hours, ${uptimes[2]} Minutes",
"${lang.uptime}: ${uptimes[0]} ${lang.days}, ${uptimes[1]} ${lang.hours}, ${uptimes[2]} ${lang.minutes}",
style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.right,
),
@ -378,7 +389,7 @@ class _DeviceListenPageState extends State<DeviceListenPage> { @@ -378,7 +389,7 @@ class _DeviceListenPageState extends State<DeviceListenPage> {
),
percentWidget(
status.memory_p(),
"Memory: ${status.memory_u()}",
"${lang.memory}: ${status.memory_u()}",
radius,
Colors.blue,
),
@ -389,13 +400,13 @@ class _DeviceListenPageState extends State<DeviceListenPage> { @@ -389,13 +400,13 @@ class _DeviceListenPageState extends State<DeviceListenPage> {
children: [
percentWidget(
status.swap_p(),
"Swap: ${status.memory_u()}",
"${lang.swap}: ${status.memory_u()}",
radius,
Colors.green,
),
percentWidget(
status.disk_p(),
"Disk: ${status.disk_u()}",
"${lang.disk}: ${status.disk_u()}",
radius,
Colors.purple,
),

2
lib/pages/setting/preference.dart

@ -45,7 +45,7 @@ class _PreferenceDetailState extends State<PreferenceDetail> { @@ -45,7 +45,7 @@ class _PreferenceDetailState extends State<PreferenceDetail> {
items: AppLocalizations.supportedLocales.map((Locale locale) {
return DropdownMenuItem<Locale>(
value: locale,
child: Text(locale.localizations(context),
child: Text(locale.localizations(),
style:
TextStyle(color: color.primary, fontSize: 16.0)),
);

12
lib/utils/mnemonic.dart

@ -7,11 +7,8 @@ import 'package:flutter/services.dart' show rootBundle; @@ -7,11 +7,8 @@ import 'package:flutter/services.dart' show rootBundle;
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
//import 'package:pointycastle/pointycastle.dart';
import 'package:unorm_dart/unorm_dart.dart';
import '../l10n/localizations.dart';
enum MnemonicLang {
CHINESE_SIMPLIFIED,
CHINESE_TRADITIONAL,
@ -29,15 +26,14 @@ final MNEMONIC_LANGS = [ @@ -29,15 +26,14 @@ final MNEMONIC_LANGS = [
];
extension MnemonicLangExtension on MnemonicLang {
String localizations(context) {
final lang = AppLocalizations.of(context);
String localizations() {
switch (this) {
case MnemonicLang.CHINESE_SIMPLIFIED:
return lang.langZh;
return '简体中文';
case MnemonicLang.ENGLISH:
return lang.langEn;
return 'English';
default:
return lang.langEn;
return 'English';
}
}

Loading…
Cancel
Save