feat: English and Chinese, and selectable chat text

- settings → general → language picks system, Chinese or English; the
  choice is stored on the device and read before the first frame
- our Chinese strings are translated through tr()/trArgs() and AppText,
  with the English in lib/l10n/en_*.dart; a missing entry falls back to
  Chinese and a test checks that every literal in lib has one
- AppText rebuilds on a language change (it depends on the resolved
  locale), so const text and whole pages switch at once; the built-in
  date/time pickers and selection menu follow the same language
- server and user data (titles, messages, prompts, paths) is never
  translated
- the chat list sits in a SelectionArea: long-press selects message text
  and shows the copy/select-all menu
- bump to 0.5.2
This commit is contained in:
blumia committed 2026-11-26 09:04:25 +08:00
1 parent da4bfb6826
commit 7b5bccf28f
42 files changed
+1943 -735

No files matched your search

+25 -24
View File
@@ -8,6 +8,7 @@ import 'package:flutter/services.dart';
import '../api/client.dart';
import '../api/shells.dart';
import '../l10n.dart';
/// One line of "正在执行 N 条命令", folding when there are many.
class ShellTaskBar extends StatefulWidget {
@@ -86,8 +87,8 @@ class _ShellTaskBarState extends State<ShellTaskBar> {
Icon(Icons.terminal, size: 15, color: theme.hintColor),
const SizedBox(width: 8),
Expanded(
child: Text(
'正在执行 $count 条命令',
child: AppText(
trArgs('正在执行 {0} 条命令', [count]),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -130,7 +131,7 @@ class _ShellTaskRow extends StatelessWidget {
Icon(Icons.terminal, size: 15, color: theme.hintColor),
const SizedBox(width: 8),
Expanded(
child: Text(
child: AppText(
task.command.replaceAll(RegExp(r'\s+'), ' ').trim(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
@@ -140,7 +141,7 @@ class _ShellTaskRow extends StatelessWidget {
),
if (subagent) ...[
const SizedBox(width: 6),
Text('子代理',
AppText('子代理',
style: TextStyle(
fontSize: 12,
color: theme.colorScheme.onSurfaceVariant,
@@ -194,7 +195,7 @@ class _ShellElapsedState extends State<ShellElapsed> {
if (widget.startedAt <= 0 || !widget.running) return const SizedBox.shrink();
final label =
formatElapsed(DateTime.now().millisecondsSinceEpoch - widget.startedAt);
return Text(
return AppText(
label,
style: TextStyle(
fontSize: 12,
@@ -337,7 +338,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
Icon(Icons.terminal, size: 18, color: theme.hintColor),
const SizedBox(width: 10),
Expanded(
child: Text(
child: AppText(
widget.task.command,
maxLines: 2,
overflow: TextOverflow.ellipsis,
@@ -361,7 +362,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
Icon(Icons.check_circle_outline,
size: 15, color: theme.hintColor),
const SizedBox(width: 6),
Text('已结束',
AppText('已结束',
style:
TextStyle(fontSize: 12, color: theme.hintColor)),
],
@@ -370,7 +371,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
TextButton.icon(
onPressed: _stopping ? null : _stop,
icon: const Icon(Icons.stop_rounded, size: 17),
label: Text(_stopping ? '停止中…' : '停止'),
label: AppText(_stopping ? '停止中…' : '停止'),
style: TextButton.styleFrom(
foregroundColor: theme.colorScheme.error,
minimumSize: const Size(0, 32),
@@ -380,7 +381,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
TextButton.icon(
onPressed: _text.isEmpty ? null : _copy,
icon: const Icon(Icons.copy, size: 15),
label: const Text('复制'),
label: const AppText('复制'),
style: TextButton.styleFrom(
minimumSize: const Size(0, 32),
padding: const EdgeInsets.symmetric(horizontal: 10),
@@ -408,7 +409,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
),
const SizedBox(height: 10),
],
Text(
AppText(
_feed.error ??
(!_feed.loaded
? '读取输出…'
@@ -446,7 +447,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
_onFeed();
},
icon: const Icon(Icons.arrow_downward, size: 15),
label: const Text('回到最新'),
label: const AppText('回到最新'),
style: FilledButton.styleFrom(
visualDensity: VisualDensity.compact,
),
@@ -464,7 +465,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
await Clipboard.setData(ClipboardData(text: _text));
if (mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('已复制输出')));
.showSnackBar(const SnackBar(content: AppText('已复制输出')));
}
}
}
@@ -541,15 +542,15 @@ class _ShellOutputInlineState extends State<ShellOutputInline> {
children: [
Icon(Icons.terminal, size: 15, color: theme.hintColor),
const SizedBox(width: 8),
Text('后台输出',
AppText('后台输出',
style: TextStyle(fontSize: 12, color: theme.hintColor)),
const SizedBox(width: 8),
if (!ended)
Text('运行中',
AppText('运行中',
style: TextStyle(
fontSize: 12, color: theme.colorScheme.primary)),
if (ended && text.isEmpty)
Text('已结束',
AppText('已结束',
style:
TextStyle(fontSize: 12, color: theme.hintColor)),
const Spacer(),
@@ -562,7 +563,7 @@ class _ShellOutputInlineState extends State<ShellOutputInline> {
padding: const EdgeInsets.symmetric(horizontal: 8),
textStyle: const TextStyle(fontSize: 12.5),
),
child: const Text('停止'),
child: const AppText('停止'),
),
TextButton(
onPressed: widget.onOpen,
@@ -571,14 +572,14 @@ class _ShellOutputInlineState extends State<ShellOutputInline> {
padding: const EdgeInsets.symmetric(horizontal: 8),
textStyle: const TextStyle(fontSize: 12.5),
),
child: const Text('查看全部'),
child: const AppText('查看全部'),
),
],
),
if (tail.isEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Text(
child: AppText(
_feed.error ?? (ended ? '没有输出' : '等待输出…'),
style: TextStyle(fontSize: 12, color: theme.hintColor)),
)
@@ -614,8 +615,8 @@ Future<bool?> confirmStopShell(BuildContext context, String command) {
return showDialog<bool>(
context: context,
builder: (dialog) => AlertDialog(
title: const Text('停止这个任务?'),
content: Text(
title: const AppText('停止这个任务?'),
content: AppText(
command,
maxLines: 4,
overflow: TextOverflow.ellipsis,
@@ -624,14 +625,14 @@ Future<bool?> confirmStopShell(BuildContext context, String command) {
actions: [
TextButton(
onPressed: () => Navigator.pop(dialog, false),
child: const Text('取消')),
child: const AppText('取消')),
FilledButton(
style: FilledButton.styleFrom(
backgroundColor: Theme.of(dialog).colorScheme.error,
foregroundColor: Theme.of(dialog).colorScheme.onError,
),
onPressed: () => Navigator.pop(dialog, true),
child: const Text('停止'),
child: const AppText('停止'),
),
],
),
@@ -727,11 +728,11 @@ class ShellOutputFeed {
_timer?.cancel();
_timer = null;
} else {
error = '读取输出失败:${e.message}';
error = trArgs('读取输出失败:{0}', [e.message]);
}
_onUpdate?.call();
} catch (e) {
error = '读取输出失败:$e';
error = trArgs('读取输出失败:{0}', ['$e']);
_onUpdate?.call();
} finally {
_busy = false;