feat: write the UI in English, select only conversation content

- source strings are English again; Chinese comes from lib/l10n/zh.dart
  through tr()/trArgs() and AppText, and a language without a table
  (Spanish, ...) reads English instead of Chinese
- server and user data (titles, messages, file names, notes, task names)
  is drawn with plain Text, so it is never looked up in the table
- SelectionArea moved from the whole message list to the messages, the
  answer text, an opened tool call's details and the turn footer; status
  lines and folded tool rows no longer start a selection
- a message the transcript does not know (its start event was lost while
  the stream was down) fetches the tail once, so a turn continued from
  another client comes in with its prompt
- bump to 0.5.3
This commit is contained in:
blumia committed 2026-11-26 11:48:16 +08:00
1 parent 7b5bccf28f
commit 511c3b006b
43 files changed
+1620 -1791

No files matched your search

+167 -156
View File
@@ -203,7 +203,7 @@ class _ChatScreenState extends State<ChatScreen> {
/// What a finished command's output reads as: the report, or that the user
/// stopped it (the report itself is a `Shell.NotFoundError` then).
String _completionText(String shellId, ShellCompletionNote completion) =>
shellWasStopped(chat.msgs, shellId) ? tr('用户停止了这条命令。') : completion.output;
shellWasStopped(chat.msgs, shellId) ? tr('You stopped this command.') : completion.output;
Future<void> _stopShell(ShellTask task) async {
final shells = _shells;
@@ -213,7 +213,7 @@ class _ChatScreenState extends State<ChatScreen> {
} on ApiError catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: AppText(trArgs('停止失败:{0}', [e.message]))));
.showSnackBar(SnackBar(content: AppText(trArgs('Could not stop: {0}', [e.message]))));
}
}
@@ -258,8 +258,8 @@ class _ChatScreenState extends State<ChatScreen> {
Expanded(
child: AppText(
operator
? '此会话由 Lead 管理,接管后才能继续。'
: '无法向子智能体会话发送提示。',
? 'This session is managed by a Lead; take it over to continue.'
: 'Cannot send prompts to a subagent session.',
style: TextStyle(
fontSize: 12.5, color: scheme.onSurfaceVariant),
),
@@ -290,14 +290,14 @@ class _ChatScreenState extends State<ChatScreen> {
leading: parent != null
? IconButton(
icon: const Icon(Icons.arrow_back),
tooltip: tr('返回父会话'),
tooltip: tr('Back to parent session'),
onPressed: () => widget.app.openChat(parent),
)
: widget.onOpenSessions == null
? null
: IconButton(
icon: const Icon(Icons.menu),
tooltip: tr('会话'),
tooltip: tr('Sessions'),
onPressed: widget.onOpenSessions,
),
title: Row(
@@ -308,7 +308,7 @@ class _ChatScreenState extends State<ChatScreen> {
const SizedBox(width: 6),
],
Expanded(
child: AppText(_title(),
child: Text(_title(),
maxLines: 1, overflow: TextOverflow.ellipsis),
),
],
@@ -316,7 +316,7 @@ class _ChatScreenState extends State<ChatScreen> {
actions: [
IconButton(
icon: const Icon(Icons.view_sidebar_outlined),
tooltip: tr('文件'),
tooltip: tr('Files'),
onPressed: () => showFilesPanel(context, widget.app, chat.dir),
),
],
@@ -330,10 +330,10 @@ class _ChatScreenState extends State<ChatScreen> {
child: Row(
children: [
Expanded(
child: AppText(chat.error!,
child: Text(chat.error!,
style: TextStyle(
color: theme.colorScheme.onErrorContainer, fontSize: 13))),
TextButton(onPressed: chat.load, child: const AppText('重试')),
TextButton(onPressed: chat.load, child: const AppText('Retry')),
],
),
),
@@ -372,36 +372,35 @@ class _ChatScreenState extends State<ChatScreen> {
}
final rows = _rows();
final olderSlot = chat.hasMore || chat.loadingOlder ? 1 : 0;
// Long-press selects the conversation's text: the rendered Markdown used
// to be plain text, so only the few SelectableText widgets could be
// selected. The selection toolbar follows the UI language.
return SelectionArea(
child: ListView.builder(
controller: _scroll,
reverse: true,
itemCount: rows.length + olderSlot,
itemBuilder: (context, i) {
// i counts from the newest row up.
if (i < rows.length) return _row(rows[rows.length - 1 - i]);
if (chat.loadingOlder) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 12),
child: Center(
child: SizedBox(
width: 22,
height: 22,
child: CircularProgressIndicator(strokeWidth: 2)),
),
);
}
return Center(
child: TextButton(
onPressed: _loadOlder,
child: const AppText('载入更早的消息'),
// Only the conversation itself is selectable: each message bubble, the
// answer text, an opened tool call's details and the turn's model line.
// Status lines and folded tool rows stay plain, so a long-press there does
// not start a selection.
return ListView.builder(
controller: _scroll,
reverse: true,
itemCount: rows.length + olderSlot,
itemBuilder: (context, i) {
// i counts from the newest row up.
if (i < rows.length) return _row(rows[rows.length - 1 - i]);
if (chat.loadingOlder) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 12),
child: Center(
child: SizedBox(
width: 22,
height: 22,
child: CircularProgressIndicator(strokeWidth: 2)),
),
);
},
),
}
return Center(
child: TextButton(
onPressed: _loadOlder,
child: const AppText('Load earlier messages'),
),
);
},
);
}
@@ -599,7 +598,7 @@ class _ChatScreenState extends State<ChatScreen> {
case 'thinking':
return const Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
child: AppText('正在思考…', style: TextStyle(color: Colors.grey, fontSize: 13)),
child: AppText('Thinking…', style: TextStyle(color: Colors.grey, fontSize: 13)),
);
case 'text':
return _textRow(r.msgId, r.part);
@@ -618,7 +617,7 @@ class _ChatScreenState extends State<ChatScreen> {
case 'shell':
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: AppText(chat.byId[r.msgId]?.text ?? '',
child: Text(chat.byId[r.msgId]?.text ?? '',
style: const TextStyle(color: Colors.grey, fontSize: 13)),
);
default:
@@ -634,7 +633,7 @@ class _ChatScreenState extends State<ChatScreen> {
return session.title;
}
}
return widget.session.title.isEmpty ? '会话' : widget.session.title;
return widget.session.title.isEmpty ? 'Sessions' : widget.session.title;
}
/// A prompt in the server's inbox: dimmer than a sent message, with the
@@ -663,12 +662,14 @@ class _ChatScreenState extends State<ChatScreen> {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (item.text.isNotEmpty)
AppText(item.text,
style: TextStyle(color: scheme.onPrimary)),
SelectionArea(
child: Text(item.text,
style: TextStyle(color: scheme.onPrimary)),
),
if (item.files.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 4),
child: AppText(trArgs('📎 {0} 个附件', [item.files.length]),
child: AppText(trArgs('📎 {0} attachments', [item.files.length]),
style: TextStyle(
color: scheme.onPrimary, fontSize: 12.5)),
),
@@ -686,17 +687,17 @@ class _ChatScreenState extends State<ChatScreen> {
const SizedBox(width: 3),
AppText(
!chat.running
? '未发送'
? 'Not sent'
: steering
? '正在转入当前回合…'
: '已排队,本轮结束后发送',
? 'Joining this turn…'
: 'Queued; sends after this turn',
style: TextStyle(fontSize: 12, color: theme.hintColor),
),
const SizedBox(width: 4),
TextButton(
onPressed: () => chat.changeInboxDelivery(
item.id, steering ? 'queue' : 'steer'),
child: AppText(steering ? '改为排队' : '转为转向',
child: AppText(steering ? 'Queue instead' : 'Steer instead',
style: const TextStyle(fontSize: 12.5)),
),
TextButton(
@@ -708,7 +709,7 @@ class _ChatScreenState extends State<ChatScreen> {
offset: _draftCtrl.text.length);
_inputFocus.requestFocus();
},
child: const AppText('撤回',
child: const AppText('Withdraw',
style: TextStyle(fontSize: 12.5)),
),
],
@@ -743,7 +744,10 @@ class _ChatScreenState extends State<ChatScreen> {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (m.text.isNotEmpty)
AppText(m.text, style: TextStyle(color: theme.colorScheme.onPrimary)),
SelectionArea(
child: Text(m.text,
style: TextStyle(color: theme.colorScheme.onPrimary)),
),
for (final i in attachedImages)
Padding(
padding: const EdgeInsets.only(top: 6),
@@ -776,7 +780,7 @@ class _ChatScreenState extends State<ChatScreen> {
color: theme.colorScheme.onPrimary.withValues(alpha: 0.14),
borderRadius: BorderRadius.circular(8),
),
child: AppText('📎 ${f.name.isEmpty ? tr('附件') : f.name}',
child: AppText('📎 ${f.name.isEmpty ? tr('Attachments') : f.name}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -798,7 +802,7 @@ class _ChatScreenState extends State<ChatScreen> {
_userImages[key] = bytes;
} catch (_) {
return const SizedBox(
width: 200, height: 60, child: Center(child: AppText('图片无法显示')));
width: 200, height: 60, child: Center(child: AppText('Cannot display image')));
}
}
return Image.memory(bytes, width: 200, height: 150, fit: BoxFit.cover);
@@ -806,7 +810,7 @@ class _ChatScreenState extends State<ChatScreen> {
void _previewAttachment(FileAttachment f) {
_showImageDialog(
f.name.isEmpty ? '图片' : f.name,
f.name.isEmpty ? 'Image' : f.name,
source: 'data:${f.mime};base64,${f.data}',
);
}
@@ -823,18 +827,18 @@ class _ChatScreenState extends State<ChatScreen> {
if (stamp.isNotEmpty)
Padding(
padding: const EdgeInsets.only(right: 8),
child: AppText(stamp, style: const TextStyle(color: Colors.grey, fontSize: 12)),
child: Text(stamp, style: const TextStyle(color: Colors.grey, fontSize: 12)),
),
TextButton(
onPressed: () => _copyText(m.text),
child: const AppText('复制'),
child: const AppText('Copy'),
),
PopupMenuButton<String>(
onSelected: (v) => _userAction(v, m),
itemBuilder: (_) => const [
PopupMenuItem(value: 'copy', child: AppText('复制消息')),
PopupMenuItem(value: 'revert', child: AppText('撤回此消息及之后')),
PopupMenuItem(value: 'fork', child: AppText('从这里分叉')),
PopupMenuItem(value: 'copy', child: AppText('Copy message')),
PopupMenuItem(value: 'revert', child: AppText('Withdraw this and later messages')),
PopupMenuItem(value: 'fork', child: AppText('Fork from here')),
],
),
],
@@ -848,9 +852,9 @@ class _ChatScreenState extends State<ChatScreen> {
break;
case 'revert':
_confirm(
title: '撤回消息?',
message: '这条消息及其之后的内容会从会话中删除,且无法恢复。',
confirm: '撤回',
title: 'Withdraw message?',
message: 'This message and everything after it will be removed from the session and cannot be recovered.',
confirm: 'Withdraw',
onConfirm: () => chat.revert(m.id),
);
break;
@@ -865,7 +869,7 @@ class _ChatScreenState extends State<ChatScreen> {
if (part < 0 || part >= m.content.length) return const SizedBox.shrink();
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
child: MarkdownView(m.content[part].text),
child: SelectionArea(child: MarkdownView(m.content[part].text)),
);
}
@@ -939,12 +943,12 @@ class _ChatScreenState extends State<ChatScreen> {
final theme = Theme.of(context);
final tools = steps.where((s) => s.part.type == 'tool').length;
final label = tools == 0
? (running ? '思考中…' : '思考过程')
? (running ? 'Thinking…' : 'Thought process')
: failed
? trArgs('有步骤失败 · {0} 次工具调用', [tools])
? trArgs('A step failed · {0} tool calls', [tools])
: running
? trArgs('执行中 · {0} 次工具调用', [tools])
: trArgs('已完成 · {0} 次工具调用', [tools]);
? trArgs('Running · {0} tool calls', [tools])
: trArgs('Done · {0} tool calls', [tools]);
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _toggleGroup(id, start, collapsed),
@@ -963,7 +967,7 @@ class _ChatScreenState extends State<ChatScreen> {
color: failed ? theme.colorScheme.error : theme.hintColor),
const SizedBox(width: 8),
Expanded(
child: AppText(label,
child: Text(label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 13, color: theme.hintColor)),
@@ -1054,7 +1058,7 @@ class _ChatScreenState extends State<ChatScreen> {
: theme.colorScheme.onSurfaceVariant),
),
const SizedBox(width: 10),
AppText(label,
Text(label,
style: TextStyle(
fontSize: 13.5, color: theme.colorScheme.onSurface)),
if (summary.isEmpty)
@@ -1064,7 +1068,7 @@ class _ChatScreenState extends State<ChatScreen> {
AppText('·', style: TextStyle(fontSize: 13, color: theme.hintColor)),
const SizedBox(width: 6),
Expanded(
child: AppText(summary,
child: Text(summary,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -1093,7 +1097,7 @@ class _ChatScreenState extends State<ChatScreen> {
.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(6),
),
child: AppText('后台',
child: AppText('Background',
style: TextStyle(
fontSize: 11,
color: theme.colorScheme.primary)),
@@ -1122,7 +1126,7 @@ class _ChatScreenState extends State<ChatScreen> {
const AppText('🖼', style: TextStyle(fontSize: 12)),
const SizedBox(width: 6),
Flexible(
child: AppText(ref.label,
child: Text(ref.label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -1136,7 +1140,12 @@ class _ChatScreenState extends State<ChatScreen> {
_Reveal(
open: open,
onGrow: _grow,
child: _stepDetails(p, reasoning, diffFiles, shellId, m.created),
// An opened call shows its command, arguments and output; those
// are conversation text like the answer is.
child: SelectionArea(
child:
_stepDetails(p, reasoning, diffFiles, shellId, m.created),
),
),
],
),
@@ -1181,7 +1190,7 @@ class _ChatScreenState extends State<ChatScreen> {
final ok = await widget.app.openSubagent(id);
if (ok || !mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: AppText(widget.app.lastError ?? '无法打开子代理会话')),
SnackBar(content: AppText(widget.app.lastError ?? 'Cannot open the subagent session')),
);
widget.app.clearLastError();
}
@@ -1294,23 +1303,23 @@ class _ChatScreenState extends State<ChatScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (command.isNotEmpty)
SelectableText(command,
Text(command,
style: mono.copyWith(color: theme.colorScheme.onSurface)),
if (command.isNotEmpty) const SizedBox(height: 6),
for (final e in extras)
Padding(
padding: const EdgeInsets.only(bottom: 2),
child: AppText('${e.key}: ${e.value}',
child: Text('${e.key}: ${e.value}',
style: mono.copyWith(
fontSize: 11.5, color: theme.hintColor)),
),
if (extras.isNotEmpty) const SizedBox(height: 4),
SelectableText(
Text(
output.isNotEmpty
? output
: shelled
? tr('输出较大,正在载入…')
: (shell ? tr('无输出') : tr('无内容')),
? tr('Large output, loading…')
: (shell ? tr('No output') : tr('No content')),
style: mono.copyWith(
color: p.state?.error != null
? theme.colorScheme.error
@@ -1405,41 +1414,41 @@ class _ChatScreenState extends State<ChatScreen> {
}
static String _stepLabel(ContentPart p) {
if (p.type == 'reasoning') return tr('思考');
if (p.type == 'reasoning') return tr('Thinking');
switch (p.name ?? '') {
case 'bash':
case 'shell':
case 'execute':
return tr('运行');
return tr('Run');
case 'read':
return tr('读取');
return tr('Read');
case 'write':
return tr('写入');
return tr('Write');
case 'edit':
return tr('编辑');
return tr('Edit');
case 'patch':
case 'apply_patch':
return tr('补丁');
return tr('Patch');
case 'grep':
case 'glob':
case 'find':
return tr('搜索');
return tr('Search');
case 'list':
return tr('列出');
return tr('List');
case 'webfetch':
case 'web_fetch':
return tr('抓取');
return tr('Fetch');
case 'todowrite':
return tr('任务');
return tr('Task');
case 'task':
case 'subagent':
return tr('子代理');
return tr('Subagent');
case 'skill':
return tr('技能');
return tr('Skill');
case 'openchamber_image':
return tr('生成图片');
return tr('Generate image');
default:
return p.name == null || p.name!.isEmpty ? tr('工具') : p.name!;
return p.name == null || p.name!.isEmpty ? tr('Tool') : p.name!;
}
}
@@ -1505,17 +1514,19 @@ class _ChatScreenState extends State<ChatScreen> {
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: AppText(parts.join(' · '),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Colors.grey, fontSize: 13)),
child: SelectionArea(
child: Text(parts.join(' · '),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Colors.grey, fontSize: 13)),
),
),
),
PopupMenuButton<String>(
onSelected: (v) => _footerAction(v, m),
itemBuilder: (_) => const [
PopupMenuItem(value: 'copy', child: AppText('复制回答')),
PopupMenuItem(value: 'fork', child: AppText('从这里分叉')),
PopupMenuItem(value: 'copy', child: AppText('Copy answer')),
PopupMenuItem(value: 'fork', child: AppText('Fork from here')),
],
),
],
@@ -1548,27 +1559,27 @@ class _ChatScreenState extends State<ChatScreen> {
final e = m.error;
final detail = (e != null && e.message.isNotEmpty)
? e.message
: (e != null && e.type.isNotEmpty ? e.type : tr('未知错误'));
: (e != null && e.type.isNotEmpty ? e.type : tr('Unknown error'));
final type = (e?.type ?? '').toLowerCase();
final plain = detail.trim().toLowerCase().replaceFirst(RegExp(r'\.$'), '');
if (m.type == 'compaction') {
return (text: trArgs('压缩失败:{0}', [detail]), body: e?.body);
return (text: trArgs('Compaction failed: {0}', [detail]), body: e?.body);
}
if (type == 'sessionretry') {
return (text: trArgs('OpenCode 发送消息失败,正在重试:{0}', [detail]), body: e?.body);
return (text: trArgs('OpenCode could not send the message; retrying: {0}', [detail]), body: e?.body);
}
if (_isAuthError(detail)) {
return (
text: tr('模型的认证失败,请在服务端重新登录或检查 API Key。'),
text: tr('The model failed to authenticate. Sign in again on the server or check the API key.'),
body: e?.body
);
}
if (type == 'messageabortederror' ||
plain == 'aborted' ||
plain == 'step interrupted') {
return (text: tr('本轮已停止。'), body: null);
return (text: tr('This turn was stopped.'), body: null);
}
return (text: trArgs('OpenCode 发送消息失败:{0}', [detail]), body: e?.body);
return (text: trArgs('OpenCode could not send the message: {0}', [detail]), body: e?.body);
}
static String _prettyBody(String raw) {
@@ -1589,7 +1600,7 @@ class _ChatScreenState extends State<ChatScreen> {
final running = m.status == 'running';
final summary = m.summary.trim();
final open = chat.expanded.contains('compaction/$id');
final label = running ? '正在压缩对话' : '对话已压缩';
final label = running ? 'Compacting conversation' : 'Conversation compacted';
final header = GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => setState(() {
@@ -1615,7 +1626,7 @@ class _ChatScreenState extends State<ChatScreen> {
style: TextStyle(fontSize: 13, color: theme.hintColor)),
),
if (summary.isNotEmpty)
AppText(open ? '隐藏摘要' : '显示摘要',
AppText(open ? 'Hide summary' : 'Show summary',
style: TextStyle(fontSize: 12, color: scheme.primary)),
const SizedBox(width: 4),
AnimatedRotation(
@@ -1644,7 +1655,7 @@ class _ChatScreenState extends State<ChatScreen> {
borderRadius: BorderRadius.circular(8),
),
child: summary.isEmpty
? AppText(running ? '正在生成摘要…' : '(摘要为空)',
? AppText(running ? 'Generating summary…' : '(No summary)',
style: TextStyle(fontSize: 13, color: theme.hintColor))
: MarkdownView(summary, fontSize: 14),
),
@@ -1702,7 +1713,7 @@ class _ChatScreenState extends State<ChatScreen> {
onPressed: () => setState(() {
open ? chat.expanded.remove(key) : chat.expanded.add(key);
}),
child: AppText(open ? '收起详情' : '显示详情',
child: AppText(open ? 'Hide details' : 'Show details',
style: const TextStyle(fontSize: 12.5)),
),
),
@@ -1739,7 +1750,7 @@ class _ChatScreenState extends State<ChatScreen> {
/// last turn, then idle.
String _petState() {
if (chat.running) {
return _activity().title == '思考中' ? 'thinking' : 'working';
return _activity().title == 'Thinking' ? 'thinking' : 'working';
}
for (var i = chat.msgs.length - 1; i >= 0; i--) {
final m = chat.msgs[i];
@@ -1760,7 +1771,7 @@ class _ChatScreenState extends State<ChatScreen> {
final st = part.state?.status ?? '';
if (part.type == 'tool' &&
(st == 'running' || st == 'streaming' || st == 'pending')) {
return (title: trArgs('正在{0}', [_stepLabel(part)]), detail: _stepSummary(part));
return (title: trArgs('{0} in progress', [_stepLabel(part)]), detail: _stepSummary(part));
}
}
if (m.completed == 0) {
@@ -1769,12 +1780,12 @@ class _ChatScreenState extends State<ChatScreen> {
m.content.any((p) => p.type == 'text' && p.text.trim().isNotEmpty);
final reasoning = m.content
.any((p) => p.type == 'reasoning' && p.text.trim().isNotEmpty);
if (text) return (title: '正在回复', detail: '');
if (reasoning) return (title: '思考中', detail: '');
if (text) return (title: 'Replying', detail: '');
if (reasoning) return (title: 'Thinking', detail: '');
}
break;
}
return (title: '思考中', detail: '');
return (title: 'Thinking', detail: '');
}
/// The running turn started with the newest user message.
@@ -1882,7 +1893,7 @@ class _ChatScreenState extends State<ChatScreen> {
if (start <= 0) return '';
final secs = ((m.completed - start) / 1000).round();
if (secs <= 0) return '';
if (secs < 60) return trArgs('{0} 秒', [secs]);
if (secs < 60) return trArgs('{0}s', [secs]);
return '${secs ~/ 60}:${(secs % 60).toString().padLeft(2, '0')}';
}
@@ -1899,12 +1910,12 @@ class _ChatScreenState extends State<ChatScreen> {
Future<void> _copyText(String text) async {
if (text.trim().isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: AppText('没有可复制的文字')));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: AppText('Nothing to copy')));
return;
}
await Clipboard.setData(ClipboardData(text: text));
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: AppText('已复制')));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: AppText('Copied')));
}
}
@@ -2002,7 +2013,7 @@ class _ChatScreenState extends State<ChatScreen> {
ComposerBox(
controller: _draftCtrl,
focusNode: _inputFocus,
hint: chat.running ? tr('生成中,仍可输入…') : tr('发消息…'),
hint: chat.running ? tr('Generating; you can still type…') : tr('Send a message…'),
maxLines: 5,
keyboardInset: keyboardInset,
// While the palette is up, the keyboard's action key picks the
@@ -2039,7 +2050,7 @@ class _ChatScreenState extends State<ChatScreen> {
},
leading: _roundKey(
icon: Icons.attach_file,
label: tr('添加附件'),
label: tr('Add attachment'),
onTap: _pickFiles,
busy: _attaching,
),
@@ -2080,7 +2091,7 @@ class _ChatScreenState extends State<ChatScreen> {
// something to send the key sends again, as dsh-Go's does.
trailing: _roundKey(
icon: showStop ? Icons.stop_rounded : Icons.arrow_upward_rounded,
label: showStop ? tr('停止') : tr('发送'),
label: showStop ? tr('Stop') : tr('Send'),
filled: true,
enabled: showStop || canSend,
onTap: showStop ? chat.stop : _send,
@@ -2188,13 +2199,13 @@ class _ChatScreenState extends State<ChatScreen> {
children: [
const Padding(
padding: EdgeInsets.fromLTRB(20, 4, 20, 8),
child: AppText('发送方式',
child: AppText('Delivery',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
),
ListTile(
leading: const Icon(Icons.alt_route),
title: const AppText('转向当前回合'),
subtitle: const AppText('在下一步加入,工作继续'),
title: const AppText('Steer into this turn'),
subtitle: const AppText('Join at the next step; work continues'),
trailing: fallback == 'steer'
? Icon(Icons.check, size: 20, color: scheme.primary)
: null,
@@ -2202,8 +2213,8 @@ class _ChatScreenState extends State<ChatScreen> {
),
ListTile(
leading: const Icon(Icons.schedule),
title: const AppText('排队'),
subtitle: const AppText('等本轮结束后发送'),
title: const AppText('Queue'),
subtitle: const AppText('Send after this turn ends'),
trailing: fallback == 'queue'
? Icon(Icons.check, size: 20, color: scheme.primary)
: null,
@@ -2263,7 +2274,7 @@ class _ChatScreenState extends State<ChatScreen> {
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: AppText(trArgs('选择失败:{0}', ['$e']))));
.showSnackBar(SnackBar(content: AppText(trArgs('Could not attach: {0}', ['$e']))));
}
} finally {
if (mounted) setState(() => _attaching = false);
@@ -2296,22 +2307,22 @@ class _ChatScreenState extends State<ChatScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(trArgs('请求权限: {0}', [p.action]),
AppText(trArgs('Permission requested: {0}', [p.action]),
style: const TextStyle(fontWeight: FontWeight.w600)),
AppText(p.resources.join(tr('、')),
Text(p.resources.join(', '),
style: const TextStyle(color: Colors.grey, fontSize: 13)),
const SizedBox(height: 6),
Row(
children: [
TextButton(
onPressed: () => chat.replyPermission(p.id, 'once'),
child: const AppText('允许一次')),
child: const AppText('Allow once')),
TextButton(
onPressed: () => chat.replyPermission(p.id, 'always'),
child: const AppText('总是允许')),
child: const AppText('Always allow')),
TextButton(
onPressed: () => chat.replyPermission(p.id, 'reject'),
child: const AppText('拒绝')),
child: const AppText('Deny')),
],
),
],
@@ -2331,7 +2342,7 @@ class _ChatScreenState extends State<ChatScreen> {
title: AppText(title),
content: AppText(message),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const AppText('取消')),
TextButton(onPressed: () => Navigator.pop(context), child: const AppText('Cancel')),
FilledButton(
onPressed: () {
Navigator.pop(context);
@@ -2373,18 +2384,18 @@ class _ChatScreenState extends State<ChatScreen> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const AppText('上下文占用', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const AppText('Context usage', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_usageRow('模型', widget.app.modelName(chat.selectedModel ?? _lastModel())),
_usageRow('已用 tokens', _fmtTokens(r.$1)),
_usageRow('Model', widget.app.modelName(chat.selectedModel ?? _lastModel())),
_usageRow('Tokens used', _fmtTokens(r.$1)),
if (r.$5) ...[
_usageRow('上下文上限', _fmtTokens(r.$2)),
_usageRow('输出预留', _fmtTokens(r.$3)),
_usageRow('占用', '${r.$4.toStringAsFixed(1)}%'),
_usageRow('Context limit', _fmtTokens(r.$2)),
_usageRow('Reserved output', _fmtTokens(r.$3)),
_usageRow('Usage', '${r.$4.toStringAsFixed(1)}%'),
],
if (chat.turnCost > 0) _usageRow('本轮费用', '\$${chat.turnCost.toStringAsFixed(4)}'),
if (chat.turnCost > 0) _usageRow('Turn cost', '\$${chat.turnCost.toStringAsFixed(4)}'),
const SizedBox(height: 8),
const AppText('输出预留按最多 32K tokens 计算,与官方客户端一致。',
const AppText('Reserved output assumes at most 32K tokens, matching the official client.',
style: TextStyle(color: Colors.grey, fontSize: 12)),
],
),
@@ -2404,7 +2415,7 @@ class _ChatScreenState extends State<ChatScreen> {
child: Row(
children: [
Expanded(child: AppText(label, style: const TextStyle(color: Colors.grey))),
AppText(value),
Text(value),
],
),
);
@@ -2560,7 +2571,7 @@ List<_ImageRef> toolImages(ContentPart p, String dir) {
}
if (labels.contains(label)) return;
}
if (label.isEmpty) label = '图片';
if (label.isEmpty) label = 'Image';
seen.add(source);
labels.add(label);
out.add(_ImageRef(source, label));
@@ -2615,9 +2626,9 @@ Future<Uint8List> _imageBytesFor(
Client client, String source, String directory) async {
if (source.startsWith('data:')) {
final comma = source.indexOf(',');
if (comma < 0) throw Exception(tr('无效的 data URL'));
if (comma < 0) throw Exception(tr('Invalid data URL'));
final meta = source.substring(5, comma);
if (!meta.contains('base64')) throw Exception(tr('不支持的 data URL'));
if (!meta.contains('base64')) throw Exception(tr('Unsupported data URL'));
return base64Decode(source.substring(comma + 1));
}
final cached = _imageBytes[source];
@@ -2685,7 +2696,7 @@ class _GeneratedImageState extends State<_GeneratedImage> {
const SizedBox(width: 8),
Expanded(
child: AppText(
trArgs('图片加载失败:{0}', [pathLeaf(widget.source)]),
trArgs('Could not load image: {0}', [pathLeaf(widget.source)]),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12, color: theme.hintColor),
@@ -2798,7 +2809,7 @@ class _ImagePreviewDialogState extends State<_ImagePreviewDialog> {
} else {
body = Padding(
padding: const EdgeInsets.all(24),
child: SelectableText(trArgs('无法预览:{0}', ['$_error']),
child: SelectableText(trArgs('Cannot preview: {0}', ['$_error']),
style: TextStyle(color: theme.colorScheme.error)),
);
}
@@ -2815,12 +2826,12 @@ class _ImagePreviewDialogState extends State<_ImagePreviewDialog> {
child: Row(
children: [
Expanded(
child: AppText(widget.title,
child: Text(widget.title,
maxLines: 2, overflow: TextOverflow.ellipsis),
),
IconButton(
icon: const Icon(Icons.close),
tooltip: tr('关闭'),
tooltip: tr('Close'),
onPressed: () => Navigator.pop(context),
),
],
@@ -2923,7 +2934,7 @@ class _FormDockState extends State<_FormDock> {
if (empty) missing.add(f.label);
}
if (missing.isNotEmpty) {
setState(() => _error = trArgs('请填写:{0}', [missing.join(tr('、'))]));
setState(() => _error = trArgs('Required: {0}', [missing.join(tr(', '))]));
return;
}
final answer = <String, Object?>{};
@@ -2966,7 +2977,7 @@ class _FormDockState extends State<_FormDock> {
const SizedBox(width: 8),
Expanded(
child: AppText(
widget.form.title.isEmpty ? '请选择' : widget.form.title,
widget.form.title.isEmpty ? 'Choose one' : widget.form.title,
style: const TextStyle(
fontSize: 14, fontWeight: FontWeight.w600),
),
@@ -2979,7 +2990,7 @@ class _FormDockState extends State<_FormDock> {
onPressed: _sending
? null
: () => widget.chat.cancelForm(widget.form),
child: const AppText('取消', style: TextStyle(fontSize: 12.5)),
child: const AppText('Cancel', style: TextStyle(fontSize: 12.5)),
),
],
),
@@ -3011,7 +3022,7 @@ class _FormDockState extends State<_FormDock> {
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2))
: const AppText('发送'),
: const AppText('Send'),
),
],
),
@@ -3026,7 +3037,7 @@ class _FormDockState extends State<_FormDock> {
final title = Row(
children: [
Flexible(
child: AppText(f.label,
child: Text(f.label,
style:
const TextStyle(fontSize: 13, fontWeight: FontWeight.w600)),
),
@@ -3038,7 +3049,7 @@ class _FormDockState extends State<_FormDock> {
? const SizedBox.shrink()
: Padding(
padding: const EdgeInsets.only(top: 2, bottom: 2),
child: AppText(f.description!,
child: Text(f.description!,
style: TextStyle(fontSize: 12, color: theme.hintColor)),
);
switch (f.type) {
@@ -3053,7 +3064,7 @@ class _FormDockState extends State<_FormDock> {
if (f.url != null && f.url!.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 2),
child: AppText(f.url!,
child: Text(f.url!,
style: TextStyle(
fontSize: 12, color: scheme.primary),
maxLines: 2,
@@ -3136,7 +3147,7 @@ class _FormDockState extends State<_FormDock> {
style: const TextStyle(fontSize: 13),
decoration: InputDecoration(
isDense: true,
hintText: tr('其他…'),
hintText: tr('Other…'),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8)),
),
@@ -3210,7 +3221,7 @@ class _FormDockState extends State<_FormDock> {
default:
return Padding(
padding: const EdgeInsets.only(top: 8),
child: AppText(trArgs('{0}({1})', [f.label, f.type]),
child: AppText(trArgs('{0} ({1})', [f.label, f.type]),
style: const TextStyle(fontSize: 13)),
);
}