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:
1 parent
da4bfb6826
commit
7b5bccf28f
42 files changed
+1943
-735
No files matched your search
@@ -8,6 +8,7 @@ import '../api/models.dart';
|
||||
import '../api/scheduled_tasks.dart';
|
||||
import '../state.dart';
|
||||
import '../widgets/scheduled_task_editor.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
/// Where a task runs: a registered project, or the chats scope.
|
||||
class _TaskScope {
|
||||
@@ -59,7 +60,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
project.label,
|
||||
project.canonical,
|
||||
),
|
||||
const _TaskScope(Client.scheduledChatsScope, '聊天'),
|
||||
_TaskScope(Client.scheduledChatsScope, tr('聊天')),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -103,14 +104,16 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_tasks = const [];
|
||||
_error = e.status == 404 ? '服务器不支持计划任务' : '加载计划任务失败:${e.message}';
|
||||
_error = e.status == 404
|
||||
? '服务器不支持计划任务'
|
||||
: trArgs('加载计划任务失败:{0}', [e.message]);
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted || _scope?.id != scope.id) return;
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_tasks = const [];
|
||||
_error = '加载计划任务失败:$e';
|
||||
_error = trArgs('加载计划任务失败:{0}', [e]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -118,7 +121,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
void _say(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(message)));
|
||||
.showSnackBar(SnackBar(content: AppText(message)));
|
||||
}
|
||||
|
||||
Future<void> _openEditor([ScheduledTask? task]) async {
|
||||
@@ -154,7 +157,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
_say(e.message.isEmpty ? '保存任务失败' : e.message);
|
||||
return false;
|
||||
} catch (e) {
|
||||
_say('保存任务失败:$e');
|
||||
_say(trArgs('保存任务失败:{0}', [e]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -189,7 +192,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
} on ApiError catch (e) {
|
||||
_say(e.status == 409 ? '任务已在队列中等待' : (e.message.isEmpty ? '运行任务失败' : e.message));
|
||||
} catch (e) {
|
||||
_say('运行任务失败:$e');
|
||||
_say(trArgs('运行任务失败:{0}', [e]));
|
||||
} finally {
|
||||
if (mounted) setState(() => _busyId = '');
|
||||
}
|
||||
@@ -202,15 +205,15 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialog) => AlertDialog(
|
||||
title: const Text('删除计划任务?'),
|
||||
content: Text('“${task.name}”及其计划会被删除。'),
|
||||
title: const AppText('删除计划任务?'),
|
||||
content: AppText(trArgs('“{0}”及其计划会被删除。', [task.name])),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialog, false),
|
||||
child: const Text('取消')),
|
||||
child: const AppText('取消')),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(dialog, true),
|
||||
child: const Text('删除')),
|
||||
child: const AppText('删除')),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -233,16 +236,16 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('计划任务'),
|
||||
title: const AppText('计划任务'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: '刷新',
|
||||
tooltip: tr('刷新'),
|
||||
onPressed: _loading ? null : _load,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
tooltip: '新建任务',
|
||||
tooltip: tr('新建任务'),
|
||||
onPressed: _scope == null ? null : () => _openEditor(),
|
||||
),
|
||||
],
|
||||
@@ -264,7 +267,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
children: [
|
||||
Icon(Icons.folder_outlined, size: 18, color: theme.hintColor),
|
||||
const SizedBox(width: 8),
|
||||
Text('运行位置', style: TextStyle(fontSize: 13, color: theme.hintColor)),
|
||||
AppText('运行位置', style: TextStyle(fontSize: 13, color: theme.hintColor)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: DropdownButtonHideUnderline(
|
||||
@@ -275,7 +278,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
for (final scope in _scopes)
|
||||
DropdownMenuItem(
|
||||
value: scope.id,
|
||||
child: Text(scope.label,
|
||||
child: AppText(scope.label,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
],
|
||||
@@ -306,9 +309,9 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(_error!, style: TextStyle(color: theme.hintColor)),
|
||||
AppText(_error!, style: TextStyle(color: theme.hintColor)),
|
||||
const SizedBox(height: 8),
|
||||
TextButton(onPressed: _load, child: const Text('重试')),
|
||||
TextButton(onPressed: _load, child: const AppText('重试')),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -320,12 +323,12 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
children: [
|
||||
Icon(Icons.event_note_outlined, size: 36, color: theme.hintColor),
|
||||
const SizedBox(height: 10),
|
||||
Text('暂无计划任务。', style: TextStyle(color: theme.hintColor)),
|
||||
AppText('暂无计划任务。', style: TextStyle(color: theme.hintColor)),
|
||||
const SizedBox(height: 8),
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: () => _openEditor(),
|
||||
icon: const Icon(Icons.add, size: 18),
|
||||
label: const Text('新建任务'),
|
||||
label: const AppText('新建任务'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -350,10 +353,13 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
_ => theme.hintColor,
|
||||
};
|
||||
final next = task.nextRunAt > 0 && task.enabled
|
||||
? '下次:${scheduledRelativeTime(task.nextRunAt)}'
|
||||
? trArgs('下次:{0}', [scheduledRelativeTime(task.nextRunAt)])
|
||||
: (task.enabled ? '' : '已暂停');
|
||||
final last = task.lastRunAt > 0
|
||||
? '上次运行 ${scheduledClock(task.lastRunAt)} · ${scheduledStatusLabel(task.lastStatus)}'
|
||||
? trArgs('上次运行 {0} · {1}', [
|
||||
scheduledClock(task.lastRunAt),
|
||||
scheduledStatusLabel(task.lastStatus),
|
||||
])
|
||||
: '从未运行';
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 2),
|
||||
@@ -368,7 +374,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
task.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -390,7 +396,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
onChanged: (v) => _toggle(task, v),
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
tooltip: '更多',
|
||||
tooltip: tr('更多'),
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case 'run':
|
||||
@@ -402,23 +408,23 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
}
|
||||
},
|
||||
itemBuilder: (_) => [
|
||||
const PopupMenuItem(value: 'run', child: Text('立即运行')),
|
||||
const PopupMenuItem(value: 'edit', child: Text('编辑')),
|
||||
const PopupMenuItem(value: 'run', child: AppText('立即运行')),
|
||||
const PopupMenuItem(value: 'edit', child: AppText('编辑')),
|
||||
PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: Text('删除',
|
||||
child: AppText('删除',
|
||||
style: TextStyle(color: theme.colorScheme.error)),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(scheduledScheduleText(task),
|
||||
AppText(scheduledScheduleText(task),
|
||||
style: TextStyle(fontSize: 13, color: theme.colorScheme.onSurfaceVariant)),
|
||||
if (task.targetSessionId.isEmpty)
|
||||
const SizedBox.shrink()
|
||||
else
|
||||
Text('发送到现有会话', style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
AppText('发送到现有会话', style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
@@ -435,7 +441,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
Expanded(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
last,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -443,7 +449,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
),
|
||||
),
|
||||
if (next.isNotEmpty)
|
||||
Text(next,
|
||||
AppText(next,
|
||||
style:
|
||||
TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
],
|
||||
@@ -451,7 +457,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
if (task.lastError.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
task.lastError,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -460,7 +466,7 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
AppText(
|
||||
task.modelLabel,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -472,4 +478,4 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user