opt.: l10n & fix: write script (#514)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-08-03 22:44:21 +08:00
committed by GitHub
parent 610f46da0d
commit 9db04a60c2
55 changed files with 686 additions and 2201 deletions

View File

@@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_highlight/theme_map.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:locale_names/locale_names.dart';
import 'package:server_box/core/extension/context/locale.dart';
import 'package:server_box/data/res/rebuild.dart';
import 'package:server_box/data/res/store.dart';
@@ -37,24 +36,19 @@ class _SettingPageState extends State<SettingPage> {
IconButton(
icon: const Icon(Icons.delete),
onPressed: () => context.showRoundDialog(
title: l10n.attention,
title: libL10n.attention,
child: SimpleMarkdown(
data: l10n.askContinue(
'${l10n.delete} **${l10n.all}** ${l10n.setting}',
data: libL10n.askContinue(
'${libL10n.delete} **${libL10n.all}** ${l10n.setting}',
)),
actions: [
TextButton(
onPressed: () {
context.pop();
_setting.box.deleteAll(_setting.box.keys);
context.showSnackBar(l10n.success);
},
child: Text(
l10n.ok,
style: const TextStyle(color: Colors.red),
),
),
],
actions: Btn.ok(
onTap: (c) {
context.pop();
_setting.box.deleteAll(_setting.box.keys);
context.showSnackBar(l10n.success);
},
red: true,
).toList,
),
),
],
@@ -62,22 +56,22 @@ class _SettingPageState extends State<SettingPage> {
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),
children: [
_buildTitle('App'),
const CenterGreyTitle('App'),
_buildApp(),
_buildTitle(l10n.server),
CenterGreyTitle(l10n.server),
_buildServer(),
_buildTitle(l10n.container),
CenterGreyTitle(l10n.container),
_buildContainer(),
_buildTitle('SSH'),
const CenterGreyTitle('SSH'),
_buildSSH(),
_buildTitle('SFTP'),
const CenterGreyTitle('SFTP'),
_buildSFTP(),
_buildTitle(l10n.editor),
CenterGreyTitle(l10n.editor),
_buildEditor(),
/// Fullscreen Mode is designed for old mobile phone which can be
/// used as a status screen.
if (isMobile) _buildTitle(l10n.fullScreen),
if (isMobile) CenterGreyTitle(l10n.fullScreen),
if (isMobile) _buildFullScreen(),
const SizedBox(height: 37),
],
@@ -85,18 +79,6 @@ class _SettingPageState extends State<SettingPage> {
);
}
Widget _buildTitle(String text) {
return Padding(
padding: const EdgeInsets.only(top: 23, bottom: 17),
child: Center(
child: Text(
text,
style: UIs.textGrey,
),
),
);
}
Widget _buildApp() {
final specific = _buildPlatformSetting();
final children = [
@@ -216,10 +198,6 @@ class _SettingPageState extends State<SettingPage> {
title: Text(
l10n.updateServerStatusInterval,
),
subtitle: Text(
l10n.willTakEeffectImmediately,
style: UIs.textGrey,
),
onTap: () async {
final val = await context.showPickSingleDialog(
title: l10n.setting,
@@ -284,12 +262,7 @@ class _SettingPageState extends State<SettingPage> {
children: children,
);
}),
actions: [
TextButton(
onPressed: () => _onSaveColor(ctrl.text),
child: Text(l10n.ok),
),
],
actions: Btn.ok(onTap: (c) => _onSaveColor(ctrl.text)).toList,
);
},
);
@@ -298,7 +271,7 @@ class _SettingPageState extends State<SettingPage> {
void _onSaveColor(String s) {
final color = s.hexToColor;
if (color == null) {
context.showSnackBar(l10n.failed);
context.showSnackBar(libL10n.fail);
return;
}
// Change [primaryColor] first, then change [_selectedColorValue],
@@ -354,13 +327,7 @@ class _SettingPageState extends State<SettingPage> {
return ValBuilder(
listenable: _setting.maxRetryCount.listenable(),
builder: (val) => ListTile(
title: Text(
l10n.maxRetryCount,
textAlign: TextAlign.start,
),
subtitle: Text(
val == 0 ? l10n.maxRetryCountEqual0 : l10n.canPullRefresh,
style: UIs.textGrey),
title: Text(l10n.maxRetryCount),
onTap: () async {
final selected = await context.showPickSingleDialog(
title: l10n.maxRetryCount,
@@ -411,9 +378,9 @@ class _SettingPageState extends State<SettingPage> {
String _buildThemeModeStr(int n) {
switch (n) {
case 1:
return l10n.light;
return libL10n.bright;
case 2:
return l10n.dark;
return libL10n.dark;
case 3:
return 'AMOLED';
case 4:
@@ -429,7 +396,7 @@ class _SettingPageState extends State<SettingPage> {
leading: const Icon(MingCute.font_fill),
title: Text(l10n.font),
trailing: Text(
fontName ?? l10n.notSelected,
fontName ?? libL10n.empty,
style: UIs.text15,
),
onTap: () {
@@ -438,7 +405,7 @@ class _SettingPageState extends State<SettingPage> {
actions: [
TextButton(
onPressed: () async => await _pickFontFile(),
child: Text(l10n.pickFile),
child: Text(libL10n.file),
),
TextButton(
onPressed: () {
@@ -446,7 +413,7 @@ class _SettingPageState extends State<SettingPage> {
context.pop();
RNodes.app.notify();
},
child: Text(l10n.clear),
child: Text(libL10n.clear),
)
],
);
@@ -536,7 +503,7 @@ class _SettingPageState extends State<SettingPage> {
final selected = await context.showPickSingleDialog(
title: l10n.language,
items: AppLocalizations.supportedLocales,
name: (p0) => '${p0.nativeDisplayLanguage} (${p0.code})',
name: (p0) => p0.nativeName,
initial: _setting.locale.fetch().toLocale,
);
if (selected != null) {
@@ -548,7 +515,7 @@ class _SettingPageState extends State<SettingPage> {
trailing: ListenBuilder(
listenable: _setting.locale.listenable(),
builder: () => Text(
l10n.languageName,
context.localeNativeName,
style: UIs.text15,
),
),
@@ -567,7 +534,7 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildEditorTheme() {
return ListTile(
leading: const Icon(MingCute.sun_fill),
title: Text('${l10n.light} ${l10n.theme.toLowerCase()}'),
title: Text('${libL10n.bright} ${l10n.theme.toLowerCase()}'),
trailing: ValBuilder(
listenable: _setting.editorTheme.listenable(),
builder: (val) => Text(val, style: UIs.text15),
@@ -589,7 +556,7 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildEditorDarkTheme() {
return ListTile(
leading: const Icon(MingCute.moon_stars_fill),
title: Text('${l10n.dark} ${l10n.theme.toLowerCase()}'),
title: Text('${libL10n.dark} ${l10n.theme.toLowerCase()}'),
trailing: ValBuilder(
listenable: _setting.editorDarkTheme.listenable(),
builder: (val) => Text(val, style: UIs.text15),
@@ -671,14 +638,6 @@ class _SettingPageState extends State<SettingPage> {
// );
// }
// Widget _buildCNKeyboardComp() {
// return ListTile(
// title: Text(l10n.cnKeyboardComp),
// subtitle: Text(l10n.cnKeyboardCompTip, style: UIs.textGrey),
// trailing: StoreSwitch(prop: _setting.cnKeyboardComp),
// );
// }
Widget _buildSSHVirtKeys() {
return ListTile(
leading: const Icon(BoxIcons.bxs_keyboard),
@@ -765,7 +724,7 @@ class _SettingPageState extends State<SettingPage> {
final md = deleteKeys.map((e) => '- $e').join('\n');
final sure = await context.showRoundDialog(
title: l10n.attention,
title: libL10n.attention,
child: SimpleMarkdown(data: md),
);
@@ -805,12 +764,7 @@ class _SettingPageState extends State<SettingPage> {
onSubmitted: _onSaveTextScaler,
suggestion: false,
),
actions: [
TextButton(
onPressed: () => _onSaveTextScaler(ctrl.text),
child: Text(l10n.ok),
),
],
actions: Btn.ok(onTap: (c) => _onSaveTextScaler(ctrl.text)).toList,
),
);
}
@@ -818,7 +772,7 @@ class _SettingPageState extends State<SettingPage> {
void _onSaveTextScaler(String s) {
final val = double.tryParse(s);
if (val == null) {
context.showSnackBar(l10n.failed);
context.showSnackBar(libL10n.fail);
return;
}
_setting.textFactor.put(val);
@@ -897,7 +851,7 @@ class _SettingPageState extends State<SettingPage> {
final fontSize = double.tryParse(ctrller.text);
if (fontSize == null) {
context.showRoundDialog(
title: l10n.failed,
title: libL10n.fail,
child: Text('Parsed failed: ${ctrller.text}'),
);
return;
@@ -915,20 +869,14 @@ class _SettingPageState extends State<SettingPage> {
suggestion: false,
onSubmitted: (_) => onSave(),
),
actions: [
TextButton(
onPressed: onSave,
child: Text(l10n.ok),
),
],
actions: Btn.ok(onTap: (c) => onSave()).toList,
);
}
Widget _buildSftpRmrDir() {
return ListTile(
leading: const Icon(MingCute.delete_2_fill),
title: const Text('rm -r'),
subtitle: Text(l10n.sftpRmrDirSummary, style: UIs.textGrey),
title: TipText(text: 'rm -r', tip: l10n.sftpRmrDirSummary),
trailing: StoreSwitch(prop: _setting.sftpRmrDir),
);
}
@@ -975,8 +923,7 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildCollapseUI() {
return ListTile(
title: Text(l10n.collapseUI),
subtitle: Text(l10n.collapseUITip, style: UIs.textGrey),
title: TipText(text: 'UI ${libL10n.fold}', tip: l10n.collapseUITip),
trailing: StoreSwitch(prop: _setting.collapseUIDefault),
);
}
@@ -1054,11 +1001,11 @@ class _SettingPageState extends State<SettingPage> {
case 0:
return l10n.system;
case 1:
return l10n.light;
return libL10n.bright;
case 2:
return l10n.dark;
return libL10n.dark;
default:
return l10n.error;
return libL10n.error;
}
}
@@ -1161,14 +1108,9 @@ class _SettingPageState extends State<SettingPage> {
void onSave(String url) {
if (url.isEmpty || !url.startsWith('http')) {
context.showRoundDialog(
title: l10n.failed,
title: libL10n.fail,
child: Text('${l10n.invalid} URL'),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.ok),
),
],
actions: Btn.ok(onTap: (c) => context.pop()).toList,
);
return;
}
@@ -1198,18 +1140,13 @@ class _SettingPageState extends State<SettingPage> {
onSubmitted: onSave,
),
ListTile(
title: Text(l10n.doc),
title: Text(libL10n.doc),
trailing: const Icon(Icons.open_in_new),
onTap: () => Urls.appWiki.launch(),
),
],
),
actions: [
TextButton(
onPressed: () => onSave(ctrl.text),
child: Text(l10n.ok),
),
],
actions: Btn.ok(onTap: (c) => onSave(ctrl.text)).toList,
);
},
);
@@ -1217,8 +1154,7 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildBeta() {
return ListTile(
title: const Text('Beta Program'),
subtitle: Text(l10n.acceptBeta, style: UIs.textGrey),
title: TipText(text: 'Beta Program', tip: l10n.acceptBeta),
trailing: StoreSwitch(prop: _setting.betaTest),
);
}
@@ -1258,7 +1194,7 @@ class _SettingPageState extends State<SettingPage> {
}
await context.showRoundDialog<bool>(
title: l10n.choose,
title: libL10n.select,
child: Input(
controller: ctrl,
autoFocus: true,

View File

@@ -15,9 +15,7 @@ class _AndroidSettingsPageState extends State<AndroidSettingsPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const CustomAppBar(
title: Text('Android'),
),
appBar: const CustomAppBar(title: Text('Android')),
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),
children: [

View File

@@ -21,9 +21,7 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const CustomAppBar(
title: Text('iOS'),
),
appBar: const CustomAppBar(title: Text('iOS')),
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),
children: [
@@ -45,22 +43,23 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
alignment: Alignment.centerRight,
padding: EdgeInsets.zero,
onPressed: () {
if (_pushToken.value != null) {
Pfs.copy(_pushToken.value!);
final val = _pushToken.value;
if (val != null) {
Pfs.copy(val);
context.showSnackBar(l10n.success);
} else {
context.showSnackBar(l10n.getPushTokenFailed);
context.showSnackBar(libL10n.fail);
}
},
),
subtitle: FutureWidget<String?>(
future: getToken(),
loading: Text(l10n.gettingToken),
error: (error, trace) => Text('${l10n.error}: $error'),
loading: const Text('...'),
error: (error, trace) => Text('${libL10n.error}: $error'),
success: (text) {
_pushToken.value = text;
return Text(
text ?? l10n.nullToken,
text ?? 'null',
style: UIs.textGrey,
overflow: TextOverflow.ellipsis,
maxLines: 1,
@@ -89,7 +88,7 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
Loggers.app.warning('WatchOS error', e, trace);
return ListTile(
title: const Text('Watch app'),
subtitle: Text('${l10n.error}: $e', style: UIs.textGrey),
subtitle: Text('${libL10n.error}: $e', style: UIs.textGrey),
);
},
success: (ctx) {

View File

@@ -9,16 +9,16 @@ abstract final class PlatformPublicSettings {
return FutureWidget<bool>(
future: BioAuth.isAvail,
loading: ListTile(
title: Text(l10n.bioAuth),
subtitle: Text(l10n.serverTabLoading, style: UIs.textGrey),
title: Text(libL10n.bioAuth),
subtitle: const Text('...', style: UIs.textGrey),
),
error: (e, __) => ListTile(
title: Text(l10n.bioAuth),
subtitle: Text('${l10n.failed}: $e', style: UIs.textGrey),
title: Text(libL10n.bioAuth),
subtitle: Text('${libL10n.fail}: $e', style: UIs.textGrey),
),
success: (can) {
return ListTile(
title: Text(l10n.bioAuth),
title: Text(libL10n.bioAuth),
subtitle: can == true
? null
: const Text(

View File

@@ -17,9 +17,7 @@ class _ServerDetailOrderPageState extends State<ServerDetailOrderPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(
title: Text(l10n.serverDetailOrder),
),
appBar: CustomAppBar(title: Text(l10n.serverDetailOrder)),
body: _buildBody(),
);
}
@@ -52,7 +50,7 @@ class _ServerDetailOrderPageState extends State<ServerDetailOrderPage> {
itemCount: allKeys.length,
onReorder: (o, n) {
if (o >= keys.length || n >= keys.length) {
context.showSnackBar(l10n.disabled);
context.showSnackBar(libL10n.disabled);
return;
}
keys.moveByItem(o, n, property: prop);

View File

@@ -17,9 +17,7 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(
title: Text(l10n.sequence),
),
appBar: CustomAppBar(title: Text(l10n.sequence)),
body: _buildBody(),
);
}
@@ -57,7 +55,7 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
itemCount: allKeys.length,
onReorder: (o, n) {
if (o >= keys.length || n >= keys.length) {
context.showSnackBar(l10n.disabled);
context.showSnackBar(libL10n.disabled);
return;
}
keys.moveByItem(o, n, property: prop);

View File

@@ -16,9 +16,7 @@ class _ServerOrderPageState extends State<ServerOrderPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(
title: Text(l10n.serverOrder),
),
appBar: CustomAppBar(title: Text(l10n.serverOrder)),
body: _buildBody(),
);
}
@@ -48,7 +46,7 @@ class _ServerOrderPageState extends State<ServerOrderPage> {
Widget _buildBody() {
if (Pros.server.serverOrder.isEmpty) {
return Center(child: Text(l10n.noServerAvailable));
return Center(child: Text(libL10n.empty));
}
return ReorderableListView.builder(
footer: const SizedBox(height: 77),

View File

@@ -17,9 +17,7 @@ class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(
title: Text(l10n.editVirtKeys),
),
appBar: CustomAppBar(title: Text(l10n.editVirtKeys)),
body: Column(
children: [
Padding(
@@ -67,7 +65,7 @@ class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {
itemCount: allKeys.length,
onReorder: (o, n) {
if (o >= keys.length || n >= keys.length) {
context.showSnackBar(l10n.disabled);
context.showSnackBar(libL10n.disabled);
return;
}
keys.moveByItem(o, n, property: prop);