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
@@ -1,6 +1,8 @@
|
||||
// Scheduled tasks: prompts the server sends on a schedule, into a new session
|
||||
// or an existing one. The wire shape follows the web client
|
||||
// (`/api/projects/:projectId/scheduled-tasks`), which reads the same tasks.
|
||||
import '../l10n.dart';
|
||||
|
||||
class ScheduledTask {
|
||||
final String id;
|
||||
final String name;
|
||||
@@ -164,7 +166,7 @@ class ScheduledTask {
|
||||
|
||||
/// The model line: a fixed choice, or that the run uses the session's.
|
||||
String get modelLabel {
|
||||
if (useDefaults || modelId.isEmpty) return '使用默认模型与智能体';
|
||||
if (useDefaults || modelId.isEmpty) return tr('使用默认模型与智能体');
|
||||
final model = [providerId, modelId].where((s) => s.isNotEmpty).join('/');
|
||||
return agent.isEmpty ? model : '$model · $agent';
|
||||
}
|
||||
@@ -181,33 +183,40 @@ const scheduledTaskKindLabels = {
|
||||
|
||||
/// '每天 09:00', '每周 周一、周三 09:00', '一次性 2026-12-01 09:00', …
|
||||
String scheduledScheduleText(ScheduledTask task) {
|
||||
final times = task.times.isEmpty ? task.time : task.times.join('、');
|
||||
final separator = tr('、');
|
||||
final times = task.times.isEmpty ? task.time : task.times.join(separator);
|
||||
switch (task.kind) {
|
||||
case 'daily':
|
||||
return '每天 ${times.isEmpty ? '--:--' : times}';
|
||||
return trArgs('每天 {0}', [times.isEmpty ? '--:--' : times]);
|
||||
case 'weekly':
|
||||
final days = [
|
||||
for (final day in task.weekdays)
|
||||
if (day >= 0 && day < scheduledWeekdays.length) scheduledWeekdays[day],
|
||||
].join('、');
|
||||
return '每周 ${days.isEmpty ? '未选' : days} ${times.isEmpty ? '--:--' : times}';
|
||||
if (day >= 0 && day < scheduledWeekdays.length)
|
||||
tr(scheduledWeekdays[day]),
|
||||
].join(separator);
|
||||
return trArgs('每周 {0} {1}', [
|
||||
days.isEmpty ? tr('未选') : days,
|
||||
times.isEmpty ? '--:--' : times,
|
||||
]);
|
||||
case 'once':
|
||||
return '一次性 ${task.date.isEmpty ? '未选日期' : task.date} '
|
||||
'${task.time.isEmpty ? '--:--' : task.time}';
|
||||
return trArgs('一次性 {0} {1}', [
|
||||
task.date.isEmpty ? tr('未选日期') : task.date,
|
||||
task.time.isEmpty ? '--:--' : task.time,
|
||||
]);
|
||||
case 'cron':
|
||||
return 'Cron:${task.cron}';
|
||||
return trArgs('Cron:{0}', [task.cron]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
String scheduledStatusLabel(String status) => switch (status) {
|
||||
'success' || 'sent' => '成功',
|
||||
'error' || 'failed' => '错误',
|
||||
'running' => '运行中',
|
||||
'queued' => '已排队',
|
||||
'skipped' => '已跳过',
|
||||
'cancelled' => '已取消',
|
||||
_ => '空闲',
|
||||
'success' || 'sent' => tr('成功'),
|
||||
'error' || 'failed' => tr('错误'),
|
||||
'running' => tr('运行中'),
|
||||
'queued' => tr('已排队'),
|
||||
'skipped' => tr('已跳过'),
|
||||
'cancelled' => tr('已取消'),
|
||||
_ => tr('空闲'),
|
||||
};
|
||||
|
||||
/// How far away a moment is, in the words the web client uses.
|
||||
@@ -219,21 +228,24 @@ String scheduledRelativeTime(int milliseconds) {
|
||||
const hour = 60 * minute;
|
||||
const day = 24 * hour;
|
||||
final future = diff >= 0;
|
||||
if (abs < minute) return future ? '不到 1 分钟后' : '刚刚';
|
||||
if (abs < minute) return future ? tr('不到 1 分钟后') : tr('刚刚');
|
||||
if (abs < hour) {
|
||||
final m = (abs / minute).round();
|
||||
return future ? '$m 分钟后' : '$m 分钟前';
|
||||
return future
|
||||
? trArgs('{0} 分钟后', [m])
|
||||
: trArgs('{0} 分钟前', [m]);
|
||||
}
|
||||
if (abs < day) {
|
||||
final h = abs ~/ hour;
|
||||
final m = ((abs % hour) / minute).round();
|
||||
final body = m > 0 ? '$h 小时 $m 分钟' : '$h 小时';
|
||||
return future ? '$body后' : '$body前';
|
||||
final body =
|
||||
m > 0 ? trArgs('{0} 小时 {1} 分钟', [h, m]) : trArgs('{0} 小时', [h]);
|
||||
return future ? trArgs('{0}后', [body]) : trArgs('{0}前', [body]);
|
||||
}
|
||||
final d = abs ~/ day;
|
||||
final h = ((abs % day) / hour).round();
|
||||
final body = h > 0 ? '$d 天 $h 小时' : '$d 天';
|
||||
return future ? '$body后' : '$body前';
|
||||
final body = h > 0 ? trArgs('{0} 天 {1} 小时', [d, h]) : trArgs('{0} 天', [d]);
|
||||
return future ? trArgs('{0}后', [body]) : trArgs('{0}前', [body]);
|
||||
}
|
||||
|
||||
String scheduledClock(int milliseconds) {
|
||||
|
||||
Reference in new issue
Block a user