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

+77 -73
View File
@@ -6,6 +6,7 @@ import '../api/client.dart';
import '../api/models.dart';
import '../state.dart';
import '../widgets/markdown_view.dart';
import '../l10n.dart';
class KnowledgePanel extends StatefulWidget {
final AppState app;
@@ -48,7 +49,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
if (client == null || _projectId.isEmpty) {
setState(() {
_loading = false;
_error = '这个会话没有关联目录';
_error = tr('这个会话没有关联目录');
});
return;
}
@@ -90,7 +91,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
void _fail(Object error) {
if (!mounted) return;
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('$error')));
.showSnackBar(SnackBar(content: AppText('$error')));
}
bool _matches(Iterable<String> fields) {
@@ -116,8 +117,8 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
decoration: InputDecoration(
isDense: true,
hintText: _memory == null
? '搜索笔记、待办与计划'
: '搜索笔记、待办、计划与记忆',
? tr('搜索笔记、待办与计划')
: tr('搜索笔记、待办、计划与记忆'),
prefixIcon: const Icon(Icons.search, size: 18),
suffixIcon: _query.isEmpty
? null
@@ -134,7 +135,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
),
),
IconButton(
tooltip: '刷新',
tooltip: tr('刷新'),
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.refresh, size: 20),
onPressed: _load,
@@ -151,11 +152,11 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
List<(String, String, int)> get _sectionsList {
final context = _context;
return [
('notes', '笔记', context?.notes.length ?? 0),
('todos', '待办', context?.todos.length ?? 0),
('plans', '计划', context?.plans.length ?? 0),
('notes', tr('笔记'), context?.notes.length ?? 0),
('todos', tr('待办'), context?.todos.length ?? 0),
('plans', tr('计划'), context?.plans.length ?? 0),
if (_memory != null)
('memory', '记忆',
('memory', tr('记忆'),
(_memory!.global.length + _memory!.project.length)),
];
}
@@ -172,7 +173,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
),
segments: [
for (final (key, label, count) in sections)
ButtonSegment(value: key, label: Text('$label $count')),
ButtonSegment(value: key, label: AppText('$label $count')),
],
selected: {_section},
onSelectionChanged: (value) => setState(() => _section = value.first),
@@ -189,11 +190,11 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(_error!,
AppText(_error!,
textAlign: TextAlign.center,
style: TextStyle(color: theme.colorScheme.error, fontSize: 13)),
const SizedBox(height: 8),
FilledButton(onPressed: _load, child: const Text('重试')),
FilledButton(onPressed: _load, child: const AppText('重试')),
],
),
),
@@ -223,7 +224,8 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
});
return Column(
children: [
_sectionHeader(theme, '${notes.length} 条笔记', '新建笔记', _addNote),
_sectionHeader(theme, trArgs('{0} 条笔记', [notes.length]),
'新建笔记', _addNote),
Expanded(
child: notes.isEmpty
? _empty(theme, Icons.sticky_note_2_outlined,
@@ -257,7 +259,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppText(
note.body.trim(),
maxLines: 5,
overflow: TextOverflow.ellipsis,
@@ -272,7 +274,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
child: Icon(Icons.push_pin,
size: 12, color: scheme.primary),
),
Text(
AppText(
_stamp(note.updatedAt),
style:
TextStyle(fontSize: 11, color: theme.hintColor),
@@ -307,10 +309,10 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
}
},
itemBuilder: (_) => [
const PopupMenuItem(value: 'edit', child: Text('编辑')),
const PopupMenuItem(value: 'edit', child: AppText('编辑')),
PopupMenuItem(
value: 'pin', child: Text(note.pinned ? '取消置顶' : '置顶')),
const PopupMenuItem(value: 'delete', child: Text('删除')),
value: 'pin', child: AppText(note.pinned ? '取消置顶' : '置顶')),
const PopupMenuItem(value: 'delete', child: AppText('删除')),
],
),
],
@@ -329,7 +331,8 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
final done = todos.where((todo) => todo.completed).length;
return Column(
children: [
_sectionHeader(theme, '$done/${todos.length} 已完成', '新建待办', _addTodo),
_sectionHeader(theme, trArgs('{0}/{1} 已完成', [done, todos.length]),
'新建待办', _addTodo),
Expanded(
child: todos.isEmpty
? _empty(theme, Icons.checklist,
@@ -344,7 +347,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
value: todo.completed,
onChanged: (value) => _toggleTodo(todo, value ?? false),
controlAffinity: ListTileControlAffinity.leading,
title: Text(
title: AppText(
todo.text,
style: TextStyle(
fontSize: 13.5,
@@ -370,7 +373,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
}
},
itemBuilder: (_) => const [
PopupMenuItem(value: 'delete', child: Text('删除')),
PopupMenuItem(value: 'delete', child: AppText('删除')),
],
),
);
@@ -404,7 +407,8 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
});
return Column(
children: [
_sectionHeader(theme, '${plans.length} 份计划', '新建计划', _newPlan),
_sectionHeader(theme, trArgs('{0} 份计划', [plans.length]),
'新建计划', _newPlan),
Expanded(
child: plans.isEmpty
? _empty(theme, Icons.description_outlined,
@@ -434,7 +438,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
child: Icon(Icons.push_pin, size: 13, color: scheme.primary),
),
Expanded(
child: Text(plan.title.isEmpty ? plan.file : plan.title,
child: AppText(plan.title.isEmpty ? plan.file : plan.title,
maxLines: 2, overflow: TextOverflow.ellipsis),
),
],
@@ -457,14 +461,14 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
),
),
const SizedBox(width: 6),
Text('${plan.progressDone}/${plan.progressTotal}',
AppText('${plan.progressDone}/${plan.progressTotal}',
style:
TextStyle(fontSize: 11, color: theme.hintColor)),
],
),
],
const SizedBox(height: 2),
Text(
AppText(
plan.source == 'shared' ? '团队共享' : '个人',
style: TextStyle(fontSize: 11, color: theme.hintColor),
),
@@ -493,8 +497,8 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
},
itemBuilder: (_) => [
PopupMenuItem(
value: 'pin', child: Text(plan.pinned ? '取消置顶' : '置顶')),
const PopupMenuItem(value: 'delete', child: Text('删除')),
value: 'pin', child: AppText(plan.pinned ? '取消置顶' : '置顶')),
const PopupMenuItem(value: 'delete', child: AppText('删除')),
],
),
onTap: () => _viewPlan(plan),
@@ -524,14 +528,14 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
return ListView(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
children: [
_memoryGroup(theme, '全局记忆', global, 'global',
_memoryGroup(theme, tr('全局记忆'), global, 'global',
failed: snapshot.globalFailed),
const SizedBox(height: 8),
_memoryGroup(theme, '项目记忆', project, 'project',
_memoryGroup(theme, tr('项目记忆'), project, 'project',
failed: snapshot.projectFailed),
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
child: AppText(
'记忆由 agent 在会话中记录;你可以在这里修改或删除它。',
style: TextStyle(fontSize: 11.5, color: theme.hintColor),
),
@@ -548,20 +552,20 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
children: [
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('$title(${entries.length})',
child: AppText(trArgs('{0}({1})', [title, entries.length]),
style: TextStyle(fontSize: 12, color: theme.hintColor)),
),
if (failed)
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('读取失败,请刷新',
child: AppText('读取失败,请刷新',
style: TextStyle(
fontSize: 12, color: theme.colorScheme.error)),
)
else if (entries.isEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('暂无', style: TextStyle(fontSize: 12, color: theme.hintColor)),
child: AppText('暂无', style: TextStyle(fontSize: 12, color: theme.hintColor)),
),
for (final entry in entries) _memoryCard(theme, entry, scope),
],
@@ -587,7 +591,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
Row(
children: [
Flexible(
child: Text(entry.title,
child: AppText(entry.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
@@ -601,7 +605,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
color: scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(4),
),
child: Text(entry.typeLabel,
child: AppText(entry.typeLabel,
style: TextStyle(
fontSize: 10, color: theme.hintColor)),
),
@@ -614,7 +618,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
],
),
const SizedBox(height: 3),
Text(entry.body,
AppText(entry.body,
maxLines: 4,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 12.5, height: 1.35)),
@@ -631,8 +635,8 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
}
},
itemBuilder: (_) => const [
PopupMenuItem(value: 'edit', child: Text('编辑')),
PopupMenuItem(value: 'delete', child: Text('删除')),
PopupMenuItem(value: 'edit', child: AppText('编辑')),
PopupMenuItem(value: 'delete', child: AppText('删除')),
],
),
],
@@ -700,7 +704,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
child: Row(
children: [
Expanded(
child: Text(summary,
child: AppText(summary,
style: TextStyle(fontSize: 12, color: theme.hintColor)),
),
TextButton.icon(
@@ -711,7 +715,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
),
onPressed: onTap,
icon: const Icon(Icons.add, size: 16),
label: Text(action, style: const TextStyle(fontSize: 12.5)),
label: AppText(action, style: const TextStyle(fontSize: 12.5)),
),
],
),
@@ -725,7 +729,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
children: [
Icon(icon, size: 36, color: theme.hintColor),
const SizedBox(height: 8),
Text(text, style: TextStyle(fontSize: 13, color: theme.hintColor)),
AppText(text, style: TextStyle(fontSize: 13, color: theme.hintColor)),
],
),
);
@@ -738,7 +742,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
context: context,
builder: (_) => _TextPromptDialog(
title: note == null ? '新建笔记' : '编辑笔记',
hint: '记点什么,供之后的会话参考',
hint: tr('记点什么,供之后的会话参考'),
initial: note?.body ?? '',
maxLength: 3000,
maxLines: 10,
@@ -765,9 +769,9 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
Future<void> _addTodo() async {
final text = await showDialog<String>(
context: context,
builder: (_) => const _TextPromptDialog(
builder: (_) => _TextPromptDialog(
title: '新建待办',
hint: '要做什么',
hint: tr('要做什么'),
maxLength: 1000,
maxLines: 1,
minLines: 1,
@@ -872,7 +876,7 @@ class _PlanPageState extends State<_PlanPage> {
} catch (error) {
if (mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('$error')));
.showSnackBar(SnackBar(content: AppText('$error')));
}
} finally {
if (mounted) setState(() => _saving = false);
@@ -883,18 +887,18 @@ class _PlanPageState extends State<_PlanPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title, maxLines: 1, overflow: TextOverflow.ellipsis),
title: AppText(widget.title, maxLines: 1, overflow: TextOverflow.ellipsis),
actions: [
if (_editing)
TextButton(
onPressed: _saving ? null : () => setState(() => _editing = false),
child: const Text('取消'),
child: const AppText('取消'),
),
TextButton(
onPressed: _saving
? null
: (_editing ? _save : () => setState(() => _editing = true)),
child: Text(_saving ? '保存中…' : (_editing ? '保存' : '编辑')),
child: AppText(_saving ? '保存中…' : (_editing ? '保存' : '编辑')),
),
],
),
@@ -961,7 +965,7 @@ class _TextPromptDialogState extends State<_TextPromptDialog> {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(widget.title),
title: AppText(widget.title),
content: SizedBox(
width: double.maxFinite,
child: TextField(
@@ -979,10 +983,10 @@ class _TextPromptDialogState extends State<_TextPromptDialog> {
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消')),
child: const AppText('取消')),
FilledButton(
onPressed: () => Navigator.pop(context, _controller.text.trim()),
child: Text(widget.action)),
child: AppText(widget.action)),
],
);
}
@@ -1010,7 +1014,7 @@ class _NewPlanDialogState extends State<_NewPlanDialog> {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('新建计划'),
title: const AppText('新建计划'),
content: SizedBox(
width: double.maxFinite,
child: Column(
@@ -1020,9 +1024,9 @@ class _NewPlanDialogState extends State<_NewPlanDialog> {
controller: _title,
autofocus: true,
maxLength: 160,
decoration: const InputDecoration(
labelText: '标题',
border: OutlineInputBorder(),
decoration: InputDecoration(
labelText: tr('标题'),
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 8),
@@ -1030,10 +1034,10 @@ class _NewPlanDialogState extends State<_NewPlanDialog> {
controller: _body,
maxLines: 10,
minLines: 6,
decoration: const InputDecoration(
decoration: InputDecoration(
alignLabelWithHint: true,
labelText: '计划正文(Markdown)',
border: OutlineInputBorder(),
labelText: tr('计划正文(Markdown)'),
border: const OutlineInputBorder(),
),
),
],
@@ -1042,11 +1046,11 @@ class _NewPlanDialogState extends State<_NewPlanDialog> {
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消')),
child: const AppText('取消')),
FilledButton(
onPressed: () => Navigator.pop(
context, (_title.text.trim(), _body.text)),
child: const Text('创建')),
child: const AppText('创建')),
],
);
}
@@ -1078,7 +1082,7 @@ class _MemoryDialogState extends State<_MemoryDialog> {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('编辑记忆'),
title: const AppText('编辑记忆'),
content: SizedBox(
width: double.maxFinite,
child: Column(
@@ -1088,9 +1092,9 @@ class _MemoryDialogState extends State<_MemoryDialog> {
controller: _title,
autofocus: true,
maxLength: 120,
decoration: const InputDecoration(
labelText: '标题',
border: OutlineInputBorder(),
decoration: InputDecoration(
labelText: tr('标题'),
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 8),
@@ -1101,9 +1105,9 @@ class _MemoryDialogState extends State<_MemoryDialog> {
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
segments: const [
ButtonSegment(value: 'fact', label: Text('事实')),
ButtonSegment(value: 'preference', label: Text('偏好')),
ButtonSegment(value: 'reference', label: Text('参考')),
ButtonSegment(value: 'fact', label: AppText('事实')),
ButtonSegment(value: 'preference', label: AppText('偏好')),
ButtonSegment(value: 'reference', label: AppText('参考')),
],
selected: {_type},
onSelectionChanged: (value) =>
@@ -1115,10 +1119,10 @@ class _MemoryDialogState extends State<_MemoryDialog> {
maxLength: 2000,
maxLines: 6,
minLines: 4,
decoration: const InputDecoration(
decoration: InputDecoration(
alignLabelWithHint: true,
labelText: '内容',
border: OutlineInputBorder(),
labelText: tr('内容'),
border: const OutlineInputBorder(),
),
),
],
@@ -1126,16 +1130,16 @@ class _MemoryDialogState extends State<_MemoryDialog> {
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context), child: const Text('取消')),
onPressed: () => Navigator.pop(context), child: const AppText('取消')),
FilledButton(
onPressed: () {
final title = _title.text.trim();
if (title.isEmpty) return;
Navigator.pop(context, (title, _body.text.trim(), _type));
},
child: const Text('保存'),
child: const AppText('保存'),
),
],
);
}
}
}