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

+145 -137
View File
@@ -21,6 +21,7 @@ import '../widgets/shell_jobs.dart';
import '../widgets/slash_palette.dart';
import '../widgets/usage_ring.dart';
import 'files_panel.dart';
import '../l10n.dart';
/// The chat: streaming Markdown, tool rows, composer and sheets.
class ChatScreen extends StatefulWidget {
@@ -202,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) ? '用户停止了这条命令。' : completion.output;
shellWasStopped(chat.msgs, shellId) ? tr('用户停止了这条命令。') : completion.output;
Future<void> _stopShell(ShellTask task) async {
final shells = _shells;
@@ -212,7 +213,7 @@ class _ChatScreenState extends State<ChatScreen> {
} on ApiError catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('停止失败:${e.message}')));
.showSnackBar(SnackBar(content: AppText(trArgs('停止失败:{0}', [e.message]))));
}
}
@@ -255,7 +256,7 @@ class _ChatScreenState extends State<ChatScreen> {
Icon(Icons.lock_outline, size: 16, color: theme.hintColor),
const SizedBox(width: 8),
Expanded(
child: Text(
child: AppText(
operator
? '此会话由 Lead 管理,接管后才能继续。'
: '无法向子智能体会话发送提示。',
@@ -289,14 +290,14 @@ class _ChatScreenState extends State<ChatScreen> {
leading: parent != null
? IconButton(
icon: const Icon(Icons.arrow_back),
tooltip: '返回父会话',
tooltip: tr('返回父会话'),
onPressed: () => widget.app.openChat(parent),
)
: widget.onOpenSessions == null
? null
: IconButton(
icon: const Icon(Icons.menu),
tooltip: '会话',
tooltip: tr('会话'),
onPressed: widget.onOpenSessions,
),
title: Row(
@@ -307,7 +308,7 @@ class _ChatScreenState extends State<ChatScreen> {
const SizedBox(width: 6),
],
Expanded(
child: Text(_title(),
child: AppText(_title(),
maxLines: 1, overflow: TextOverflow.ellipsis),
),
],
@@ -315,7 +316,7 @@ class _ChatScreenState extends State<ChatScreen> {
actions: [
IconButton(
icon: const Icon(Icons.view_sidebar_outlined),
tooltip: '文件',
tooltip: tr('文件'),
onPressed: () => showFilesPanel(context, widget.app, chat.dir),
),
],
@@ -329,10 +330,10 @@ class _ChatScreenState extends State<ChatScreen> {
child: Row(
children: [
Expanded(
child: Text(chat.error!,
child: AppText(chat.error!,
style: TextStyle(
color: theme.colorScheme.onErrorContainer, fontSize: 13))),
TextButton(onPressed: chat.load, child: const Text('重试')),
TextButton(onPressed: chat.load, child: const AppText('重试')),
],
),
),
@@ -371,29 +372,36 @@ class _ChatScreenState extends State<ChatScreen> {
}
final rows = _rows();
final olderSlot = chat.hasMore || chat.loadingOlder ? 1 : 0;
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)),
// 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('载入更早的消息'),
),
);
}
return Center(
child: TextButton(
onPressed: _loadOlder,
child: const Text('载入更早的消息'),
),
);
},
},
),
);
}
@@ -591,7 +599,7 @@ class _ChatScreenState extends State<ChatScreen> {
case 'thinking':
return const Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
child: Text('正在思考…', style: TextStyle(color: Colors.grey, fontSize: 13)),
child: AppText('正在思考…', style: TextStyle(color: Colors.grey, fontSize: 13)),
);
case 'text':
return _textRow(r.msgId, r.part);
@@ -610,7 +618,7 @@ class _ChatScreenState extends State<ChatScreen> {
case 'shell':
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Text(chat.byId[r.msgId]?.text ?? '',
child: AppText(chat.byId[r.msgId]?.text ?? '',
style: const TextStyle(color: Colors.grey, fontSize: 13)),
);
default:
@@ -655,12 +663,12 @@ class _ChatScreenState extends State<ChatScreen> {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (item.text.isNotEmpty)
Text(item.text,
AppText(item.text,
style: TextStyle(color: scheme.onPrimary)),
if (item.files.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Text('📎 ${item.files.length} 个附件',
child: AppText(trArgs('📎 {0} 个附件', [item.files.length]),
style: TextStyle(
color: scheme.onPrimary, fontSize: 12.5)),
),
@@ -676,7 +684,7 @@ class _ChatScreenState extends State<ChatScreen> {
Icon(steering ? Icons.alt_route : Icons.schedule,
size: 13, color: theme.hintColor),
const SizedBox(width: 3),
Text(
AppText(
!chat.running
? '未发送'
: steering
@@ -688,7 +696,7 @@ class _ChatScreenState extends State<ChatScreen> {
TextButton(
onPressed: () => chat.changeInboxDelivery(
item.id, steering ? 'queue' : 'steer'),
child: Text(steering ? '改为排队' : '转为转向',
child: AppText(steering ? '改为排队' : '转为转向',
style: const TextStyle(fontSize: 12.5)),
),
TextButton(
@@ -700,7 +708,7 @@ class _ChatScreenState extends State<ChatScreen> {
offset: _draftCtrl.text.length);
_inputFocus.requestFocus();
},
child: const Text('撤回',
child: const AppText('撤回',
style: TextStyle(fontSize: 12.5)),
),
],
@@ -735,7 +743,7 @@ class _ChatScreenState extends State<ChatScreen> {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (m.text.isNotEmpty)
Text(m.text, style: TextStyle(color: theme.colorScheme.onPrimary)),
AppText(m.text, style: TextStyle(color: theme.colorScheme.onPrimary)),
for (final i in attachedImages)
Padding(
padding: const EdgeInsets.only(top: 6),
@@ -768,7 +776,7 @@ class _ChatScreenState extends State<ChatScreen> {
color: theme.colorScheme.onPrimary.withValues(alpha: 0.14),
borderRadius: BorderRadius.circular(8),
),
child: Text('📎 ${f.name.isEmpty ? '附件' : f.name}',
child: AppText('📎 ${f.name.isEmpty ? tr('附件') : f.name}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -790,7 +798,7 @@ class _ChatScreenState extends State<ChatScreen> {
_userImages[key] = bytes;
} catch (_) {
return const SizedBox(
width: 200, height: 60, child: Center(child: Text('图片无法显示')));
width: 200, height: 60, child: Center(child: AppText('图片无法显示')));
}
}
return Image.memory(bytes, width: 200, height: 150, fit: BoxFit.cover);
@@ -815,18 +823,18 @@ class _ChatScreenState extends State<ChatScreen> {
if (stamp.isNotEmpty)
Padding(
padding: const EdgeInsets.only(right: 8),
child: Text(stamp, style: const TextStyle(color: Colors.grey, fontSize: 12)),
child: AppText(stamp, style: const TextStyle(color: Colors.grey, fontSize: 12)),
),
TextButton(
onPressed: () => _copyText(m.text),
child: const Text('复制'),
child: const AppText('复制'),
),
PopupMenuButton<String>(
onSelected: (v) => _userAction(v, m),
itemBuilder: (_) => const [
PopupMenuItem(value: 'copy', child: Text('复制消息')),
PopupMenuItem(value: 'revert', child: Text('撤回此消息及之后')),
PopupMenuItem(value: 'fork', child: Text('从这里分叉')),
PopupMenuItem(value: 'copy', child: AppText('复制消息')),
PopupMenuItem(value: 'revert', child: AppText('撤回此消息及之后')),
PopupMenuItem(value: 'fork', child: AppText('从这里分叉')),
],
),
],
@@ -933,10 +941,10 @@ class _ChatScreenState extends State<ChatScreen> {
final label = tools == 0
? (running ? '思考中…' : '思考过程')
: failed
? '有步骤失败 · $tools 次工具调用'
? trArgs('有步骤失败 · {0} 次工具调用', [tools])
: running
? '执行中 · $tools 次工具调用'
: '已完成 · $tools 次工具调用';
? trArgs('执行中 · {0} 次工具调用', [tools])
: trArgs('已完成 · {0} 次工具调用', [tools]);
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _toggleGroup(id, start, collapsed),
@@ -955,7 +963,7 @@ class _ChatScreenState extends State<ChatScreen> {
color: failed ? theme.colorScheme.error : theme.hintColor),
const SizedBox(width: 8),
Expanded(
child: Text(label,
child: AppText(label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 13, color: theme.hintColor)),
@@ -1046,17 +1054,17 @@ class _ChatScreenState extends State<ChatScreen> {
: theme.colorScheme.onSurfaceVariant),
),
const SizedBox(width: 10),
Text(label,
AppText(label,
style: TextStyle(
fontSize: 13.5, color: theme.colorScheme.onSurface)),
if (summary.isEmpty)
const Spacer()
else ...[
const SizedBox(width: 6),
Text('·', style: TextStyle(fontSize: 13, color: theme.hintColor)),
AppText('·', style: TextStyle(fontSize: 13, color: theme.hintColor)),
const SizedBox(width: 6),
Expanded(
child: Text(summary,
child: AppText(summary,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -1085,7 +1093,7 @@ class _ChatScreenState extends State<ChatScreen> {
.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(6),
),
child: Text('后台',
child: AppText('后台',
style: TextStyle(
fontSize: 11,
color: theme.colorScheme.primary)),
@@ -1111,10 +1119,10 @@ class _ChatScreenState extends State<ChatScreen> {
onTap: () => _openPreview(ref),
child: Row(
children: [
const Text('🖼', style: TextStyle(fontSize: 12)),
const AppText('🖼', style: TextStyle(fontSize: 12)),
const SizedBox(width: 6),
Flexible(
child: Text(ref.label,
child: AppText(ref.label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -1173,7 +1181,7 @@ class _ChatScreenState extends State<ChatScreen> {
final ok = await widget.app.openSubagent(id);
if (ok || !mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(widget.app.lastError ?? '无法打开子代理会话')),
SnackBar(content: AppText(widget.app.lastError ?? '无法打开子代理会话')),
);
widget.app.clearLastError();
}
@@ -1292,7 +1300,7 @@ class _ChatScreenState extends State<ChatScreen> {
for (final e in extras)
Padding(
padding: const EdgeInsets.only(bottom: 2),
child: Text('${e.key}: ${e.value}',
child: AppText('${e.key}: ${e.value}',
style: mono.copyWith(
fontSize: 11.5, color: theme.hintColor)),
),
@@ -1301,8 +1309,8 @@ class _ChatScreenState extends State<ChatScreen> {
output.isNotEmpty
? output
: shelled
? '输出较大,正在载入…'
: (shell ? '无输出' : '无内容'),
? tr('输出较大,正在载入…')
: (shell ? tr('无输出') : tr('无内容')),
style: mono.copyWith(
color: p.state?.error != null
? theme.colorScheme.error
@@ -1339,7 +1347,7 @@ class _ChatScreenState extends State<ChatScreen> {
if (output.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
child: AppText(
output,
maxLines: 4,
overflow: TextOverflow.ellipsis,
@@ -1397,41 +1405,41 @@ class _ChatScreenState extends State<ChatScreen> {
}
static String _stepLabel(ContentPart p) {
if (p.type == 'reasoning') return '思考';
if (p.type == 'reasoning') return tr('思考');
switch (p.name ?? '') {
case 'bash':
case 'shell':
case 'execute':
return '运行';
return tr('运行');
case 'read':
return '读取';
return tr('读取');
case 'write':
return '写入';
return tr('写入');
case 'edit':
return '编辑';
return tr('编辑');
case 'patch':
case 'apply_patch':
return '补丁';
return tr('补丁');
case 'grep':
case 'glob':
case 'find':
return '搜索';
return tr('搜索');
case 'list':
return '列出';
return tr('列出');
case 'webfetch':
case 'web_fetch':
return '抓取';
return tr('抓取');
case 'todowrite':
return '任务';
return tr('任务');
case 'task':
case 'subagent':
return '子代理';
return tr('子代理');
case 'skill':
return '技能';
return tr('技能');
case 'openchamber_image':
return '生成图片';
return tr('生成图片');
default:
return p.name == null || p.name!.isEmpty ? '工具' : p.name!;
return p.name == null || p.name!.isEmpty ? tr('工具') : p.name!;
}
}
@@ -1497,7 +1505,7 @@ class _ChatScreenState extends State<ChatScreen> {
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Text(parts.join(' · '),
child: AppText(parts.join(' · '),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Colors.grey, fontSize: 13)),
@@ -1506,8 +1514,8 @@ class _ChatScreenState extends State<ChatScreen> {
PopupMenuButton<String>(
onSelected: (v) => _footerAction(v, m),
itemBuilder: (_) => const [
PopupMenuItem(value: 'copy', child: Text('复制回答')),
PopupMenuItem(value: 'fork', child: Text('从这里分叉')),
PopupMenuItem(value: 'copy', child: AppText('复制回答')),
PopupMenuItem(value: 'fork', child: AppText('从这里分叉')),
],
),
],
@@ -1540,27 +1548,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 : '未知错误');
: (e != null && e.type.isNotEmpty ? e.type : tr('未知错误'));
final type = (e?.type ?? '').toLowerCase();
final plain = detail.trim().toLowerCase().replaceFirst(RegExp(r'\.$'), '');
if (m.type == 'compaction') {
return (text: '压缩失败:$detail', body: e?.body);
return (text: trArgs('压缩失败:{0}', [detail]), body: e?.body);
}
if (type == 'sessionretry') {
return (text: 'OpenCode 发送消息失败,正在重试:$detail', body: e?.body);
return (text: trArgs('OpenCode 发送消息失败,正在重试:{0}', [detail]), body: e?.body);
}
if (_isAuthError(detail)) {
return (
text: '模型的认证失败,请在服务端重新登录或检查 API Key。',
text: tr('模型的认证失败,请在服务端重新登录或检查 API Key。'),
body: e?.body
);
}
if (type == 'messageabortederror' ||
plain == 'aborted' ||
plain == 'step interrupted') {
return (text: '本轮已停止。', body: null);
return (text: tr('本轮已停止。'), body: null);
}
return (text: 'OpenCode 发送消息失败:$detail', body: e?.body);
return (text: trArgs('OpenCode 发送消息失败:{0}', [detail]), body: e?.body);
}
static String _prettyBody(String raw) {
@@ -1601,13 +1609,13 @@ class _ChatScreenState extends State<ChatScreen> {
Icon(Icons.content_cut, size: 16, color: theme.hintColor),
const SizedBox(width: 8),
Expanded(
child: Text(label,
child: AppText(label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 13, color: theme.hintColor)),
),
if (summary.isNotEmpty)
Text(open ? '隐藏摘要' : '显示摘要',
AppText(open ? '隐藏摘要' : '显示摘要',
style: TextStyle(fontSize: 12, color: scheme.primary)),
const SizedBox(width: 4),
AnimatedRotation(
@@ -1636,7 +1644,7 @@ class _ChatScreenState extends State<ChatScreen> {
borderRadius: BorderRadius.circular(8),
),
child: summary.isEmpty
? Text(running ? '正在生成摘要…' : '(摘要为空)',
? AppText(running ? '正在生成摘要…' : '(摘要为空)',
style: TextStyle(fontSize: 13, color: theme.hintColor))
: MarkdownView(summary, fontSize: 14),
),
@@ -1694,7 +1702,7 @@ class _ChatScreenState extends State<ChatScreen> {
onPressed: () => setState(() {
open ? chat.expanded.remove(key) : chat.expanded.add(key);
}),
child: Text(open ? '收起详情' : '显示详情',
child: AppText(open ? '收起详情' : '显示详情',
style: const TextStyle(fontSize: 12.5)),
),
),
@@ -1752,7 +1760,7 @@ class _ChatScreenState extends State<ChatScreen> {
final st = part.state?.status ?? '';
if (part.type == 'tool' &&
(st == 'running' || st == 'streaming' || st == 'pending')) {
return (title: '正在${_stepLabel(part)}', detail: _stepSummary(part));
return (title: trArgs('正在{0}', [_stepLabel(part)]), detail: _stepSummary(part));
}
}
if (m.completed == 0) {
@@ -1819,7 +1827,7 @@ class _ChatScreenState extends State<ChatScreen> {
Expanded(
child: Row(
children: [
Text(
AppText(
act.title,
style: theme.textTheme.labelMedium?.copyWith(
fontSize: 13,
@@ -1830,7 +1838,7 @@ class _ChatScreenState extends State<ChatScreen> {
if (act.detail.isNotEmpty) ...[
const SizedBox(width: 6),
Flexible(
child: Text(
child: AppText(
act.detail,
maxLines: 1,
softWrap: false,
@@ -1847,7 +1855,7 @@ class _ChatScreenState extends State<ChatScreen> {
),
if (elapsed.isNotEmpty) ...[
const SizedBox(width: 8),
Text(
AppText(
elapsed,
style: TextStyle(
fontSize: 12,
@@ -1874,7 +1882,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 '$secs 秒';
if (secs < 60) return trArgs('{0} 秒', [secs]);
return '${secs ~/ 60}:${(secs % 60).toString().padLeft(2, '0')}';
}
@@ -1891,12 +1899,12 @@ class _ChatScreenState extends State<ChatScreen> {
Future<void> _copyText(String text) async {
if (text.trim().isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('没有可复制的文字')));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: AppText('没有可复制的文字')));
return;
}
await Clipboard.setData(ClipboardData(text: text));
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('已复制')));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: AppText('已复制')));
}
}
@@ -1994,7 +2002,7 @@ class _ChatScreenState extends State<ChatScreen> {
ComposerBox(
controller: _draftCtrl,
focusNode: _inputFocus,
hint: chat.running ? '生成中,仍可输入…' : '发消息…',
hint: chat.running ? tr('生成中,仍可输入…') : tr('发消息…'),
maxLines: 5,
keyboardInset: keyboardInset,
// While the palette is up, the keyboard's action key picks the
@@ -2031,7 +2039,7 @@ class _ChatScreenState extends State<ChatScreen> {
},
leading: _roundKey(
icon: Icons.attach_file,
label: '添加附件',
label: tr('添加附件'),
onTap: _pickFiles,
busy: _attaching,
),
@@ -2059,7 +2067,7 @@ class _ChatScreenState extends State<ChatScreen> {
size: 16,
accent: scheme.primary),
const SizedBox(width: 3),
Text('${usage.$4.round()}%',
AppText('${usage.$4.round()}%',
style: TextStyle(
fontSize: 12,
color: scheme.onSurfaceVariant)),
@@ -2072,7 +2080,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 ? '停止' : '发送',
label: showStop ? tr('停止') : tr('发送'),
filled: true,
enabled: showStop || canSend,
onTap: showStop ? chat.stop : _send,
@@ -2180,13 +2188,13 @@ class _ChatScreenState extends State<ChatScreen> {
children: [
const Padding(
padding: EdgeInsets.fromLTRB(20, 4, 20, 8),
child: Text('发送方式',
child: AppText('发送方式',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
),
ListTile(
leading: const Icon(Icons.alt_route),
title: const Text('转向当前回合'),
subtitle: const Text('在下一步加入,工作继续'),
title: const AppText('转向当前回合'),
subtitle: const AppText('在下一步加入,工作继续'),
trailing: fallback == 'steer'
? Icon(Icons.check, size: 20, color: scheme.primary)
: null,
@@ -2194,8 +2202,8 @@ class _ChatScreenState extends State<ChatScreen> {
),
ListTile(
leading: const Icon(Icons.schedule),
title: const Text('排队'),
subtitle: const Text('等本轮结束后发送'),
title: const AppText('排队'),
subtitle: const AppText('等本轮结束后发送'),
trailing: fallback == 'queue'
? Icon(Icons.check, size: 20, color: scheme.primary)
: null,
@@ -2255,7 +2263,7 @@ class _ChatScreenState extends State<ChatScreen> {
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('选择失败:$e')));
.showSnackBar(SnackBar(content: AppText(trArgs('选择失败:{0}', ['$e']))));
}
} finally {
if (mounted) setState(() => _attaching = false);
@@ -2288,22 +2296,22 @@ class _ChatScreenState extends State<ChatScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('请求权限: ${p.action}',
AppText(trArgs('请求权限: {0}', [p.action]),
style: const TextStyle(fontWeight: FontWeight.w600)),
Text(p.resources.join('、'),
AppText(p.resources.join(tr('、')),
style: const TextStyle(color: Colors.grey, fontSize: 13)),
const SizedBox(height: 6),
Row(
children: [
TextButton(
onPressed: () => chat.replyPermission(p.id, 'once'),
child: const Text('允许一次')),
child: const AppText('允许一次')),
TextButton(
onPressed: () => chat.replyPermission(p.id, 'always'),
child: const Text('总是允许')),
child: const AppText('总是允许')),
TextButton(
onPressed: () => chat.replyPermission(p.id, 'reject'),
child: const Text('拒绝')),
child: const AppText('拒绝')),
],
),
],
@@ -2320,16 +2328,16 @@ class _ChatScreenState extends State<ChatScreen> {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(title),
content: Text(message),
title: AppText(title),
content: AppText(message),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('取消')),
TextButton(onPressed: () => Navigator.pop(context), child: const AppText('取消')),
FilledButton(
onPressed: () {
Navigator.pop(context);
onConfirm();
},
child: Text(confirm),
child: AppText(confirm),
),
],
),
@@ -2365,7 +2373,7 @@ class _ChatScreenState extends State<ChatScreen> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('上下文占用', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const AppText('上下文占用', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_usageRow('模型', widget.app.modelName(chat.selectedModel ?? _lastModel())),
_usageRow('已用 tokens', _fmtTokens(r.$1)),
@@ -2376,7 +2384,7 @@ class _ChatScreenState extends State<ChatScreen> {
],
if (chat.turnCost > 0) _usageRow('本轮费用', '\$${chat.turnCost.toStringAsFixed(4)}'),
const SizedBox(height: 8),
const Text('输出预留按最多 32K tokens 计算,与官方客户端一致。',
const AppText('输出预留按最多 32K tokens 计算,与官方客户端一致。',
style: TextStyle(color: Colors.grey, fontSize: 12)),
],
),
@@ -2395,8 +2403,8 @@ class _ChatScreenState extends State<ChatScreen> {
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
Expanded(child: Text(label, style: const TextStyle(color: Colors.grey))),
Text(value),
Expanded(child: AppText(label, style: const TextStyle(color: Colors.grey))),
AppText(value),
],
),
);
@@ -2607,9 +2615,9 @@ Future<Uint8List> _imageBytesFor(
Client client, String source, String directory) async {
if (source.startsWith('data:')) {
final comma = source.indexOf(',');
if (comma < 0) throw Exception('无效的 data URL');
if (comma < 0) throw Exception(tr('无效的 data URL'));
final meta = source.substring(5, comma);
if (!meta.contains('base64')) throw Exception('不支持的 data URL');
if (!meta.contains('base64')) throw Exception(tr('不支持的 data URL'));
return base64Decode(source.substring(comma + 1));
}
final cached = _imageBytes[source];
@@ -2676,8 +2684,8 @@ class _GeneratedImageState extends State<_GeneratedImage> {
size: 16, color: theme.hintColor),
const SizedBox(width: 8),
Expanded(
child: Text(
'图片加载失败:${pathLeaf(widget.source)}',
child: AppText(
trArgs('图片加载失败:{0}', [pathLeaf(widget.source)]),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12, color: theme.hintColor),
@@ -2790,7 +2798,7 @@ class _ImagePreviewDialogState extends State<_ImagePreviewDialog> {
} else {
body = Padding(
padding: const EdgeInsets.all(24),
child: SelectableText('无法预览:$_error',
child: SelectableText(trArgs('无法预览:{0}', ['$_error']),
style: TextStyle(color: theme.colorScheme.error)),
);
}
@@ -2807,12 +2815,12 @@ class _ImagePreviewDialogState extends State<_ImagePreviewDialog> {
child: Row(
children: [
Expanded(
child: Text(widget.title,
child: AppText(widget.title,
maxLines: 2, overflow: TextOverflow.ellipsis),
),
IconButton(
icon: const Icon(Icons.close),
tooltip: '关闭',
tooltip: tr('关闭'),
onPressed: () => Navigator.pop(context),
),
],
@@ -2915,7 +2923,7 @@ class _FormDockState extends State<_FormDock> {
if (empty) missing.add(f.label);
}
if (missing.isNotEmpty) {
setState(() => _error = '请填写:${missing.join('、')}');
setState(() => _error = trArgs('请填写:{0}', [missing.join(tr('、'))]));
return;
}
final answer = <String, Object?>{};
@@ -2957,7 +2965,7 @@ class _FormDockState extends State<_FormDock> {
Icon(Icons.help_outline, size: 18, color: scheme.primary),
const SizedBox(width: 8),
Expanded(
child: Text(
child: AppText(
widget.form.title.isEmpty ? '请选择' : widget.form.title,
style: const TextStyle(
fontSize: 14, fontWeight: FontWeight.w600),
@@ -2971,7 +2979,7 @@ class _FormDockState extends State<_FormDock> {
onPressed: _sending
? null
: () => widget.chat.cancelForm(widget.form),
child: const Text('取消', style: TextStyle(fontSize: 12.5)),
child: const AppText('取消', style: TextStyle(fontSize: 12.5)),
),
],
),
@@ -2990,7 +2998,7 @@ class _FormDockState extends State<_FormDock> {
if (_error != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Text(_error!,
child: AppText(_error!,
style: TextStyle(fontSize: 12, color: scheme.error)),
),
Row(
@@ -3003,7 +3011,7 @@ class _FormDockState extends State<_FormDock> {
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2))
: const Text('发送'),
: const AppText('发送'),
),
],
),
@@ -3018,19 +3026,19 @@ class _FormDockState extends State<_FormDock> {
final title = Row(
children: [
Flexible(
child: Text(f.label,
child: AppText(f.label,
style:
const TextStyle(fontSize: 13, fontWeight: FontWeight.w600)),
),
if (f.required)
Text(' *', style: TextStyle(color: scheme.error, fontSize: 13)),
AppText(' *', style: TextStyle(color: scheme.error, fontSize: 13)),
],
);
Widget hint() => f.description == null || f.description!.isEmpty
? const SizedBox.shrink()
: Padding(
padding: const EdgeInsets.only(top: 2, bottom: 2),
child: Text(f.description!,
child: AppText(f.description!,
style: TextStyle(fontSize: 12, color: theme.hintColor)),
);
switch (f.type) {
@@ -3045,7 +3053,7 @@ class _FormDockState extends State<_FormDock> {
if (f.url != null && f.url!.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 2),
child: Text(f.url!,
child: AppText(f.url!,
style: TextStyle(
fontSize: 12, color: scheme.primary),
maxLines: 2,
@@ -3079,7 +3087,7 @@ class _FormDockState extends State<_FormDock> {
children: [
for (final o in f.options)
FilterChip(
label: Text(o.label, style: const TextStyle(fontSize: 12.5)),
label: AppText(o.label, style: const TextStyle(fontSize: 12.5)),
selected: selected.contains(o.value),
onSelected: (on) {
final next = [...selected];
@@ -3112,7 +3120,7 @@ class _FormDockState extends State<_FormDock> {
children: [
for (final o in f.options)
ChoiceChip(
label: Text(o.label,
label: AppText(o.label,
style: const TextStyle(fontSize: 12.5)),
selected: current == o.value,
onSelected: (_) => _set(f, o.value),
@@ -3128,7 +3136,7 @@ class _FormDockState extends State<_FormDock> {
style: const TextStyle(fontSize: 13),
decoration: InputDecoration(
isDense: true,
hintText: '其他…',
hintText: tr('其他…'),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8)),
),
@@ -3202,7 +3210,7 @@ class _FormDockState extends State<_FormDock> {
default:
return Padding(
padding: const EdgeInsets.only(top: 8),
child: Text('${f.label}(${f.type})',
child: AppText(trArgs('{0}({1})', [f.label, f.type]),
style: const TextStyle(fontSize: 13)),
);
}