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
+5
-3
@@ -3,6 +3,8 @@ library;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import '../l10n.dart';
|
||||
|
||||
class ModelRef {
|
||||
final String id;
|
||||
final String providerId;
|
||||
@@ -905,9 +907,9 @@ class AgentMemoryEntry {
|
||||
);
|
||||
|
||||
String get typeLabel => switch (type) {
|
||||
'preference' => '偏好',
|
||||
'reference' => '参考',
|
||||
_ => '事实',
|
||||
'preference' => tr('偏好'),
|
||||
'reference' => tr('参考'),
|
||||
_ => tr('事实'),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import '../l10n.dart';
|
||||
import '../version.dart';
|
||||
import 'relay_tunnel.dart';
|
||||
import 'transport.dart';
|
||||
@@ -83,7 +84,7 @@ class RelayTransport implements Transport {
|
||||
final bytes = await response.body
|
||||
.fold<List<int>>(<int>[], (all, chunk) => all..addAll(chunk));
|
||||
if (response.status < 200 || response.status >= 300) {
|
||||
throw RelayTunnelException('无法获取 WebSocket 令牌(${response.status})');
|
||||
throw RelayTunnelException(trArgs('无法获取 WebSocket 令牌({0})', [response.status]));
|
||||
}
|
||||
try {
|
||||
final decoded = jsonDecode(utf8.decode(bytes, allowMalformed: true));
|
||||
|
||||
+18
-15
@@ -12,6 +12,7 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../l10n.dart';
|
||||
import 'relay_crypto.dart';
|
||||
import 'transport.dart';
|
||||
|
||||
@@ -132,11 +133,11 @@ class RelayTunnel {
|
||||
try {
|
||||
decoded = jsonDecode(utf8.decode(payload));
|
||||
} catch (_) {
|
||||
finish(error: const RelayTunnelException('响应头无效'));
|
||||
finish(error: RelayTunnelException(tr('响应头无效')));
|
||||
return;
|
||||
}
|
||||
if (decoded is! Map) {
|
||||
finish(error: const RelayTunnelException('响应头无效'));
|
||||
finish(error: RelayTunnelException(tr('响应头无效')));
|
||||
return;
|
||||
}
|
||||
final status = (decoded['status'] as num?)?.toInt() ?? 0;
|
||||
@@ -161,7 +162,7 @@ class RelayTunnel {
|
||||
controller.close();
|
||||
break;
|
||||
case RelayFrameType.streamAbort:
|
||||
var reason = '传输被中断';
|
||||
var reason = tr('传输被中断');
|
||||
try {
|
||||
final decoded = jsonDecode(utf8.decode(payload));
|
||||
if (decoded is Map && decoded['reason'] is String) {
|
||||
@@ -268,7 +269,7 @@ class RelayTunnel {
|
||||
ws = await WebSocket.connect(uri.toString(), customClient: _http)
|
||||
.timeout(_connectTimeout);
|
||||
} catch (error) {
|
||||
throw RelayTunnelException('无法连接 Relay:$error');
|
||||
throw RelayTunnelException(trArgs('无法连接 Relay:{0}', [error]));
|
||||
}
|
||||
final channel = _RelayChannel(ws);
|
||||
final ready = Completer<void>();
|
||||
@@ -325,7 +326,7 @@ class RelayTunnel {
|
||||
deadline?.cancel();
|
||||
ready.complete();
|
||||
} catch (error) {
|
||||
closeWith(RelayTunnelException('密钥协商失败:$error'));
|
||||
closeWith(RelayTunnelException(trArgs('密钥协商失败:{0}', [error])));
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -333,7 +334,7 @@ class RelayTunnel {
|
||||
// After the channel is up the host may repeat `ready` for a retried
|
||||
// hello; anything else plaintext is a protocol violation.
|
||||
if (raw.contains('"ready"')) return;
|
||||
closeWith(const RelayTunnelException('握手后收到明文帧'));
|
||||
closeWith(RelayTunnelException(tr('握手后收到明文帧')));
|
||||
return;
|
||||
}
|
||||
if (raw is! List<int>) return;
|
||||
@@ -343,23 +344,24 @@ class RelayTunnel {
|
||||
final plaintext = channel.decryptor.decrypt(Uint8List.fromList(raw));
|
||||
channel.handlePlaintext(plaintext);
|
||||
} catch (error) {
|
||||
closeWith(RelayTunnelException('解密失败:$error'));
|
||||
closeWith(RelayTunnelException(trArgs('解密失败:{0}', [error])));
|
||||
}
|
||||
}
|
||||
|
||||
subscription = ws.listen(
|
||||
onData,
|
||||
onError: (Object error) => closeWith(RelayTunnelException('Relay 连接出错:$error')),
|
||||
onError: (Object error) => closeWith(RelayTunnelException(trArgs('Relay 连接出错:{0}', [error]))),
|
||||
onDone: () {
|
||||
if (!finished) {
|
||||
closeWith(RelayTunnelException(
|
||||
'Relay 连接已关闭(${ws.closeCode ?? '-'} ${ws.closeReason ?? ''})'));
|
||||
closeWith(RelayTunnelException(trArgs(
|
||||
'Relay 连接已关闭({0} {1})',
|
||||
[ws.closeCode ?? '-', ws.closeReason ?? ''])));
|
||||
}
|
||||
},
|
||||
cancelOnError: true,
|
||||
);
|
||||
channel.onClosed = () =>
|
||||
closeWith(const RelayTunnelException('Relay 连接已关闭'));
|
||||
closeWith(RelayTunnelException(tr('Relay 连接已关闭')));
|
||||
|
||||
void sendHello() {
|
||||
if (finished) return;
|
||||
@@ -371,13 +373,14 @@ class RelayTunnel {
|
||||
sendHello();
|
||||
helloTimer = Timer.periodic(const Duration(seconds: 1), (_) => sendHello());
|
||||
deadline = Timer(_handshakeTimeout, () {
|
||||
closeWith(const RelayTunnelException('Relay 握手超时'));
|
||||
closeWith(RelayTunnelException(tr('Relay 握手超时')));
|
||||
});
|
||||
|
||||
await ready.future;
|
||||
if (channel.dead) {
|
||||
throw RelayTunnelException(
|
||||
'Relay 连接已关闭(${ws.closeCode ?? '-'} ${ws.closeReason ?? ''})');
|
||||
throw RelayTunnelException(trArgs(
|
||||
'Relay 连接已关闭({0} {1})',
|
||||
[ws.closeCode ?? '-', ws.closeReason ?? '']));
|
||||
}
|
||||
channel.startKeepAlive();
|
||||
return channel;
|
||||
@@ -601,7 +604,7 @@ class _RelaySocket implements TransportSocket {
|
||||
_finish();
|
||||
break;
|
||||
case RelayFrameType.streamAbort:
|
||||
_finish(error: const RelayTunnelException('WebSocket 子流被中断'));
|
||||
_finish(error: RelayTunnelException(tr('WebSocket 子流被中断')));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+4
-2
@@ -1,6 +1,7 @@
|
||||
// Background commands of a session (opencode's shells), as the first-party
|
||||
// client shows them above the composer: the command, how long it has been
|
||||
// running, and a way to stop it.
|
||||
import '../l10n.dart';
|
||||
import 'models.dart';
|
||||
|
||||
/// One running (or just ended) shell. `id` is the shell id opencode created
|
||||
@@ -238,10 +239,11 @@ const shellOutputTailBytes = 256 * 1024;
|
||||
/// `12秒`, `3分05秒`, `1:02:03`: the running clock a task row shows.
|
||||
String formatElapsed(int milliseconds) {
|
||||
final secs = milliseconds <= 0 ? 0 : milliseconds ~/ 1000;
|
||||
if (secs < 60) return '$secs秒';
|
||||
if (secs < 60) return trArgs('{0}秒', [secs]);
|
||||
if (secs < 3600) {
|
||||
final rest = secs % 60;
|
||||
return '${secs ~/ 60}分${rest.toString().padLeft(2, '0')}秒';
|
||||
return trArgs(
|
||||
'{0}分{1}秒', [secs ~/ 60, rest.toString().padLeft(2, '0')]);
|
||||
}
|
||||
final hours = secs ~/ 3600;
|
||||
final mins = (secs % 3600) ~/ 60;
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'dart:io';
|
||||
|
||||
import 'package:socks5_proxy/socks_client.dart';
|
||||
|
||||
import '../l10n.dart';
|
||||
|
||||
/// One request: a method, a path relative to the server root, its query, the
|
||||
/// headers already decided by [Client] (auth, directory, accept, …) and an
|
||||
/// optional complete body.
|
||||
@@ -96,7 +98,7 @@ class CancelToken {
|
||||
class DownloadCancelled implements Exception {
|
||||
const DownloadCancelled();
|
||||
@override
|
||||
String toString() => '下载已取消';
|
||||
String toString() => tr('下载已取消');
|
||||
}
|
||||
|
||||
/// A proxy as configured: an HTTP CONNECT proxy, or a SOCKS5 one.
|
||||
@@ -118,13 +120,14 @@ ProxyConfig? parseProxy(String? raw) {
|
||||
if (!normalized.contains('://')) normalized = 'http://$normalized';
|
||||
final uri = Uri.tryParse(normalized);
|
||||
if (uri == null || uri.host.isEmpty) {
|
||||
throw ArgumentError('代理地址无效:$raw');
|
||||
throw ArgumentError(trArgs('代理地址无效:{0}', [raw]));
|
||||
}
|
||||
final scheme = uri.scheme.toLowerCase();
|
||||
final socks = scheme == 'socks' || scheme == 'socks5' || scheme == 'socks5h';
|
||||
final http = scheme == 'http' || scheme == 'https';
|
||||
if (!socks && !http) {
|
||||
throw ArgumentError('不支持的代理协议:$scheme(支持 http、https、socks5、socks5h)');
|
||||
throw ArgumentError(trArgs(
|
||||
'不支持的代理协议:{0}(支持 http、https、socks5、socks5h)', [scheme]));
|
||||
}
|
||||
String? user;
|
||||
String? pass;
|
||||
@@ -190,7 +193,7 @@ class DirectTransport implements Transport {
|
||||
if (_proxyAddress != null) return _proxyAddress!;
|
||||
final addresses = await InternetAddress.lookup(_proxyConfig!.host);
|
||||
if (addresses.isEmpty) {
|
||||
throw const SocketException('无法解析代理主机');
|
||||
throw SocketException(tr('无法解析代理主机'));
|
||||
}
|
||||
return _proxyAddress = addresses.first;
|
||||
}
|
||||
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
// The app speaks Chinese and English. Our own text is written in Chinese and
|
||||
// translated by lookup: `tr('保存')` in code that builds strings, `AppText`
|
||||
// for the many Text leaves. `设置 → 常规 → 语言` chooses between the system
|
||||
// language, Chinese and English; Chinese is the fallback for a missing entry,
|
||||
// so a new string never disappears.
|
||||
import 'dart:async';
|
||||
import 'dart:ui' show PlatformDispatcher;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'l10n/en_chat.dart';
|
||||
import 'l10n/en_core.dart';
|
||||
import 'l10n/en_servers.dart';
|
||||
import 'l10n/en_sessions.dart';
|
||||
import 'l10n/en_settings.dart';
|
||||
import 'l10n/en_tools.dart';
|
||||
|
||||
/// Every English string, keyed by the Chinese text it replaces.
|
||||
final Map<String, String> englishStrings = <String, String>{
|
||||
...enCore,
|
||||
...enChat,
|
||||
...enSessions,
|
||||
...enSettings,
|
||||
...enTools,
|
||||
...enServers,
|
||||
};
|
||||
|
||||
enum AppLanguage {
|
||||
system('跟随系统', 'System'),
|
||||
zh('中文', '中文'),
|
||||
en('English', 'English');
|
||||
|
||||
/// What the choice reads as, in each language.
|
||||
final String zhLabel;
|
||||
final String enLabel;
|
||||
|
||||
const AppLanguage(this.zhLabel, this.enLabel);
|
||||
|
||||
String labelFor(bool english) => english ? enLabel : zhLabel;
|
||||
}
|
||||
|
||||
/// The language the UI is drawn in, and the lookup behind [tr] and [AppText].
|
||||
class L10n extends ChangeNotifier {
|
||||
L10n._();
|
||||
static final L10n instance = L10n._();
|
||||
|
||||
/// Chinese until [ensureLoaded] has read the stored choice: tests and the
|
||||
/// first frame before the app starts never see a half-changed language.
|
||||
AppLanguage _choice = AppLanguage.zh;
|
||||
|
||||
AppLanguage get choice => _choice;
|
||||
|
||||
/// Reads the saved choice. No saved choice means follow the system, which
|
||||
/// is what a fresh install does.
|
||||
Future<void> ensureLoaded() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_choice = switch (prefs.getString('language')) {
|
||||
'zh' => AppLanguage.zh,
|
||||
'en' => AppLanguage.en,
|
||||
_ => AppLanguage.system,
|
||||
};
|
||||
} catch (_) {
|
||||
_choice = AppLanguage.system;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> setLanguage(AppLanguage choice) async {
|
||||
apply(choice);
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (choice == AppLanguage.system) {
|
||||
await prefs.remove('language');
|
||||
} else {
|
||||
await prefs.setString('language', choice.name);
|
||||
}
|
||||
} catch (_) {
|
||||
// The choice still holds for this run.
|
||||
}
|
||||
}
|
||||
|
||||
/// Changes the language without touching the stored choice (tests, and the
|
||||
/// first resolve before prefs are read).
|
||||
void apply(AppLanguage choice) {
|
||||
if (_choice == choice) return;
|
||||
_choice = choice;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Locale get locale => switch (_choice) {
|
||||
AppLanguage.zh => const Locale('zh', 'CN'),
|
||||
AppLanguage.en => const Locale('en'),
|
||||
AppLanguage.system =>
|
||||
_systemIsChinese ? const Locale('zh', 'CN') : const Locale('en'),
|
||||
};
|
||||
|
||||
bool get _systemIsChinese {
|
||||
try {
|
||||
return PlatformDispatcher.instance.locale.languageCode == 'zh';
|
||||
} catch (_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool get isEnglish => locale.languageCode == 'en';
|
||||
|
||||
/// The English text for [zh], or [zh] when none is written yet.
|
||||
String tr(String zh) => isEnglish ? (englishStrings[zh] ?? zh) : zh;
|
||||
|
||||
/// Same, for text built from parts: `trArgs('{0} 个子代理', [n])`. The
|
||||
/// Chinese template is filled as written; English entries use the same
|
||||
/// `{0}`, `{1}` placeholders.
|
||||
String trArgs(String template, [List<Object?> args = const []]) {
|
||||
var out = isEnglish ? (englishStrings[template] ?? template) : template;
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
out = out.replaceAll('{$i}', '${args[i] ?? ''}');
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// A system language change reaches the app while it runs; the choice
|
||||
/// "follow the system" then has to redraw.
|
||||
void systemLocaleChanged() {
|
||||
if (_choice == AppLanguage.system) notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
String tr(String zh) => L10n.instance.tr(zh);
|
||||
|
||||
String trArgs(String template, [List<Object?> args = const []]) =>
|
||||
L10n.instance.trArgs(template, args);
|
||||
|
||||
/// [Text] that goes through the same lookup. It is const-constructible, so a
|
||||
/// tree does not have to give up `const` to be translated. Content that comes
|
||||
/// from the server (message text, titles) is drawn with plain [Text]: only
|
||||
/// our own strings are keys.
|
||||
class AppText extends StatelessWidget {
|
||||
final String data;
|
||||
final TextStyle? style;
|
||||
final StrutStyle? strutStyle;
|
||||
final TextAlign? textAlign;
|
||||
final TextDirection? textDirection;
|
||||
final Locale? locale;
|
||||
final bool? softWrap;
|
||||
final TextOverflow? overflow;
|
||||
final TextScaler? textScaler;
|
||||
final int? maxLines;
|
||||
final String? semanticsLabel;
|
||||
final TextWidthBasis? textWidthBasis;
|
||||
final TextHeightBehavior? textHeightBehavior;
|
||||
final Color? selectionColor;
|
||||
|
||||
const AppText(
|
||||
this.data, {
|
||||
super.key,
|
||||
this.style,
|
||||
this.strutStyle,
|
||||
this.textAlign,
|
||||
this.textDirection,
|
||||
this.locale,
|
||||
this.softWrap,
|
||||
this.overflow,
|
||||
this.textScaler,
|
||||
this.maxLines,
|
||||
this.semanticsLabel,
|
||||
this.textWidthBasis,
|
||||
this.textHeightBehavior,
|
||||
this.selectionColor,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Reading the resolved locale makes this widget depend on it: when the
|
||||
// language changes, every AppText — including a const one whose widget
|
||||
// instance the parent build reuses — is rebuilt in the new language.
|
||||
final resolved = locale ?? Localizations.localeOf(context);
|
||||
return Text(
|
||||
tr(data),
|
||||
style: style,
|
||||
strutStyle: strutStyle,
|
||||
textAlign: textAlign,
|
||||
textDirection: textDirection,
|
||||
locale: resolved,
|
||||
softWrap: softWrap,
|
||||
overflow: overflow,
|
||||
textScaler: textScaler,
|
||||
maxLines: maxLines,
|
||||
semanticsLabel: semanticsLabel,
|
||||
textWidthBasis: textWidthBasis,
|
||||
textHeightBehavior: textHeightBehavior,
|
||||
selectionColor: selectionColor,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
// English strings for one part of the app; merged into L10n's table. Keys are
|
||||
// the Chinese text the code writes, including {0}, {1} placeholders for text
|
||||
// that is built from parts.
|
||||
const Map<String, String> enChat = {
|
||||
'附件不能超过 10MB': 'Attachments cannot be larger than 10 MB',
|
||||
// Chat app bar and transcript
|
||||
'返回父会话': 'Back to parent session',
|
||||
'会话': 'Session',
|
||||
'文件': 'Files',
|
||||
'重试': 'Retry',
|
||||
'载入更早的消息': 'Load earlier messages',
|
||||
'正在思考…': 'Thinking…',
|
||||
'此会话由 Lead 管理,接管后才能继续。':
|
||||
'This session is managed by a Lead; take it over to continue.',
|
||||
'无法向子智能体会话发送提示。': 'Cannot send prompts to a subagent session.',
|
||||
'无法打开子代理会话': 'Cannot open the subagent session',
|
||||
|
||||
// Pending prompts and message actions
|
||||
'📎 {0} 个附件': '📎 {0} attachments',
|
||||
'附件': 'Attachment',
|
||||
'未发送': 'Not sent',
|
||||
'正在转入当前回合…': 'Joining this turn…',
|
||||
'已排队,本轮结束后发送': 'Queued; sends after this turn',
|
||||
'改为排队': 'Queue instead',
|
||||
'转为转向': 'Steer instead',
|
||||
'撤回': 'Withdraw',
|
||||
'复制': 'Copy',
|
||||
'复制消息': 'Copy message',
|
||||
'撤回此消息及之后': 'Withdraw this and later messages',
|
||||
'从这里分叉': 'Fork from here',
|
||||
'复制回答': 'Copy answer',
|
||||
'撤回消息?': 'Withdraw message?',
|
||||
'这条消息及其之后的内容会从会话中删除,且无法恢复。':
|
||||
'This message and everything after it will be removed from the session '
|
||||
'and cannot be recovered.',
|
||||
'没有可复制的文字': 'Nothing to copy',
|
||||
'已复制': 'Copied',
|
||||
|
||||
// Tool steps and activity
|
||||
'思考': 'Thinking',
|
||||
'运行': 'Run',
|
||||
'读取': 'Read',
|
||||
'写入': 'Write',
|
||||
'编辑': 'Edit',
|
||||
'补丁': 'Patch',
|
||||
'搜索': 'Search',
|
||||
'列出': 'List',
|
||||
'抓取': 'Fetch',
|
||||
'任务': 'Task',
|
||||
'子代理': 'Subagent',
|
||||
'技能': 'Skill',
|
||||
'生成图片': 'Generate image',
|
||||
'工具': 'Tool',
|
||||
'后台': 'Background',
|
||||
'思考中…': 'Thinking…',
|
||||
'思考过程': 'Thought process',
|
||||
'有步骤失败 · {0} 次工具调用': 'A step failed · {0} tool calls',
|
||||
'执行中 · {0} 次工具调用': 'Running · {0} tool calls',
|
||||
'已完成 · {0} 次工具调用': 'Done · {0} tool calls',
|
||||
'正在{0}': '{0} in progress',
|
||||
'正在回复': 'Replying',
|
||||
'思考中': 'Thinking',
|
||||
'{0} 秒': '{0}s',
|
||||
'输出较大,正在载入…': 'Large output, loading…',
|
||||
'无输出': 'No output',
|
||||
'无内容': 'No content',
|
||||
|
||||
// Errors
|
||||
'未知错误': 'Unknown error',
|
||||
'压缩失败:{0}': 'Compaction failed: {0}',
|
||||
'OpenCode 发送消息失败,正在重试:{0}':
|
||||
'OpenCode could not send the message; retrying: {0}',
|
||||
'OpenCode 发送消息失败:{0}': 'OpenCode could not send the message: {0}',
|
||||
'模型的认证失败,请在服务端重新登录或检查 API Key。':
|
||||
'The model failed to authenticate. Sign in again on the server or check '
|
||||
'the API key.',
|
||||
'本轮已停止。': 'This turn was stopped.',
|
||||
'用户停止了这条命令。': 'You stopped this command.',
|
||||
'停止失败:{0}': 'Could not stop: {0}',
|
||||
|
||||
// Compaction
|
||||
'正在压缩对话': 'Compacting conversation',
|
||||
'对话已压缩': 'Conversation compacted',
|
||||
'隐藏摘要': 'Hide summary',
|
||||
'显示摘要': 'Show summary',
|
||||
'正在生成摘要…': 'Generating summary…',
|
||||
'(摘要为空)': '(No summary)',
|
||||
'收起详情': 'Hide details',
|
||||
'显示详情': 'Show details',
|
||||
|
||||
// Composer
|
||||
'生成中,仍可输入…': 'Generating; you can still type…',
|
||||
'发消息…': 'Send a message…',
|
||||
'添加附件': 'Add attachment',
|
||||
'停止': 'Stop',
|
||||
'发送': 'Send',
|
||||
'选择失败:{0}': 'Selection failed: {0}',
|
||||
'发送方式': 'Delivery',
|
||||
'转向当前回合': 'Steer into this turn',
|
||||
'在下一步加入,工作继续': 'Join at the next step; work continues',
|
||||
'排队': 'Queue',
|
||||
'等本轮结束后发送': 'Send after this turn ends',
|
||||
|
||||
// Permissions and forms
|
||||
'请求权限: {0}': 'Permission requested: {0}',
|
||||
'、': ', ',
|
||||
'允许一次': 'Allow once',
|
||||
'总是允许': 'Always allow',
|
||||
'拒绝': 'Deny',
|
||||
'取消': 'Cancel',
|
||||
'请填写:{0}': 'Required: {0}',
|
||||
'请选择': 'Choose one',
|
||||
'其他…': 'Other…',
|
||||
'{0}({1})': '{0} ({1})',
|
||||
|
||||
// Usage sheet
|
||||
'上下文占用': 'Context usage',
|
||||
'模型': 'Model',
|
||||
'已用 tokens': 'Tokens used',
|
||||
'上下文上限': 'Context limit',
|
||||
'输出预留': 'Reserved output',
|
||||
'占用': 'Usage',
|
||||
'本轮费用': 'Turn cost',
|
||||
'输出预留按最多 32K tokens 计算,与官方客户端一致。':
|
||||
'Reserved output assumes at most 32K tokens, matching the official '
|
||||
'client.',
|
||||
|
||||
// Images
|
||||
'图片': 'Image',
|
||||
'图片无法显示': 'Cannot display image',
|
||||
'无效的 data URL': 'Invalid data URL',
|
||||
'不支持的 data URL': 'Unsupported data URL',
|
||||
'图片加载失败:{0}': 'Could not load image: {0}',
|
||||
'无法预览:{0}': 'Cannot preview: {0}',
|
||||
'关闭': 'Close',
|
||||
|
||||
// Background commands
|
||||
'正在执行 {0} 条命令': 'Running {0} commands',
|
||||
'已结束': 'Ended',
|
||||
'停止中…': 'Stopping…',
|
||||
'读取输出…': 'Reading output…',
|
||||
'等待输出…': 'Waiting for output…',
|
||||
'没有输出': 'No output',
|
||||
'回到最新': 'Jump to latest',
|
||||
'已复制输出': 'Output copied',
|
||||
'后台输出': 'Background output',
|
||||
'运行中': 'Running',
|
||||
'查看全部': 'View all',
|
||||
'停止这个任务?': 'Stop this task?',
|
||||
'读取输出失败:{0}': 'Could not read output: {0}',
|
||||
|
||||
// Slash palette
|
||||
'压缩': 'Compact',
|
||||
'初始化': 'Init',
|
||||
'审查': 'Review',
|
||||
'目标': 'Goal',
|
||||
'新建扩展': 'New extension',
|
||||
'权限': 'Permission',
|
||||
'计划': 'Plan',
|
||||
'反馈': 'Feedback',
|
||||
'没有可用的指令': 'No commands available',
|
||||
'这个目录还没有注册指令或技能':
|
||||
'This directory has no commands or skills yet',
|
||||
|
||||
// Model picker and controls
|
||||
'选择模型': 'Choose model',
|
||||
'正在载入模型…': 'Loading models…',
|
||||
'没有结果': 'No results',
|
||||
'收藏': 'Favorites',
|
||||
'取消收藏': 'Remove from favorites',
|
||||
'最近': 'Recent',
|
||||
'其它': 'Other',
|
||||
'{0} 上下文': '{0} context',
|
||||
'思考强度': 'Thinking effort',
|
||||
'完成': 'Done',
|
||||
'模式': 'Mode',
|
||||
'先规划,不改动文件': 'Plan first without changing files',
|
||||
'直接构建': 'Build directly',
|
||||
|
||||
// Diff view
|
||||
'文件 {0}': 'File {0}',
|
||||
'仅显示前 {0} 行,共 {1} 行': 'Showing the first {0} of {1} lines',
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
// English strings for one part of the app; merged into L10n's table. Keys are
|
||||
// the Chinese text the code writes, including {0}, {1} placeholders for text
|
||||
// that is built from parts.
|
||||
const Map<String, String> enCore = {
|
||||
// state.dart
|
||||
'未连接': 'Not connected',
|
||||
'保存失败:{0}': 'Could not save: {0}',
|
||||
'配对链接无效或已过期': 'Pairing link is invalid or expired',
|
||||
'服务器没有返回设备令牌': 'Server did not return a device token',
|
||||
'配对失败': 'Pairing failed',
|
||||
'Relay 服务器': 'Relay server',
|
||||
'配对已失效,请重新配对': 'Pairing expired, please pair again',
|
||||
'需要密码或已保存的凭据': 'Password or saved credentials required',
|
||||
'登录成功但没有返回令牌': 'Signed in but no token was returned',
|
||||
'密码错误,请重试': 'Wrong password, try again',
|
||||
'连接超时:检查服务器与代理地址':
|
||||
'Connection timed out: check the server and proxy address',
|
||||
'连接被拒绝:服务器或代理未启动,或端口不对':
|
||||
'Connection refused: server or proxy not running, or wrong port',
|
||||
'无法解析地址:检查服务器或代理主机名':
|
||||
'Could not resolve address: check the server or proxy hostname',
|
||||
'网络不可达': 'Network unreachable',
|
||||
'连接被断开:检查代理是否可用':
|
||||
'Connection closed: check whether the proxy works',
|
||||
'网络错误:{0}': 'Network error: {0}',
|
||||
'使用 AI 压缩会话历史以减少上下文大小':
|
||||
'Use AI to compact the session history and reduce context size',
|
||||
'聊天': 'Chat',
|
||||
'无法打开子代理会话:{0}': 'Could not open the subagent session: {0}',
|
||||
'未连接服务器': 'Not connected to a server',
|
||||
'服务器没有提供聊天目录': 'Server did not provide a chat directory',
|
||||
'无法创建聊天目录:{0}': 'Could not create the chat directory: {0}',
|
||||
'连接中断,正在重连…': 'Connection lost, reconnecting…',
|
||||
'附件': 'Attachment',
|
||||
|
||||
// api/relay_tunnel.dart
|
||||
'响应头无效': 'Invalid response headers',
|
||||
'传输被中断': 'Transfer interrupted',
|
||||
'无法连接 Relay:{0}': 'Could not connect to the relay: {0}',
|
||||
'密钥协商失败:{0}': 'Key exchange failed: {0}',
|
||||
'握手后收到明文帧': 'Received a plaintext frame after the handshake',
|
||||
'解密失败:{0}': 'Decryption failed: {0}',
|
||||
'Relay 连接出错:{0}': 'Relay connection error: {0}',
|
||||
'Relay 连接已关闭({0} {1})': 'Relay connection closed ({0} {1})',
|
||||
'Relay 连接已关闭': 'Relay connection closed',
|
||||
'Relay 握手超时': 'Relay handshake timed out',
|
||||
'WebSocket 子流被中断': 'WebSocket substream interrupted',
|
||||
|
||||
// pets/pet_library.dart
|
||||
'文件为空': 'File is empty',
|
||||
'宠物包不能超过 40MB': 'Pet pack cannot exceed 40 MB',
|
||||
'不是有效的 zip 文件': 'Not a valid zip file',
|
||||
'压缩包里没有 pack.json': 'The archive has no pack.json',
|
||||
'pack.json 不是有效的宠物包': 'pack.json is not a valid pet pack',
|
||||
'pack.json 缺少动画或状态': 'pack.json is missing animations or states',
|
||||
'解压后超过 60MB': 'Extracted size exceeds 60 MB',
|
||||
'动画 {0} 没有精灵图': 'Animation {0} has no sprite sheet',
|
||||
'缺少精灵图 {0}': 'Missing sprite sheet {0}',
|
||||
|
||||
// model_prefs.dart
|
||||
'默认': 'Default',
|
||||
'无': 'None',
|
||||
'极低': 'Minimal',
|
||||
'低': 'Low',
|
||||
'中': 'Medium',
|
||||
'高': 'High',
|
||||
'极高': 'Extra high',
|
||||
|
||||
// terminal_state.dart
|
||||
'终端 {0}': 'Terminal {0}',
|
||||
'终端 1': 'Terminal 1',
|
||||
'终端': 'Terminal',
|
||||
'已退出': 'Exited',
|
||||
'退出码 {0}': 'Exit code {0}',
|
||||
'终端连接失败': 'Terminal connection failed',
|
||||
|
||||
// api/transport.dart
|
||||
'下载已取消': 'Download cancelled',
|
||||
'代理地址无效:{0}': 'Invalid proxy address: {0}',
|
||||
'不支持的代理协议:{0}(支持 http、https、socks5、socks5h)':
|
||||
'Unsupported proxy protocol: {0} (supported: http, https, socks5, socks5h)',
|
||||
'无法解析代理主机': 'Could not resolve the proxy host',
|
||||
|
||||
// api/models.dart
|
||||
'偏好': 'Preference',
|
||||
'参考': 'Reference',
|
||||
'事实': 'Fact',
|
||||
|
||||
// api/shells.dart
|
||||
'{0}秒': '{0}s',
|
||||
'{0}分{1}秒': '{0}m{1}s',
|
||||
|
||||
// api/relay_transport.dart
|
||||
'无法获取 WebSocket 令牌({0})': 'Could not get a WebSocket token ({0})',
|
||||
};
|
||||
@@ -0,0 +1,71 @@
|
||||
// English strings for one part of the app; merged into L10n's table. Keys are
|
||||
// the Chinese text the code writes, including {0}, {1} placeholders for text
|
||||
// that is built from parts.
|
||||
const Map<String, String> enServers = {
|
||||
'需要密码': 'Password',
|
||||
// Server list
|
||||
'连接你的 OpenChamber 服务器': 'Connect to your OpenChamber server',
|
||||
'添加服务器': 'Add server',
|
||||
'配对链接': 'Pairing link',
|
||||
'经由 Relay · {0}': 'Via Relay · {0}',
|
||||
'经由 {0}': 'Via {0}',
|
||||
'已连接': 'Connected',
|
||||
'连接': 'Connect',
|
||||
'编辑': 'Edit',
|
||||
'删除': 'Delete',
|
||||
'删除服务器?': 'Delete server?',
|
||||
'“{0}”将从列表移除,设备令牌也会删除。':
|
||||
'“{0}” will be removed from the list, and its device token will be deleted.',
|
||||
'取消': 'Cancel',
|
||||
'配对失败': 'Pairing failed',
|
||||
|
||||
// Connect form
|
||||
'连接 {0}': 'Connect to {0}',
|
||||
'名称': 'Name',
|
||||
'如 我的电脑': 'e.g. My computer',
|
||||
'通过 Relay 连接': 'Connect through Relay',
|
||||
'端到端加密;服务器与设备令牌保持不变':
|
||||
'End-to-end encrypted; the server and device token stay the same',
|
||||
'服务器地址': 'Server address',
|
||||
'代理(可选)': 'Proxy (optional)',
|
||||
'http://… 或 socks5://…': 'http://… or socks5://…',
|
||||
'自签证书指纹(可选)': 'Self-signed certificate fingerprint (optional)',
|
||||
'SHA-256 十六进制': 'SHA-256 hex',
|
||||
'信任自签名证书': 'Trust self-signed certificates',
|
||||
'密码(如果需要)': 'Password (if required)',
|
||||
'服务器密码;服务器未设置可留空':
|
||||
'Server password; leave empty if the server has none',
|
||||
|
||||
// Pairing dialog
|
||||
'在 OpenChamber 网页端打开「连接设备」,粘贴链接或直接扫描二维码。'
|
||||
'链接里带一次性密钥,以及直连地址或私有 Relay。':
|
||||
'In the OpenChamber web app, open “Connect a device”, then paste the link '
|
||||
'or scan the QR code. The link carries a one-time key and either a '
|
||||
'direct address or a private Relay.',
|
||||
'扫码': 'Scan QR code',
|
||||
'粘贴': 'Paste',
|
||||
'配对并连接': 'Pair and connect',
|
||||
|
||||
// QR scanner
|
||||
'没有可用的相机': 'No camera available',
|
||||
'没有收到相机画面,请关闭后重试':
|
||||
'No camera frames received; close and try again',
|
||||
'还没识别到二维码,试着靠近一点或让二维码占满取景框':
|
||||
'No QR code yet; move closer or fill the frame with the code',
|
||||
'需要相机权限才能扫码。请在系统设置里允许 OpenChamber 使用相机。':
|
||||
'Camera permission is required to scan. Allow OpenChamber to use the '
|
||||
'camera in system settings.',
|
||||
'无法打开相机:{0}': 'Could not open the camera: {0}',
|
||||
'这不是 OpenChamber 配对二维码': 'This is not an OpenChamber pairing QR code',
|
||||
'二维码解码出错,请重试': 'Could not decode the QR code; try again',
|
||||
'这个相机不支持手电筒': 'This camera does not support the flashlight',
|
||||
'重试': 'Retry',
|
||||
'关闭': 'Close',
|
||||
'手电筒': 'Flashlight',
|
||||
'把配对二维码放进框内': 'Put the pairing QR code inside the frame',
|
||||
'在 OpenChamber 网页端打开「连接设备」,选择二维码':
|
||||
'In the OpenChamber web app, open “Connect a device” and choose the QR '
|
||||
'code',
|
||||
'{0} · 已扫描 {1} 帧 / 解码 {2} 次':
|
||||
'{0} · {1} frames scanned / {2} decode attempts',
|
||||
};
|
||||
@@ -0,0 +1,167 @@
|
||||
// English strings for one part of the app; merged into L10n's table. Keys are
|
||||
// the Chinese text the code writes, including {0}, {1} placeholders for text
|
||||
// that is built from parts.
|
||||
const Map<String, String> enSessions = {
|
||||
'选择一个会话': 'Choose a session',
|
||||
'打开会话列表': 'Open the session list',
|
||||
// ------------------------------------------------------------ knowledge
|
||||
'这个会话没有关联目录': 'This session has no directory',
|
||||
'搜索笔记、待办与计划': 'Search notes, todos, and plans',
|
||||
'搜索笔记、待办、计划与记忆': 'Search notes, todos, plans, and memory',
|
||||
'刷新': 'Refresh',
|
||||
'笔记': 'Notes',
|
||||
'待办': 'Todos',
|
||||
'计划': 'Plans',
|
||||
'记忆': 'Memory',
|
||||
'重试': 'Retry',
|
||||
'{0} 条笔记': '{0} notes',
|
||||
'新建笔记': 'New note',
|
||||
'还没有笔记': 'No notes yet',
|
||||
'没有匹配的笔记': 'No matching notes',
|
||||
'编辑': 'Edit',
|
||||
'取消置顶': 'Unpin',
|
||||
'置顶': 'Pin',
|
||||
'删除': 'Delete',
|
||||
'{0}/{1} 已完成': '{0}/{1} done',
|
||||
'新建待办': 'New todo',
|
||||
'还没有待办': 'No todos yet',
|
||||
'没有匹配的待办': 'No matching todos',
|
||||
'{0} 份计划': '{0} plans',
|
||||
'新建计划': 'New plan',
|
||||
'还没有计划': 'No plans yet',
|
||||
'没有匹配的计划': 'No matching plans',
|
||||
'团队共享': 'Shared',
|
||||
'个人': 'Personal',
|
||||
'记忆功能未启用': 'Memory is not enabled',
|
||||
'还没有记忆': 'No memories yet',
|
||||
'没有匹配的记忆': 'No matching memories',
|
||||
'全局记忆': 'Global memory',
|
||||
'项目记忆': 'Project memory',
|
||||
'{0}({1})': '{0} ({1})',
|
||||
'记忆由 agent 在会话中记录;你可以在这里修改或删除它。':
|
||||
'Memory is recorded by the agent during sessions; you can edit or delete it here.',
|
||||
'读取失败,请刷新': 'Could not load, refresh to retry',
|
||||
'暂无': 'None',
|
||||
'编辑笔记': 'Edit note',
|
||||
'记点什么,供之后的会话参考': 'Write something for later sessions to read',
|
||||
'保存': 'Save',
|
||||
'要做什么': 'What needs doing',
|
||||
'保存中…': 'Saving…',
|
||||
'标题': 'Title',
|
||||
'计划正文(Markdown)': 'Plan body (Markdown)',
|
||||
'创建': 'Create',
|
||||
'编辑记忆': 'Edit memory',
|
||||
'事实': 'Fact',
|
||||
'偏好': 'Preference',
|
||||
'参考': 'Reference',
|
||||
'内容': 'Content',
|
||||
'取消': 'Cancel',
|
||||
|
||||
// ------------------------------------------------------------- sessions
|
||||
'会话': 'Sessions',
|
||||
'搜索': 'Search',
|
||||
'新会话': 'New session',
|
||||
'搜索会话': 'Search sessions',
|
||||
'全部功能': 'All features',
|
||||
'设置': 'Settings',
|
||||
'暂无会话': 'No sessions',
|
||||
'没有匹配的会话': 'No matching sessions',
|
||||
'聊天': 'Chat',
|
||||
'未命名项目': 'Untitled project',
|
||||
'新建聊天': 'New chat',
|
||||
'在此项目新会话': 'New session in this project',
|
||||
'今天': 'Today',
|
||||
'昨天': 'Yesterday',
|
||||
'本周早些时候': 'Earlier this week',
|
||||
'更早': 'Earlier',
|
||||
'已置顶': 'Pinned',
|
||||
'草稿': 'Draft',
|
||||
'草稿 · {0}': 'Draft · {0}',
|
||||
'丢弃草稿': 'Discard draft',
|
||||
'归档': 'Archive',
|
||||
'取消归档': 'Unarchive',
|
||||
'收起子代理': 'Collapse subagents',
|
||||
'展开子代理': 'Expand subagents',
|
||||
'(无标题会话)': '(Untitled session)',
|
||||
'子代理 · {0}': 'Subagent · {0}',
|
||||
'已复制会话 ID': 'Session ID copied',
|
||||
'重命名': 'Rename',
|
||||
'复制会话 ID': 'Copy session ID',
|
||||
'载入更多': 'Load more',
|
||||
'隐藏已归档': 'Hide archived',
|
||||
'显示已归档': 'Show archived',
|
||||
'显示已归档 ({0})': 'Show archived ({0})',
|
||||
'没有已归档的会话': 'No archived sessions',
|
||||
'{0} 个子代理': '{0} subagents',
|
||||
'“{0}”及其子会话将被删除,且无法恢复。':
|
||||
'“{0}” and its subagent sessions will be deleted permanently.',
|
||||
'服务器': 'Servers',
|
||||
'经由 Relay · {0}': 'via Relay · {0}',
|
||||
'{0}\n经由 {1}': '{0}\nvia {1}',
|
||||
'已连接': 'Connected',
|
||||
'添加服务器': 'Add server',
|
||||
'配对链接': 'Pairing link',
|
||||
'直连地址或 OpenChamber Relay': 'Direct address or OpenChamber Relay',
|
||||
'断开当前连接': 'Disconnect',
|
||||
'删除会话?': 'Delete session?',
|
||||
|
||||
// ---------------------------------------------------------------- files
|
||||
'文件': 'Files',
|
||||
'文件较大({0}),请下载后查看': 'File is large ({0}), download it to view',
|
||||
'已保存': 'Saved',
|
||||
'保存失败:{0}': 'Could not save: {0}',
|
||||
'新建文件夹': 'New folder',
|
||||
'新建文件': 'New file',
|
||||
'名称': 'Name',
|
||||
'例如 docs': 'e.g. docs',
|
||||
'例如 notes.md': 'e.g. notes.md',
|
||||
'名称里不能有斜杠': 'Names cannot contain slashes',
|
||||
'项目知识': 'Project knowledge',
|
||||
'终端': 'Terminal',
|
||||
'关闭侧栏': 'Close sidebar',
|
||||
'搜索当前目录…': 'Search this directory…',
|
||||
'搜索子目录': 'Search subdirectories',
|
||||
'正在搜索子目录…({0})': 'Searching subdirectories… ({0})',
|
||||
'返回': 'Back',
|
||||
'上一级': 'Up one level',
|
||||
'预览': 'Preview',
|
||||
'下载': 'Download',
|
||||
'新建': 'New',
|
||||
'更多': 'More',
|
||||
'显示被 git 忽略的文件': 'Show git-ignored files',
|
||||
'目录为空': 'Directory is empty',
|
||||
'没有匹配的文件': 'No matching files',
|
||||
'子目录结果': 'Subdirectory results',
|
||||
'子目录里没有匹配的文件': 'No matching files in subdirectories',
|
||||
'这个文件无法预览': 'This file cannot be previewed',
|
||||
'正在下载': 'Downloading',
|
||||
'{0} / {1}({2}%)': '{0} / {1} ({2}%)',
|
||||
'已下载 {0}': 'Downloaded {0}',
|
||||
'正在取消…': 'Canceling…',
|
||||
'关闭': 'Close',
|
||||
|
||||
// ------------------------------------------------------------- terminal
|
||||
'未启动': 'Not started',
|
||||
'正在创建…': 'Creating…',
|
||||
'正在连接…': 'Connecting…',
|
||||
'连接中断,正在重连…': 'Connection lost, reconnecting…',
|
||||
'运行中': 'Running',
|
||||
'已退出': 'Exited',
|
||||
'连接失败': 'Connection failed',
|
||||
'切换终端': 'Switch terminal',
|
||||
'新建终端': 'New terminal',
|
||||
'键盘': 'Keyboard',
|
||||
'重新启动': 'Restart',
|
||||
'清屏': 'Clear screen',
|
||||
'关闭此终端': 'Close this terminal',
|
||||
|
||||
// ---------------------------------------------------------- new session
|
||||
'选择失败:{0}': 'Could not attach: {0}',
|
||||
'我们今天要做什么?': 'What are we building today?',
|
||||
'选择项目': 'Choose project',
|
||||
'规划、构建或提问': 'Plan, build, or ask',
|
||||
'添加附件': 'Add attachment',
|
||||
'不关联项目,保存在 OpenChamber 的聊天目录':
|
||||
'Not tied to a project, saved in OpenChamber\'s chat directory',
|
||||
'没有可用的项目': 'No projects available',
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
// English strings for one part of the app; merged into L10n's table. Keys are
|
||||
// the Chinese text the code writes, including {0}, {1} placeholders for text
|
||||
// that is built from parts.
|
||||
const Map<String, String> enSettings = {};
|
||||
@@ -0,0 +1,249 @@
|
||||
// English strings for one part of the app; merged into L10n's table. Keys are
|
||||
// the Chinese text the code writes, including {0}, {1} placeholders for text
|
||||
// that is built from parts.
|
||||
const Map<String, String> enTools = {
|
||||
// settings index
|
||||
'设置': 'Settings',
|
||||
'常规': 'General',
|
||||
'语言': 'Language',
|
||||
'跟随系统、中文或 English': 'Follow the system, Chinese or English',
|
||||
'通用': 'Agent tools',
|
||||
'智能体工具与记忆': 'Agent tools and memory',
|
||||
'聊天': 'Chat',
|
||||
'追问处理行为': 'Follow-up behavior',
|
||||
'外观': 'Appearance',
|
||||
'仅当前设备生效,不同步到服务器':
|
||||
'Applies to this device only; not synced to the server',
|
||||
'主题': 'Theme',
|
||||
'主题模式与主题色': 'Theme mode and color',
|
||||
'宠物': 'Pet',
|
||||
'导入、启用与大小': 'Import, enable and size',
|
||||
'帮助与关于': 'Help & about',
|
||||
'关于': 'About',
|
||||
'版本、服务端与开源许可': 'Version, server and open-source licenses',
|
||||
|
||||
// general: agent tools
|
||||
'在聊天中': 'In chat',
|
||||
'图表和原型': 'Charts and prototypes',
|
||||
'让智能体在聊天中展示图表、表格、示意图和界面草图(与你的文件隔离),并请你在其中选择一个选项。':
|
||||
'Let the agent show charts, tables, diagrams and UI sketches in chat (isolated from your files) and ask you to pick one of them.',
|
||||
'图像': 'Images',
|
||||
'让智能体用你选择的模型生成和编辑图像,费用由该模型的提供商收取。':
|
||||
'Let the agent generate and edit images with the model you choose; the model\'s provider charges for it.',
|
||||
'图像模型': 'Image model',
|
||||
'你的提供商中没有图像模型': 'Your provider has no image models',
|
||||
'不指定': 'None',
|
||||
'密钥': 'Secrets',
|
||||
'允许智能体在聊天中的私密卡片上向你索取 API 密钥、令牌或密码。值不会进入对话。':
|
||||
'Let the agent ask you for API keys, tokens or passwords on a private card in chat. Values never enter the conversation.',
|
||||
'通知': 'Notifications',
|
||||
'工作完成或卡住时,智能体会通知你。':
|
||||
'The agent notifies you when work finishes or gets stuck.',
|
||||
'智能体知道的内容': 'What the agent knows',
|
||||
'记忆': 'Memory',
|
||||
'跨会话记住关于你和每个项目的事实。':
|
||||
'Remember facts about you and each project across sessions.',
|
||||
'项目知识': 'Project knowledge',
|
||||
'让智能体读取并更新项目的笔记、待办和计划。':
|
||||
'Let the agent read and update the project\'s notes, todos and plans.',
|
||||
'用量限额': 'Usage limits',
|
||||
'让智能体查看各提供商的限额及重置时间。':
|
||||
'Let the agent check each provider\'s limits and reset times.',
|
||||
'未选择': 'Not selected',
|
||||
'默认': 'Default',
|
||||
'默认模型': 'Default model',
|
||||
'整理记忆': 'Tidy memory',
|
||||
'整理记忆使用的模型': 'Model for tidying memory',
|
||||
'知道了': 'Got it',
|
||||
'每天一次,在没有会话运行时,智能体会在后台整理记忆:合并重复条目,删除已过时或项目文档中已有的内容。':
|
||||
'Once a day, when no session is running, the agent tidies memory in the background: merging duplicates and removing entries that are obsolete or already in the project docs.',
|
||||
'保存失败:{0}': 'Couldn\'t save: {0}',
|
||||
'保存失败': 'Couldn\'t save',
|
||||
'未知错误': 'Unknown error',
|
||||
|
||||
// language
|
||||
'中文': 'Chinese',
|
||||
'当前:{0}': 'Current: {0}',
|
||||
'界面文字与系统自带的日期、时间选择器会一起切换。':
|
||||
'The UI text switches together with the system\'s date and time pickers.',
|
||||
|
||||
// chat behavior
|
||||
'运行中按发送时,消息默认怎么处理。与网页端设置同步。':
|
||||
'What happens by default when you press send while a run is in progress. Synced with the web client\'s setting.',
|
||||
'转向': 'Steer',
|
||||
'排队': 'Queue',
|
||||
'转向:在下一步加入当前回合,工作继续。':
|
||||
'Steer: joins the current turn at the next step and work continues.',
|
||||
'排队:等当前回合结束后再发送。':
|
||||
'Queue: sends after the current turn ends.',
|
||||
|
||||
// theme
|
||||
'跟随系统': 'Follow system',
|
||||
'浅色': 'Light',
|
||||
'深色': 'Dark',
|
||||
'主题模式': 'Theme mode',
|
||||
'主题色': 'Accent color',
|
||||
'主题色 {0}': 'Accent color {0}',
|
||||
'主题只保存在本机,不随服务器同步。':
|
||||
'The theme is stored on this device only and does not sync with the server.',
|
||||
|
||||
// pet
|
||||
'默认不提供宠物;宠物包只存放在本机。':
|
||||
'No pet is included; pet packs stay on this device.',
|
||||
'尚未导入宠物': 'No pet imported',
|
||||
'导入一个宠物包(.zip)后,它会站在输入框上方。':
|
||||
'Import a pet pack (.zip) and it will stand above the input box.',
|
||||
'导入宠物包': 'Import pet pack',
|
||||
'选择宠物包(.zip)': 'Select a pet pack (.zip)',
|
||||
'已导入 {0}': 'Imported {0}',
|
||||
'导入失败:{0}': 'Import failed: {0}',
|
||||
'启用宠物': 'Enable pet',
|
||||
'站在输入框上方,默认关闭': 'Stands above the input box; off by default',
|
||||
'大小': 'Size',
|
||||
'小': 'Small',
|
||||
'中': 'Medium',
|
||||
'大': 'Large',
|
||||
'更换宠物包': 'Change pet pack',
|
||||
'移除': 'Remove',
|
||||
'移除宠物?': 'Remove pet?',
|
||||
'本机保存的宠物包会被删除。':
|
||||
'The pet pack stored on this device will be deleted.',
|
||||
'取消': 'Cancel',
|
||||
|
||||
// about
|
||||
'读取中…': 'Loading…',
|
||||
'未连接': 'Not connected',
|
||||
'未获取到': 'Not available',
|
||||
'重新获取服务端版本': 'Fetch the server version again',
|
||||
'手机客户端': 'Mobile client',
|
||||
'应用': 'App',
|
||||
'版本': 'Version',
|
||||
'未知': 'Unknown',
|
||||
'开源许可': 'Open-source licenses',
|
||||
'本应用使用的第三方组件与它们的许可证':
|
||||
'Third-party components used by this app and their licenses',
|
||||
'服务端': 'Server',
|
||||
'版本取自当前连接的服务器': 'Version comes from the currently connected server',
|
||||
'下面列出随本应用打包的第三方组件;点开可阅读完整许可证。':
|
||||
'Third-party components bundled with this app are listed below; tap one to read its full license.',
|
||||
'该组件没有附带许可证文本。': 'This component has no license text.',
|
||||
|
||||
// features
|
||||
'全部功能': 'All features',
|
||||
'服务器与智能体的工具都收在这里。':
|
||||
'Tools for servers and agents are collected here.',
|
||||
'计划任务': 'Scheduled tasks',
|
||||
'按时间向会话发送提示词': 'Send prompts to sessions on a schedule',
|
||||
|
||||
// scheduled task editor
|
||||
'新建计划任务': 'New scheduled task',
|
||||
'编辑计划任务': 'Edit scheduled task',
|
||||
'保存中…': 'Saving…',
|
||||
'保存': 'Save',
|
||||
'运行位置:{0}': 'Runs in: {0}',
|
||||
'任务名称': 'Task name',
|
||||
'每日同步': 'Daily sync',
|
||||
'提示词': 'Prompt',
|
||||
'总结未完成任务并给出下一步建议':
|
||||
'Summarize unfinished tasks and suggest next steps',
|
||||
'计划类型': 'Schedule type',
|
||||
'星期': 'Weekdays',
|
||||
'日期': 'Date',
|
||||
'时间': 'Time',
|
||||
'Cron 表达式': 'Cron expression',
|
||||
'每 5 分钟': 'Every 5 minutes',
|
||||
'每小时': 'Every hour',
|
||||
'每天 9 点': 'Daily at 9',
|
||||
'每周一 9 点': 'Mondays at 9',
|
||||
'每月 1 日': '1st of each month',
|
||||
'时间点': 'Times',
|
||||
'移除时间': 'Remove time',
|
||||
'添加时间': 'Add time',
|
||||
'时间按服务器所在时区。': 'Times follow the server\'s time zone.',
|
||||
'选择模型': 'Select model',
|
||||
'默认智能体': 'Default agent',
|
||||
'模型': 'Model',
|
||||
'智能体': 'Agent',
|
||||
'使用默认模型与智能体': 'Use default model and agent',
|
||||
'关闭后可固定这次运行使用的模型和智能体。':
|
||||
'Turn off to pin the model and agent this run uses.',
|
||||
'已启用': 'Enabled',
|
||||
'暂停的任务不会按计划运行,但可以手动运行。':
|
||||
'Paused tasks don\'t run on schedule but can still be run manually.',
|
||||
'任务名称为必填项': 'Task name is required',
|
||||
'任务名称不能超过 80 个字符': 'Task name can\'t exceed 80 characters',
|
||||
'提示词为必填项': 'Prompt is required',
|
||||
'提示词不能超过 20000 个字符': 'Prompt can\'t exceed 20,000 characters',
|
||||
'时间格式必须是 HH:mm': 'Time must be in HH:mm format',
|
||||
'请至少选择一个星期': 'Select at least one weekday',
|
||||
'Cron 表达式为必填项': 'Cron expression is required',
|
||||
'请选择模型,或改回使用默认模型':
|
||||
'Select a model, or switch back to the default model',
|
||||
|
||||
// scheduled tasks list
|
||||
'未连接服务器': 'Not connected to a server',
|
||||
'服务器不支持计划任务': 'The server doesn\'t support scheduled tasks',
|
||||
'加载计划任务失败:{0}': 'Couldn\'t load scheduled tasks: {0}',
|
||||
'计划任务已保存': 'Scheduled task saved',
|
||||
'保存任务失败': 'Couldn\'t save task',
|
||||
'保存任务失败:{0}': 'Couldn\'t save task: {0}',
|
||||
'更新任务失败': 'Couldn\'t update task',
|
||||
'任务已启动': 'Task started',
|
||||
'任务已在队列中等待': 'Task is already waiting in the queue',
|
||||
'运行任务失败': 'Couldn\'t run task',
|
||||
'运行任务失败:{0}': 'Couldn\'t run task: {0}',
|
||||
'删除计划任务?': 'Delete scheduled task?',
|
||||
'“{0}”及其计划会被删除。': '“{0}” and its schedule will be deleted.',
|
||||
'计划任务已删除': 'Scheduled task deleted',
|
||||
'删除任务失败': 'Couldn\'t delete task',
|
||||
'刷新': 'Refresh',
|
||||
'新建任务': 'New task',
|
||||
'下次:{0}': 'Next: {0}',
|
||||
'已暂停': 'Paused',
|
||||
'上次运行 {0} · {1}': 'Last run {0} · {1}',
|
||||
'从未运行': 'Never run',
|
||||
'更多': 'More',
|
||||
'立即运行': 'Run now',
|
||||
'编辑': 'Edit',
|
||||
'删除': 'Delete',
|
||||
'运行位置': 'Runs in',
|
||||
'重试': 'Retry',
|
||||
'暂无计划任务。': 'No scheduled tasks yet.',
|
||||
'发送到现有会话': 'Sends to an existing session',
|
||||
|
||||
// scheduled task schedule text and status
|
||||
'周日': 'Sun',
|
||||
'周一': 'Mon',
|
||||
'周二': 'Tue',
|
||||
'周三': 'Wed',
|
||||
'周四': 'Thu',
|
||||
'周五': 'Fri',
|
||||
'周六': 'Sat',
|
||||
'每天': 'Daily',
|
||||
'每周': 'Weekly',
|
||||
'一次性': 'Once',
|
||||
'每天 {0}': 'Daily {0}',
|
||||
'每周 {0} {1}': 'Weekly {0} {1}',
|
||||
'未选': 'no days',
|
||||
'一次性 {0} {1}': 'Once {0} {1}',
|
||||
'未选日期': 'no date',
|
||||
'Cron:{0}': 'Cron: {0}',
|
||||
'、': ', ',
|
||||
'成功': 'Success',
|
||||
'错误': 'Error',
|
||||
'运行中': 'Running',
|
||||
'已排队': 'Queued',
|
||||
'已跳过': 'Skipped',
|
||||
'已取消': 'Cancelled',
|
||||
'空闲': 'Idle',
|
||||
'不到 1 分钟后': 'In less than a minute',
|
||||
'刚刚': 'Just now',
|
||||
'{0} 分钟后': 'In {0} min',
|
||||
'{0} 分钟前': '{0} min ago',
|
||||
'{0} 小时 {1} 分钟': '{0} hr {1} min',
|
||||
'{0} 小时': '{0} hr',
|
||||
'{0} 天 {1} 小时': '{0} days {1} hr',
|
||||
'{0} 天': '{0} days',
|
||||
'{0}后': 'In {0}',
|
||||
'{0}前': '{0} ago',
|
||||
};
|
||||
+16
-6
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
|
||||
import 'appearance_prefs.dart';
|
||||
import 'l10n.dart';
|
||||
import 'pets/pet_library.dart';
|
||||
import 'screens/home_screen.dart';
|
||||
import 'screens/servers_screen.dart';
|
||||
@@ -11,8 +12,10 @@ import 'version.dart';
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
// The version goes into every connection's handshake; read it once here so
|
||||
// nothing waits for it later.
|
||||
// nothing waits for it later. The language is read before the first frame
|
||||
// for the same reason: a saved choice should never flash the other one.
|
||||
await loadAppVersion();
|
||||
await L10n.instance.ensureLoaded();
|
||||
runApp(const OpenChamberApp());
|
||||
}
|
||||
|
||||
@@ -41,6 +44,12 @@ class _OpenChamberAppState extends State<OpenChamberApp>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeLocales(List<Locale>? locales) {
|
||||
// "Follow the system" has to redraw when the system language changes.
|
||||
L10n.instance.systemLocaleChanged();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// The socket often dies while the app sits in the background; nothing
|
||||
@@ -52,17 +61,18 @@ class _OpenChamberAppState extends State<OpenChamberApp>
|
||||
Widget build(BuildContext context) {
|
||||
final look = AppearancePrefs.instance;
|
||||
return ListenableBuilder(
|
||||
listenable: Listenable.merge([app, look]),
|
||||
listenable: Listenable.merge([app, look, L10n.instance]),
|
||||
builder: (context, _) {
|
||||
final home = app.client == null
|
||||
? ServersScreen(app: app)
|
||||
: HomeScreen(app: app);
|
||||
return MaterialApp(
|
||||
title: 'OpenChamber',
|
||||
// The app speaks Chinese only; this also puts the built-in pieces
|
||||
// (date and time pickers, text selection menu) in Chinese.
|
||||
locale: const Locale('zh', 'CN'),
|
||||
supportedLocales: const [Locale('zh', 'CN'), Locale('en')],
|
||||
// Chinese and English, picked in 设置 → 常规 → 语言 or followed
|
||||
// from the system. The built-in pieces (date and time pickers,
|
||||
// text selection menu) follow the same choice.
|
||||
locale: L10n.instance.locale,
|
||||
supportedLocales: const [Locale('en'), Locale('zh', 'CN')],
|
||||
localizationsDelegates: const [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
|
||||
+10
-8
@@ -4,6 +4,8 @@ import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'l10n.dart';
|
||||
|
||||
class ModelPrefs {
|
||||
ModelPrefs._();
|
||||
static final ModelPrefs instance = ModelPrefs._();
|
||||
@@ -92,15 +94,15 @@ String formatTokenCount(int tokens) {
|
||||
|
||||
/// The Chinese label for an effort variant; unknown ids keep their own name.
|
||||
String effortLabel(String? variant) {
|
||||
if (variant == null || variant.isEmpty) return '默认';
|
||||
if (variant == null || variant.isEmpty) return tr('默认');
|
||||
return switch (variant.toLowerCase()) {
|
||||
'default' => '默认',
|
||||
'none' => '无',
|
||||
'minimal' => '极低',
|
||||
'low' => '低',
|
||||
'medium' || 'mid' => '中',
|
||||
'high' => '高',
|
||||
'xhigh' || 'max' => '极高',
|
||||
'default' => tr('默认'),
|
||||
'none' => tr('无'),
|
||||
'minimal' => tr('极低'),
|
||||
'low' => tr('低'),
|
||||
'medium' || 'mid' => tr('中'),
|
||||
'high' => tr('高'),
|
||||
'xhigh' || 'max' => tr('极高'),
|
||||
_ => variant,
|
||||
};
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../l10n.dart';
|
||||
import 'pet_pack.dart';
|
||||
|
||||
class PetImportException implements Exception {
|
||||
@@ -110,16 +111,16 @@ class PetLibrary extends ChangeNotifier {
|
||||
/// Unpacks and activates a pet package. [root] is for tests; the app uses
|
||||
/// the documents directory.
|
||||
Future<PetPack> importZip(List<int> bytes, {Directory? root}) async {
|
||||
if (bytes.isEmpty) throw const PetImportException('文件为空');
|
||||
if (bytes.isEmpty) throw PetImportException(tr('文件为空'));
|
||||
if (bytes.length > 40 * 1024 * 1024) {
|
||||
throw const PetImportException('宠物包不能超过 40MB');
|
||||
throw PetImportException(tr('宠物包不能超过 40MB'));
|
||||
}
|
||||
|
||||
final Archive archive;
|
||||
try {
|
||||
archive = ZipDecoder().decodeBytes(bytes, verify: true);
|
||||
} catch (_) {
|
||||
throw const PetImportException('不是有效的 zip 文件');
|
||||
throw PetImportException(tr('不是有效的 zip 文件'));
|
||||
}
|
||||
|
||||
ArchiveFile? manifest;
|
||||
@@ -133,7 +134,7 @@ class PetLibrary extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
if (manifest == null) {
|
||||
throw const PetImportException('压缩包里没有 pack.json');
|
||||
throw PetImportException(tr('压缩包里没有 pack.json'));
|
||||
}
|
||||
|
||||
final manifestName = manifest.name.replaceAll('\\', '/');
|
||||
@@ -148,10 +149,10 @@ class PetLibrary extends ChangeNotifier {
|
||||
if (json is! Map<String, dynamic>) throw const FormatException();
|
||||
parsed = PetPack.fromJson(json);
|
||||
} catch (_) {
|
||||
throw const PetImportException('pack.json 不是有效的宠物包');
|
||||
throw PetImportException(tr('pack.json 不是有效的宠物包'));
|
||||
}
|
||||
if (!parsed.isValid) {
|
||||
throw const PetImportException('pack.json 缺少动画或状态');
|
||||
throw PetImportException(tr('pack.json 缺少动画或状态'));
|
||||
}
|
||||
|
||||
final id = _safeId(parsed.id.isNotEmpty ? parsed.id : parsed.name);
|
||||
@@ -174,7 +175,7 @@ class PetLibrary extends ChangeNotifier {
|
||||
final content = _content(file);
|
||||
extracted += content.length;
|
||||
if (extracted > 60 * 1024 * 1024) {
|
||||
throw const PetImportException('解压后超过 60MB');
|
||||
throw PetImportException(tr('解压后超过 60MB'));
|
||||
}
|
||||
final target = File('${staging.path}/$rel');
|
||||
await target.parent.create(recursive: true);
|
||||
@@ -183,11 +184,11 @@ class PetLibrary extends ChangeNotifier {
|
||||
|
||||
for (final animation in parsed.animations.values) {
|
||||
if (animation.sheet.isEmpty) {
|
||||
throw PetImportException('动画 ${animation.name} 没有精灵图');
|
||||
throw PetImportException(trArgs('动画 {0} 没有精灵图', [animation.name]));
|
||||
}
|
||||
final sheet = File('${staging.path}/${animation.sheet}');
|
||||
if (!await sheet.exists()) {
|
||||
throw PetImportException('缺少精灵图 ${animation.sheet}');
|
||||
throw PetImportException(trArgs('缺少精灵图 {0}', [animation.sheet]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+145
-137
@@ -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)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../state.dart';
|
||||
import 'scheduled_tasks_screen.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
class FeaturesScreen extends StatelessWidget {
|
||||
final AppState app;
|
||||
@@ -13,11 +14,11 @@ class FeaturesScreen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('全部功能')),
|
||||
appBar: AppBar(title: const AppText('全部功能')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 32),
|
||||
children: [
|
||||
Text('服务器与智能体的工具都收在这里。',
|
||||
AppText('服务器与智能体的工具都收在这里。',
|
||||
style: TextStyle(fontSize: 12.5, color: theme.hintColor)),
|
||||
const SizedBox(height: 14),
|
||||
GridView.count(
|
||||
@@ -82,11 +83,11 @@ class _FeatureTile extends StatelessWidget {
|
||||
size: 21, color: theme.colorScheme.onPrimaryContainer),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(title,
|
||||
AppText(title,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5, fontWeight: FontWeight.w600)),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
AppText(
|
||||
caption,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -98,4 +99,4 @@ class _FeatureTile extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,14 @@ import '../state.dart';
|
||||
import '../widgets/markdown_view.dart';
|
||||
import 'knowledge_panel.dart';
|
||||
import 'terminal_panel.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
Future<void> showFilesPanel(
|
||||
BuildContext context, AppState app, String directory) {
|
||||
return showGeneralDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '文件',
|
||||
barrierLabel: tr('文件'),
|
||||
barrierColor: Colors.black54,
|
||||
transitionDuration: const Duration(milliseconds: 220),
|
||||
pageBuilder: (context, _, __) {
|
||||
@@ -243,7 +244,8 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
if (!mounted || _previewPath != entry.path) return;
|
||||
setState(() {
|
||||
_previewLoading = false;
|
||||
_previewError = '文件较大(${_fmtSize(stat.size)}),请下载后查看';
|
||||
_previewError = trArgs(
|
||||
'文件较大({0}),请下载后查看', [_fmtSize(stat.size)]);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -316,7 +318,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
);
|
||||
if (uri != null) _toast('已保存');
|
||||
} catch (e) {
|
||||
_toast('保存失败:$e');
|
||||
_toast(trArgs('保存失败:{0}', [e]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,23 +351,23 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
final name = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(title),
|
||||
title: AppText(title),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: '名称',
|
||||
hintText: title == '新建文件夹' ? '例如 docs' : '例如 notes.md',
|
||||
labelText: tr('名称'),
|
||||
hintText: title == '新建文件夹' ? tr('例如 docs') : tr('例如 notes.md'),
|
||||
),
|
||||
onSubmitted: (v) => Navigator.of(context).pop(v),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('取消')),
|
||||
child: const AppText('取消')),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(controller.text),
|
||||
child: const Text('创建')),
|
||||
child: const AppText('创建')),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -373,7 +375,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
final trimmed = name?.trim() ?? '';
|
||||
if (trimmed.isEmpty) return null;
|
||||
if (trimmed.contains('/') || trimmed.contains('\\')) {
|
||||
_toast('名称里不能有斜杠');
|
||||
_toast(tr('名称里不能有斜杠'));
|
||||
return null;
|
||||
}
|
||||
return trimmed;
|
||||
@@ -381,7 +383,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
|
||||
void _toast(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: AppText(message)));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- build
|
||||
@@ -425,7 +427,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
),
|
||||
segments: [
|
||||
for (var i = 0; i < labels.length; i++)
|
||||
ButtonSegment(value: i, label: Text(labels[i])),
|
||||
ButtonSegment(value: i, label: AppText(labels[i])),
|
||||
],
|
||||
selected: {_tab},
|
||||
onSelectionChanged: (v) => setState(() => _tab = v.first),
|
||||
@@ -433,7 +435,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: '关闭侧栏',
|
||||
tooltip: tr('关闭侧栏'),
|
||||
onPressed: () => Navigator.of(context).maybePop(),
|
||||
),
|
||||
],
|
||||
@@ -443,7 +445,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
|
||||
Widget _body(ThemeData theme) {
|
||||
if (_root.isEmpty) {
|
||||
return const Center(child: Text('这个会话没有关联目录'));
|
||||
return const Center(child: AppText('这个会话没有关联目录'));
|
||||
}
|
||||
switch (_tab) {
|
||||
case 1:
|
||||
@@ -485,12 +487,12 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
prefixIcon: const Icon(Icons.search, size: 20),
|
||||
hintText: '搜索当前目录…',
|
||||
hintText: tr('搜索当前目录…'),
|
||||
suffixIcon: _query.trim().isEmpty
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.travel_explore, size: 20),
|
||||
tooltip: '搜索子目录',
|
||||
tooltip: tr('搜索子目录'),
|
||||
onPressed: _searching ? null : _deepSearch,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
@@ -513,7 +515,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2)),
|
||||
const SizedBox(width: 8),
|
||||
Text('正在搜索子目录…(${_deepResults.length})',
|
||||
AppText(trArgs('正在搜索子目录…({0})', [_deepResults.length]),
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
],
|
||||
),
|
||||
@@ -535,7 +537,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
IconButton(
|
||||
icon: Icon(preview ? Icons.arrow_back : Icons.arrow_upward,
|
||||
size: 20),
|
||||
tooltip: preview ? '返回' : '上一级',
|
||||
tooltip: preview ? tr('返回') : tr('上一级'),
|
||||
onPressed: preview
|
||||
? () => setState(() => _previewPath = null)
|
||||
: (_path == _root ? null : _up),
|
||||
@@ -546,12 +548,12 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(_previewName,
|
||||
AppText(_previewName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5, fontWeight: FontWeight.w600)),
|
||||
Text(_previewPath!,
|
||||
AppText(_previewPath!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
@@ -565,7 +567,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
_crumb(theme, _rootName, () => _load(_root),
|
||||
last: crumbs.isEmpty),
|
||||
for (var i = 0; i < crumbs.length; i++) ...[
|
||||
Text(' / ', style: TextStyle(color: theme.hintColor)),
|
||||
AppText(' / ', style: TextStyle(color: theme.hintColor)),
|
||||
_crumb(theme, crumbs[i], () => _goToCrumb(i),
|
||||
last: i == crumbs.length - 1),
|
||||
],
|
||||
@@ -579,7 +581,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
icon: Icon(_editing
|
||||
? Icons.visibility_outlined
|
||||
: Icons.edit_outlined),
|
||||
tooltip: _editing ? '预览' : '编辑',
|
||||
tooltip: _editing ? tr('预览') : tr('编辑'),
|
||||
onPressed:
|
||||
_saving ? null : () => setState(() => _editing = !_editing),
|
||||
),
|
||||
@@ -591,27 +593,27 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Icon(Icons.check),
|
||||
tooltip: '保存',
|
||||
tooltip: tr('保存'),
|
||||
onPressed: _saving ? null : _save,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.download_outlined),
|
||||
tooltip: '下载',
|
||||
tooltip: tr('下载'),
|
||||
onPressed: _download,
|
||||
),
|
||||
] else if (_root.isNotEmpty) ...[
|
||||
PopupMenuButton<bool>(
|
||||
icon: const Icon(Icons.add),
|
||||
tooltip: '新建',
|
||||
tooltip: tr('新建'),
|
||||
onSelected: (directory) => _newEntry(directory: directory),
|
||||
itemBuilder: (_) => const [
|
||||
PopupMenuItem(value: false, child: Text('新建文件')),
|
||||
PopupMenuItem(value: true, child: Text('新建文件夹')),
|
||||
PopupMenuItem(value: false, child: AppText('新建文件')),
|
||||
PopupMenuItem(value: true, child: AppText('新建文件夹')),
|
||||
],
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
tooltip: '更多',
|
||||
tooltip: tr('更多'),
|
||||
onSelected: (value) {
|
||||
if (value == 'ignored') {
|
||||
setState(() => _showIgnored = !_showIgnored);
|
||||
@@ -624,7 +626,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
CheckedPopupMenuItem(
|
||||
value: 'ignored',
|
||||
checked: _showIgnored,
|
||||
child: const Text('显示被 git 忽略的文件'),
|
||||
child: const AppText('显示被 git 忽略的文件'),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'refresh',
|
||||
@@ -632,7 +634,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
children: [
|
||||
Icon(Icons.refresh, size: 18),
|
||||
SizedBox(width: 10),
|
||||
Text('刷新'),
|
||||
AppText('刷新'),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -651,7 +653,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
@@ -672,9 +674,9 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(_error!, textAlign: TextAlign.center),
|
||||
AppText(_error!, textAlign: TextAlign.center),
|
||||
const SizedBox(height: 8),
|
||||
TextButton(onPressed: () => _load(), child: const Text('重试')),
|
||||
TextButton(onPressed: () => _load(), child: const AppText('重试')),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -688,7 +690,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
.toList();
|
||||
if (filtered.isEmpty && _deepResults.isEmpty) {
|
||||
return Center(
|
||||
child: Text(_query.trim().isEmpty ? '目录为空' : '没有匹配的文件',
|
||||
child: AppText(_query.trim().isEmpty ? '目录为空' : '没有匹配的文件',
|
||||
style: TextStyle(color: theme.hintColor)),
|
||||
);
|
||||
}
|
||||
@@ -699,7 +701,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
if (_query.trim().isNotEmpty && _deepResults.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
|
||||
child: Text('子目录结果',
|
||||
child: AppText('子目录结果',
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
),
|
||||
for (final e in _deepResults) _tile(theme, e, showPath: true),
|
||||
@@ -711,7 +713,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
filtered.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
child: Text('子目录里没有匹配的文件',
|
||||
child: AppText('子目录里没有匹配的文件',
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
),
|
||||
],
|
||||
@@ -728,10 +730,10 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
color: entry.isDirectory
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurfaceVariant),
|
||||
title: Text(entry.name,
|
||||
title: AppText(entry.name,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis, style: const TextStyle(fontSize: 14)),
|
||||
subtitle: showPath
|
||||
? Text(_relative(entry.path),
|
||||
? AppText(_relative(entry.path),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 11, color: theme.hintColor))
|
||||
@@ -768,10 +770,10 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(_previewError!, textAlign: TextAlign.center),
|
||||
AppText(_previewError!, textAlign: TextAlign.center),
|
||||
const SizedBox(height: 8),
|
||||
if (_previewBytes != null || _previewError != null)
|
||||
TextButton(onPressed: _download, child: const Text('下载')),
|
||||
TextButton(onPressed: _download, child: const AppText('下载')),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -793,16 +795,16 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
Icon(Icons.insert_drive_file_outlined,
|
||||
size: 40, color: theme.hintColor),
|
||||
const SizedBox(height: 10),
|
||||
Text('这个文件无法预览',
|
||||
AppText('这个文件无法预览',
|
||||
style: TextStyle(color: theme.hintColor)),
|
||||
const SizedBox(height: 6),
|
||||
Text(_fmtSize(_previewBytes?.length ?? 0),
|
||||
AppText(_fmtSize(_previewBytes?.length ?? 0),
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
const SizedBox(height: 8),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _download,
|
||||
icon: const Icon(Icons.download_outlined, size: 18),
|
||||
label: const Text('下载'),
|
||||
label: const AppText('下载'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1000,12 +1002,12 @@ class _DownloadDialogState extends State<_DownloadDialog> {
|
||||
? (_received / total).clamp(0.0, 1.0)
|
||||
: null;
|
||||
return AlertDialog(
|
||||
title: const Text('正在下载'),
|
||||
title: const AppText('正在下载'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(widget.name,
|
||||
AppText(widget.name,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 13)),
|
||||
@@ -1013,15 +1015,18 @@ class _DownloadDialogState extends State<_DownloadDialog> {
|
||||
if (_error == null) ...[
|
||||
LinearProgressIndicator(value: fraction),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
AppText(
|
||||
total != null
|
||||
? '${_size(_received)} / ${_size(total)}'
|
||||
'(${(fraction! * 100).toStringAsFixed(0)}%)'
|
||||
: '已下载 ${_size(_received)}',
|
||||
? trArgs('{0} / {1}({2}%)', [
|
||||
_size(_received),
|
||||
_size(total),
|
||||
(fraction! * 100).toStringAsFixed(0),
|
||||
])
|
||||
: trArgs('已下载 {0}', [_size(_received)]),
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor),
|
||||
),
|
||||
] else
|
||||
Text(_error!,
|
||||
AppText(_error!,
|
||||
style:
|
||||
TextStyle(fontSize: 12.5, color: theme.colorScheme.error)),
|
||||
],
|
||||
@@ -1035,14 +1040,14 @@ class _DownloadDialogState extends State<_DownloadDialog> {
|
||||
setState(() => _cancelling = true);
|
||||
_cancel.cancel();
|
||||
},
|
||||
child: Text(_cancelling ? '正在取消…' : '取消'),
|
||||
child: AppText(_cancelling ? '正在取消…' : '取消'),
|
||||
)
|
||||
else
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('关闭'),
|
||||
child: const AppText('关闭'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import '../state.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'new_session_screen.dart';
|
||||
import 'sessions_screen.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
final AppState app;
|
||||
@@ -126,13 +127,13 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
children: [
|
||||
Icon(Icons.forum_outlined, size: 40, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(height: 12),
|
||||
Text('选择一个会话',
|
||||
AppText('选择一个会话',
|
||||
style: TextStyle(fontSize: 16, color: scheme.onSurfaceVariant)),
|
||||
if (!wide) ...[
|
||||
const SizedBox(height: 12),
|
||||
FilledButton(
|
||||
onPressed: () => _scaffold.currentState?.openDrawer(),
|
||||
child: const Text('打开会话列表'),
|
||||
child: const AppText('打开会话列表'),
|
||||
),
|
||||
],
|
||||
],
|
||||
@@ -140,4 +141,4 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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('保存'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import '../widgets/pet_sprite.dart';
|
||||
import '../widgets/project_icon.dart';
|
||||
import '../widgets/slash_palette.dart';
|
||||
import 'files_panel.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
class NewSessionScreen extends StatefulWidget {
|
||||
final AppState app;
|
||||
@@ -176,7 +177,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
} 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);
|
||||
@@ -207,14 +208,14 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.menu),
|
||||
tooltip: '会话',
|
||||
tooltip: tr('会话'),
|
||||
onPressed: widget.onOpenSessions,
|
||||
),
|
||||
title: const Text('新会话'),
|
||||
title: const AppText('新会话'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.folder_open_outlined),
|
||||
tooltip: '文件',
|
||||
tooltip: tr('文件'),
|
||||
onPressed: () => showFilesPanel(context, app, draft.directory),
|
||||
),
|
||||
],
|
||||
@@ -228,7 +229,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
'我们今天要做什么?',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
@@ -252,7 +253,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
if (draft.error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
draft.error!,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5, color: scheme.error),
|
||||
@@ -300,7 +301,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
const SizedBox(width: 5),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 170),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
label.isEmpty ? '选择项目' : label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -322,7 +323,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
Widget body = ComposerBox(
|
||||
controller: _text,
|
||||
focusNode: _inputFocus,
|
||||
hint: '规划、构建或提问',
|
||||
hint: tr('规划、构建或提问'),
|
||||
maxLines: 5,
|
||||
keyboardInset: keyboardInset,
|
||||
textInputAction:
|
||||
@@ -354,7 +355,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
},
|
||||
leading: _roundKey(
|
||||
icon: Icons.attach_file,
|
||||
label: '添加附件',
|
||||
label: tr('添加附件'),
|
||||
onTap: _pickFiles,
|
||||
busy: _attaching,
|
||||
),
|
||||
@@ -477,7 +478,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(16, 14, 16, 6),
|
||||
child: Text('选择项目',
|
||||
child: AppText('选择项目',
|
||||
style:
|
||||
TextStyle(fontSize: 17, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
@@ -489,8 +490,8 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
dense: true,
|
||||
leading: ProjectIcon(
|
||||
app: widget.app, chat: true, size: 20),
|
||||
title: const Text('聊天'),
|
||||
subtitle: const Text('不关联项目,保存在 OpenChamber 的聊天目录'),
|
||||
title: const AppText('聊天'),
|
||||
subtitle: const AppText('不关联项目,保存在 OpenChamber 的聊天目录'),
|
||||
trailing: draft.directory == AppState.chatTarget
|
||||
? Icon(Icons.check,
|
||||
size: 18,
|
||||
@@ -508,9 +509,9 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
dense: true,
|
||||
leading:
|
||||
ProjectIcon(app: widget.app, project: project, size: 20),
|
||||
title: Text(project.label,
|
||||
title: AppText(project.label,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
subtitle: Text(project.canonical,
|
||||
subtitle: AppText(project.canonical,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
trailing: project.canonical == draft.directory
|
||||
? Icon(Icons.check,
|
||||
@@ -527,7 +528,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
if (projects.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: Text('没有可用的项目', textAlign: TextAlign.center),
|
||||
child: AppText('没有可用的项目', textAlign: TextAlign.center),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -555,4 +556,4 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
}
|
||||
return byPath.values.toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../api/qr_scan.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
/// Opens the scanner and returns the pairing link, or null when cancelled.
|
||||
Future<String?> scanPairingQr(BuildContext context) {
|
||||
@@ -92,7 +93,7 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
return;
|
||||
}
|
||||
if (cameras.isEmpty) {
|
||||
if (mounted) setState(() => _error = '没有可用的相机');
|
||||
if (mounted) setState(() => _error = tr('没有可用的相机'));
|
||||
return;
|
||||
}
|
||||
CameraDescription pick = cameras.first;
|
||||
@@ -123,11 +124,12 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
await controller.startImageStream(_onFrame);
|
||||
_watchdog = Timer(const Duration(seconds: 4), () {
|
||||
if (!mounted || _frames > 0 || _error != null) return;
|
||||
setState(() => _hint = '没有收到相机画面,请关闭后重试');
|
||||
setState(() => _hint = tr('没有收到相机画面,请关闭后重试'));
|
||||
});
|
||||
_slowHint = Timer(const Duration(seconds: 12), () {
|
||||
if (!mounted || _found || _frames == 0) return;
|
||||
_showHint('还没识别到二维码,试着靠近一点或让二维码占满取景框', sticky: true);
|
||||
_showHint(tr('还没识别到二维码,试着靠近一点或让二维码占满取景框'),
|
||||
sticky: true);
|
||||
});
|
||||
return;
|
||||
} catch (error) {
|
||||
@@ -151,11 +153,11 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
if (error.code == 'CameraAccessDenied' ||
|
||||
error.code == 'CameraAccessDeniedWithoutPrompt' ||
|
||||
error.code == 'CameraAccessRestricted') {
|
||||
return '需要相机权限才能扫码。请在系统设置里允许 OpenChamber 使用相机。';
|
||||
return tr('需要相机权限才能扫码。请在系统设置里允许 OpenChamber 使用相机。');
|
||||
}
|
||||
return '无法打开相机:${error.description ?? error.code}';
|
||||
return trArgs('无法打开相机:{0}', [error.description ?? error.code]);
|
||||
}
|
||||
return '无法打开相机:$error';
|
||||
return trArgs('无法打开相机:{0}', [error]);
|
||||
}
|
||||
|
||||
void _onFrame(CameraImage image) {
|
||||
@@ -187,14 +189,14 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
if (text.trim().startsWith('openchamber://connect')) {
|
||||
_accept(text.trim());
|
||||
} else {
|
||||
_showHint('这不是 OpenChamber 配对二维码');
|
||||
_showHint(tr('这不是 OpenChamber 配对二维码'));
|
||||
}
|
||||
}).catchError((Object error) {
|
||||
_decoding = false;
|
||||
_decodeErrors += 1;
|
||||
if (_decodeErrors == 1) {
|
||||
debugPrint('qr: decode failed: $error');
|
||||
if (mounted) _showHint('二维码解码出错,请重试');
|
||||
if (mounted) _showHint(tr('二维码解码出错,请重试'));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -247,7 +249,7 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
await controller.setFlashMode(_torch ? FlashMode.off : FlashMode.torch);
|
||||
if (mounted) setState(() => _torch = !_torch);
|
||||
} catch (_) {
|
||||
if (mounted) _showHint('这个相机不支持手电筒');
|
||||
if (mounted) _showHint(tr('这个相机不支持手电筒'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,13 +275,13 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
const Icon(Icons.no_photography_outlined,
|
||||
size: 36, color: Colors.white70),
|
||||
const SizedBox(height: 12),
|
||||
Text(_error!,
|
||||
AppText(_error!,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(color: Colors.white70)),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton.tonal(
|
||||
onPressed: _start,
|
||||
child: const Text('重试'),
|
||||
child: const AppText('重试'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -294,14 +296,14 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: '关闭',
|
||||
tooltip: tr('关闭'),
|
||||
icon: const Icon(Icons.close),
|
||||
color: Colors.white,
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
tooltip: '手电筒',
|
||||
tooltip: tr('手电筒'),
|
||||
icon: Icon(_torch ? Icons.flash_on : Icons.flash_off),
|
||||
color: Colors.white,
|
||||
onPressed: _toggleTorch,
|
||||
@@ -313,13 +315,13 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
padding: const EdgeInsets.fromLTRB(24, 0, 24, 32),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
AppText(
|
||||
_hint ?? '把配对二维码放进框内',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
const Text(
|
||||
const AppText(
|
||||
'在 OpenChamber 网页端打开「连接设备」,选择二维码',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.white60, fontSize: 12),
|
||||
@@ -327,8 +329,9 @@ class _ScanQrScreenState extends State<ScanQrScreen> {
|
||||
if (ready && _frames > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
'${_frameShape ?? ''} · 已扫描 $_frames 帧 / 解码 $_decodeAttempts 次',
|
||||
child: AppText(
|
||||
trArgs('{0} · 已扫描 {1} 帧 / 解码 {2} 次',
|
||||
[_frameShape ?? '', _frames, _decodeAttempts]),
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color: Colors.white38,
|
||||
|
||||
@@ -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> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
|
||||
import '../state.dart';
|
||||
import '../storage.dart';
|
||||
import 'scan_qr_screen.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
/// The first screen: the saved servers, or the connect form.
|
||||
class ServersScreen extends StatefulWidget {
|
||||
@@ -70,11 +71,11 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('OpenChamber',
|
||||
AppText('OpenChamber',
|
||||
style: theme.textTheme.headlineMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
Text('连接你的 OpenChamber 服务器',
|
||||
AppText('连接你的 OpenChamber 服务器',
|
||||
style: theme.textTheme.bodyMedium
|
||||
?.copyWith(color: theme.hintColor)),
|
||||
],
|
||||
@@ -83,7 +84,7 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
if (widget.app.error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: Text(widget.app.error!,
|
||||
child: AppText(widget.app.error!,
|
||||
style: TextStyle(color: theme.colorScheme.error, fontSize: 13)),
|
||||
),
|
||||
Expanded(
|
||||
@@ -98,7 +99,7 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => _startEdit(null),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('添加服务器'),
|
||||
label: const AppText('添加服务器'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
@@ -106,7 +107,7 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
child: FilledButton.tonalIcon(
|
||||
onPressed: _pair,
|
||||
icon: const Icon(Icons.qr_code_2, size: 18),
|
||||
label: const Text('配对链接'),
|
||||
label: const AppText('配对链接'),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -126,14 +127,14 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
child: ListTile(
|
||||
title: Text(c.label, style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
title: AppText(c.label, style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(c.isRelay ? '经由 Relay · ${c.serverId}' : c.url,
|
||||
AppText(c.isRelay ? trArgs('经由 Relay · {0}', [c.serverId]) : c.url,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
if (!c.isRelay && c.proxy.isNotEmpty)
|
||||
Text('经由 ${c.proxy}',
|
||||
AppText(trArgs('经由 {0}', [c.proxy]),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
@@ -143,9 +144,9 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (connected)
|
||||
Text('已连接', style: TextStyle(color: theme.colorScheme.primary))
|
||||
AppText('已连接', style: TextStyle(color: theme.colorScheme.primary))
|
||||
else
|
||||
TextButton(onPressed: () => _connect(c), child: const Text('连接')),
|
||||
TextButton(onPressed: () => _connect(c), child: const AppText('连接')),
|
||||
PopupMenuButton<String>(
|
||||
onSelected: (v) {
|
||||
if (v == 'edit') {
|
||||
@@ -155,8 +156,8 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
}
|
||||
},
|
||||
itemBuilder: (_) => const [
|
||||
PopupMenuItem(value: 'edit', child: Text('编辑')),
|
||||
PopupMenuItem(value: 'delete', child: Text('删除')),
|
||||
PopupMenuItem(value: 'edit', child: AppText('编辑')),
|
||||
PopupMenuItem(value: 'delete', child: AppText('删除')),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -221,7 +222,7 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
setState(() => _editing = false);
|
||||
},
|
||||
),
|
||||
title: Text(_editNew ? '添加服务器' : '连接 ${_edit!.label}'),
|
||||
title: AppText(_editNew ? '添加服务器' : trArgs('连接 {0}', [_edit!.label])),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -230,15 +231,16 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
TextField(
|
||||
controller: TextEditingController(text: _label),
|
||||
onChanged: (v) => _label = v,
|
||||
decoration: const InputDecoration(hintText: '如 我的电脑', border: OutlineInputBorder()),
|
||||
decoration: InputDecoration(
|
||||
hintText: tr('如 我的电脑'), border: const OutlineInputBorder()),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
if (_edit?.isRelay == true) ...[
|
||||
const ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(Icons.lock_outline, size: 20),
|
||||
title: Text('通过 Relay 连接'),
|
||||
subtitle: Text('端到端加密;服务器与设备令牌保持不变'),
|
||||
title: AppText('通过 Relay 连接'),
|
||||
subtitle: AppText('端到端加密;服务器与设备令牌保持不变'),
|
||||
),
|
||||
] else ...[
|
||||
_labelText('服务器地址'),
|
||||
@@ -255,19 +257,22 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
controller: TextEditingController(text: _proxy),
|
||||
onChanged: (v) => _proxy = v,
|
||||
keyboardType: TextInputType.url,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'http://… 或 socks5://…', border: OutlineInputBorder()),
|
||||
decoration: InputDecoration(
|
||||
hintText: tr('http://… 或 socks5://…'),
|
||||
border: const OutlineInputBorder()),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_labelText('自签证书指纹(可选)'),
|
||||
TextField(
|
||||
controller: TextEditingController(text: _fingerprint),
|
||||
onChanged: (v) => _fingerprint = v,
|
||||
decoration: const InputDecoration(hintText: 'SHA-256 十六进制', border: OutlineInputBorder()),
|
||||
decoration: InputDecoration(
|
||||
hintText: tr('SHA-256 十六进制'),
|
||||
border: const OutlineInputBorder()),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('信任自签名证书'),
|
||||
title: const AppText('信任自签名证书'),
|
||||
value: _insecure,
|
||||
onChanged: (v) => setState(() => _insecure = v),
|
||||
),
|
||||
@@ -279,15 +284,15 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
focusNode: _passwordFocus,
|
||||
onChanged: (v) => _password = v,
|
||||
obscureText: true,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '服务器密码;服务器未设置可留空',
|
||||
border: OutlineInputBorder()),
|
||||
decoration: InputDecoration(
|
||||
hintText: tr('服务器密码;服务器未设置可留空'),
|
||||
border: const OutlineInputBorder()),
|
||||
),
|
||||
],
|
||||
if (_formError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(_formError!,
|
||||
child: AppText(_formError!,
|
||||
style: TextStyle(color: theme.colorScheme.error)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -296,7 +301,7 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
child: _connecting
|
||||
? const SizedBox(
|
||||
height: 20, width: 20, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Text('连接'),
|
||||
: const AppText('连接'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -305,7 +310,7 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
|
||||
Widget _labelText(String s) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(s, style: Theme.of(context).textTheme.bodySmall),
|
||||
child: AppText(s, style: Theme.of(context).textTheme.bodySmall),
|
||||
);
|
||||
|
||||
Future<void> _submit() async {
|
||||
@@ -348,7 +353,8 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
|
||||
/// The server asked for a password: put the caret where it is typed.
|
||||
void _focusPasswordIfNeeded(String? message) {
|
||||
if (message == null || !message.contains('需要密码')) return;
|
||||
// The message is already in the UI's language; look for the same word.
|
||||
if (message == null || !message.contains(tr('需要密码'))) return;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) _passwordFocus.requestFocus();
|
||||
});
|
||||
@@ -364,16 +370,16 @@ class _ServersScreenState extends State<ServersScreen> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('删除服务器?'),
|
||||
content: Text('“${c.label}”将从列表移除,设备令牌也会删除。'),
|
||||
title: const AppText('删除服务器?'),
|
||||
content: AppText(trArgs('“{0}”将从列表移除,设备令牌也会删除。', [c.label])),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('取消')),
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const AppText('取消')),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
widget.app.removeConnection(c);
|
||||
},
|
||||
child: const Text('删除'),
|
||||
child: const AppText('删除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -452,7 +458,7 @@ class _PairingDialogState extends State<_PairingDialog> {
|
||||
}
|
||||
setState(() {
|
||||
_busy = false;
|
||||
_error = widget.app.lastError ?? '配对失败';
|
||||
_error = widget.app.lastError ?? tr('配对失败');
|
||||
});
|
||||
widget.app.clearLastError();
|
||||
}
|
||||
@@ -461,14 +467,14 @@ class _PairingDialogState extends State<_PairingDialog> {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return AlertDialog(
|
||||
title: const Text('配对链接'),
|
||||
title: const AppText('配对链接'),
|
||||
content: SizedBox(
|
||||
width: 420,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
AppText(
|
||||
'在 OpenChamber 网页端打开「连接设备」,粘贴链接或直接扫描二维码。'
|
||||
'链接里带一次性密钥,以及直连地址或私有 Relay。',
|
||||
style: TextStyle(fontSize: 12.5, color: theme.hintColor),
|
||||
@@ -489,7 +495,7 @@ class _PairingDialogState extends State<_PairingDialog> {
|
||||
if (_error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(_error!,
|
||||
child: AppText(_error!,
|
||||
style: TextStyle(color: theme.colorScheme.error, fontSize: 12.5)),
|
||||
),
|
||||
Row(
|
||||
@@ -497,13 +503,13 @@ class _PairingDialogState extends State<_PairingDialog> {
|
||||
TextButton.icon(
|
||||
onPressed: _busy ? null : _scan,
|
||||
icon: const Icon(Icons.qr_code_scanner, size: 18),
|
||||
label: const Text('扫码'),
|
||||
label: const AppText('扫码'),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
TextButton.icon(
|
||||
onPressed: _busy ? null : _paste,
|
||||
icon: const Icon(Icons.content_paste, size: 18),
|
||||
label: const Text('粘贴'),
|
||||
label: const AppText('粘贴'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -513,14 +519,14 @@ class _PairingDialogState extends State<_PairingDialog> {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _busy ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('取消'),
|
||||
child: const AppText('取消'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _busy ? null : _connect,
|
||||
child: _busy
|
||||
? const SizedBox(
|
||||
width: 18, height: 18, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Text('配对并连接'),
|
||||
: const AppText('配对并连接'),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -10,6 +10,7 @@ import '../widgets/project_icon.dart';
|
||||
import 'features_screen.dart';
|
||||
import 'servers_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
/// The session list: a drawer on a phone, a persistent column on a wide
|
||||
/// layout. Sessions are grouped by project, dated within it, and a row swipes
|
||||
@@ -80,13 +81,13 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
children: [
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Text('会话',
|
||||
child: AppText('会话',
|
||||
style: TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(_searchOpen ? Icons.close : Icons.search),
|
||||
tooltip: '搜索',
|
||||
tooltip: tr('搜索'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_searchOpen = !_searchOpen;
|
||||
@@ -99,7 +100,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
tooltip: '新会话',
|
||||
tooltip: tr('新会话'),
|
||||
onPressed: () => _newSession(),
|
||||
),
|
||||
],
|
||||
@@ -112,10 +113,10 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
controller: _searchCtrl,
|
||||
autofocus: true,
|
||||
onChanged: _onSearchChanged,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '搜索会话',
|
||||
prefixIcon: Icon(Icons.search),
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
hintText: tr('搜索会话'),
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
),
|
||||
),
|
||||
@@ -126,13 +127,13 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(_app.error!,
|
||||
child: AppText(_app.error!,
|
||||
style: TextStyle(
|
||||
color: scheme.error, fontSize: 13)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _app.refreshSessions,
|
||||
child: const Text('重试')),
|
||||
child: const AppText('重试')),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -171,7 +172,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
size: 18, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
_app.connectionName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -188,12 +189,12 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.widgets_outlined),
|
||||
tooltip: '全部功能',
|
||||
tooltip: tr('全部功能'),
|
||||
onPressed: _openFeatures,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.settings_outlined),
|
||||
tooltip: '设置',
|
||||
tooltip: tr('设置'),
|
||||
onPressed: _openSettings,
|
||||
),
|
||||
],
|
||||
@@ -241,10 +242,10 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(_searchCtrl.text.isEmpty ? '暂无会话' : '没有匹配的会话'),
|
||||
AppText(_searchCtrl.text.isEmpty ? '暂无会话' : '没有匹配的会话'),
|
||||
const SizedBox(height: 8),
|
||||
FilledButton(
|
||||
onPressed: () => _newSession(), child: const Text('新会话')),
|
||||
onPressed: () => _newSession(), child: const AppText('新会话')),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -349,7 +350,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
),
|
||||
],
|
||||
),
|
||||
title: Text(
|
||||
title: AppText(
|
||||
group.label.isEmpty ? '未命名项目' : group.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -361,7 +362,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
),
|
||||
subtitle: group.path.isEmpty
|
||||
? null
|
||||
: Text(
|
||||
: AppText(
|
||||
group.path,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -375,7 +376,9 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.add, size: 20),
|
||||
padding: EdgeInsets.zero,
|
||||
tooltip: group.key == AppState.chatTarget ? '新建聊天' : '在此项目新会话',
|
||||
tooltip: group.key == AppState.chatTarget
|
||||
? tr('新建聊天')
|
||||
: tr('在此项目新会话'),
|
||||
onPressed: () => _newSession(
|
||||
directory: group.key == AppState.chatTarget
|
||||
? AppState.chatTarget
|
||||
@@ -397,7 +400,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
Widget _caption(String label) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(28, 6, 12, 2),
|
||||
child: Text(label,
|
||||
child: AppText(label,
|
||||
style: TextStyle(
|
||||
fontSize: 11, color: Theme.of(context).hintColor)),
|
||||
);
|
||||
@@ -456,7 +459,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
size: 13, color: Theme.of(context).hintColor),
|
||||
const SizedBox(width: 5),
|
||||
Expanded(
|
||||
child: Text('已置顶',
|
||||
child: AppText('已置顶',
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
@@ -475,25 +478,25 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
|
||||
Widget _draftRow(SessionDraft draft) {
|
||||
final theme = Theme.of(context);
|
||||
final label = draft.firstLine.isEmpty ? '新会话' : draft.firstLine;
|
||||
final label = draft.firstLine.isEmpty ? tr('新会话') : draft.firstLine;
|
||||
final project = _app.projectLabelFor(draft.directory);
|
||||
return ListTile(
|
||||
selected: _app.draftOpen,
|
||||
leading: Icon(Icons.edit_outlined, size: 18, color: theme.hintColor),
|
||||
title: Text(
|
||||
title: AppText(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
subtitle: Text(
|
||||
project.isEmpty ? '草稿' : '草稿 · $project',
|
||||
subtitle: AppText(
|
||||
project.isEmpty ? '草稿' : trArgs('草稿 · {0}', [project]),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.close, size: 18),
|
||||
tooltip: '丢弃草稿',
|
||||
tooltip: tr('丢弃草稿'),
|
||||
onPressed: () => _app.discardDraft(),
|
||||
),
|
||||
onTap: () {
|
||||
@@ -566,21 +569,21 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
SlidableAction(
|
||||
onPressed: (_) => _app.togglePin(session),
|
||||
icon: Icons.push_pin_outlined,
|
||||
label: session.isPinned ? '取消置顶' : '置顶',
|
||||
label: session.isPinned ? tr('取消置顶') : tr('置顶'),
|
||||
backgroundColor: scheme.secondaryContainer,
|
||||
foregroundColor: scheme.onSecondaryContainer,
|
||||
),
|
||||
SlidableAction(
|
||||
onPressed: (_) => _archive(session, archived),
|
||||
icon: archived ? Icons.unarchive_outlined : Icons.archive_outlined,
|
||||
label: archived ? '取消归档' : '归档',
|
||||
label: archived ? tr('取消归档') : tr('归档'),
|
||||
backgroundColor: scheme.surfaceContainerHighest,
|
||||
foregroundColor: scheme.onSurface,
|
||||
),
|
||||
SlidableAction(
|
||||
onPressed: (_) => _confirmDelete(session),
|
||||
icon: Icons.delete_outline,
|
||||
label: '删除',
|
||||
label: tr('删除'),
|
||||
backgroundColor: scheme.errorContainer,
|
||||
foregroundColor: scheme.onErrorContainer,
|
||||
),
|
||||
@@ -612,7 +615,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
? Icons.expand_more
|
||||
: Icons.chevron_right,
|
||||
size: 18),
|
||||
tooltip: expanded ? '收起子代理' : '展开子代理',
|
||||
tooltip: expanded ? tr('收起子代理') : tr('展开子代理'),
|
||||
padding: EdgeInsets.zero,
|
||||
visualDensity: VisualDensity.compact,
|
||||
constraints:
|
||||
@@ -626,7 +629,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
}),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
title: AppText(
|
||||
session.title.isEmpty ? '(无标题会话)' : session.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -635,8 +638,8 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.w400,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
child ? '子代理 · ${_subtitle(session)}' : _subtitle(session),
|
||||
subtitle: AppText(
|
||||
child ? trArgs('子代理 · {0}', [_subtitle(session)]) : _subtitle(session),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
trailing: Row(
|
||||
@@ -693,22 +696,22 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
case 'copy':
|
||||
Clipboard.setData(ClipboardData(text: session.id));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('已复制会话 ID')));
|
||||
const SnackBar(content: AppText('已复制会话 ID')));
|
||||
break;
|
||||
}
|
||||
},
|
||||
itemBuilder: (_) => [
|
||||
if (!archived) ...[
|
||||
const PopupMenuItem(value: 'rename', child: Text('重命名')),
|
||||
const PopupMenuItem(value: 'rename', child: AppText('重命名')),
|
||||
PopupMenuItem(
|
||||
value: 'pin',
|
||||
child: Text(session.isPinned ? '取消置顶' : '置顶')),
|
||||
child: AppText(session.isPinned ? '取消置顶' : '置顶')),
|
||||
],
|
||||
PopupMenuItem(
|
||||
value: 'archive',
|
||||
child: Text(archived ? '取消归档' : '归档')),
|
||||
const PopupMenuItem(value: 'delete', child: Text('删除')),
|
||||
const PopupMenuItem(value: 'copy', child: Text('复制会话 ID')),
|
||||
child: AppText(archived ? '取消归档' : '归档')),
|
||||
const PopupMenuItem(value: 'delete', child: AppText('删除')),
|
||||
const PopupMenuItem(value: 'copy', child: AppText('复制会话 ID')),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -728,7 +731,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Text('载入更多'),
|
||||
: const AppText('载入更多'),
|
||||
),
|
||||
TextButton.icon(
|
||||
icon: Icon(
|
||||
@@ -736,12 +739,12 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
? Icons.expand_less
|
||||
: Icons.archive_outlined,
|
||||
size: 16),
|
||||
label: Text(
|
||||
label: AppText(
|
||||
_showArchived
|
||||
? '隐藏已归档'
|
||||
: archivedCount == null
|
||||
? '显示已归档'
|
||||
: '显示已归档 ($archivedCount)',
|
||||
: trArgs('显示已归档 ({0})', [archivedCount]),
|
||||
style: const TextStyle(fontSize: 12.5),
|
||||
),
|
||||
onPressed: app.archivedLoading ? null : _toggleArchived,
|
||||
@@ -762,7 +765,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
app.archivedSessions.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text('没有已归档的会话',
|
||||
child: AppText('没有已归档的会话',
|
||||
style: TextStyle(fontSize: 12, color: scheme.outline)),
|
||||
),
|
||||
],
|
||||
@@ -782,7 +785,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
final parts = <String>[];
|
||||
if (s.agent.isNotEmpty) parts.add(s.agent);
|
||||
final children = _childrenOf(s).length;
|
||||
if (children > 0) parts.add('$children 个子代理');
|
||||
if (children > 0) parts.add(trArgs('{0} 个子代理', [children]));
|
||||
if (s.model != null) parts.add(_app.modelName(s.model));
|
||||
if (s.updated > 0) {
|
||||
final t = DateTime.fromMillisecondsSinceEpoch(s.updated);
|
||||
@@ -809,18 +812,18 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('重命名'),
|
||||
title: const AppText('重命名'),
|
||||
content: TextField(controller: ctrl, autofocus: true),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消')),
|
||||
child: const AppText('取消')),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_app.client?.updateSession(s.id, title: ctrl.text);
|
||||
},
|
||||
child: const Text('保存'),
|
||||
child: const AppText('保存'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -831,12 +834,12 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('删除会话?'),
|
||||
content: Text('“${s.title}”及其子会话将被删除,且无法恢复。'),
|
||||
title: const AppText('删除会话?'),
|
||||
content: AppText(trArgs('“{0}”及其子会话将被删除,且无法恢复。', [s.title])),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消')),
|
||||
child: const AppText('取消')),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
@@ -845,7 +848,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
_app.archivedSessions.removeWhere((x) => x.id == s.id);
|
||||
_app.touch();
|
||||
},
|
||||
child: const Text('删除'),
|
||||
child: const AppText('删除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -862,18 +865,20 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(12),
|
||||
child: Text('服务器',
|
||||
child: AppText('服务器',
|
||||
style:
|
||||
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
for (final c in app.connections) ...[
|
||||
ListTile(
|
||||
title: Text(c.label),
|
||||
subtitle: Text(c.isRelay
|
||||
? '经由 Relay · ${c.serverId}'
|
||||
: (c.proxy.isEmpty ? c.url : '${c.url}\n经由 ${c.proxy}')),
|
||||
title: AppText(c.label),
|
||||
subtitle: AppText(c.isRelay
|
||||
? trArgs('经由 Relay · {0}', [c.serverId])
|
||||
: (c.proxy.isEmpty
|
||||
? c.url
|
||||
: trArgs('{0}\n经由 {1}', [c.url, c.proxy]))),
|
||||
trailing: app.conn?.id == c.id
|
||||
? Text('已连接',
|
||||
? AppText('已连接',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.primary))
|
||||
: null,
|
||||
@@ -885,7 +890,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
],
|
||||
ListTile(
|
||||
leading: const Icon(Icons.add),
|
||||
title: const Text('添加服务器'),
|
||||
title: const AppText('添加服务器'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
@@ -895,8 +900,8 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.qr_code_2),
|
||||
title: const Text('配对链接'),
|
||||
subtitle: const Text('直连地址或 OpenChamber Relay'),
|
||||
title: const AppText('配对链接'),
|
||||
subtitle: const AppText('直连地址或 OpenChamber Relay'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
showPairingDialog(context, app);
|
||||
@@ -905,7 +910,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
||||
if (app.client != null)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.link_off),
|
||||
title: const Text('断开当前连接'),
|
||||
title: const AppText('断开当前连接'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
app.disconnect();
|
||||
@@ -930,4 +935,4 @@ class _SessionGroup {
|
||||
required this.path,
|
||||
required this.sessions,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart'
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/models.dart';
|
||||
import '../l10n.dart';
|
||||
import '../appearance_prefs.dart';
|
||||
import '../pets/pet_library.dart';
|
||||
import '../pets/pet_pack.dart';
|
||||
@@ -20,12 +21,18 @@ class SettingsScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('设置')),
|
||||
appBar: AppBar(title: const AppText('设置')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.only(top: 4, bottom: 32),
|
||||
children: [
|
||||
const _SectionHeader('常规'),
|
||||
_Section(children: [
|
||||
_NavTile(
|
||||
icon: Icons.translate,
|
||||
title: '语言',
|
||||
subtitle: '跟随系统、中文或 English',
|
||||
builder: (_) => const LanguageSettingsPage(),
|
||||
),
|
||||
_NavTile(
|
||||
icon: Icons.tune,
|
||||
title: '通用',
|
||||
@@ -114,7 +121,9 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
final ok = await app.setAgentToolSetting(key, value);
|
||||
if (!ok && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('保存失败:${app.lastError ?? '未知错误'}')),
|
||||
SnackBar(
|
||||
content: AppText(
|
||||
trArgs('保存失败:{0}', [app.lastError ?? tr('未知错误')]))),
|
||||
);
|
||||
app.clearLastError();
|
||||
}
|
||||
@@ -124,7 +133,7 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('通用')),
|
||||
appBar: AppBar(title: const AppText('通用')),
|
||||
body: ListenableBuilder(
|
||||
listenable: app,
|
||||
builder: (context, _) => ListView(
|
||||
@@ -149,8 +158,8 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
if (app.imageToolEnabled)
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.fromLTRB(52, 0, 16, 4),
|
||||
title: const Text('图像模型'),
|
||||
subtitle: Text(_imageModelName(),
|
||||
title: const AppText('图像模型'),
|
||||
subtitle: AppText(_imageModelName(),
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
trailing: const Icon(Icons.chevron_right, size: 20),
|
||||
onTap: _pickImageModel,
|
||||
@@ -214,8 +223,8 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
value: value,
|
||||
onChanged: (v) => _save(key, v),
|
||||
secondary: Icon(icon, size: 20),
|
||||
title: Text(title),
|
||||
subtitle: Text(subtitle),
|
||||
title: AppText(title),
|
||||
subtitle: AppText(subtitle),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -248,10 +257,10 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
onChanged: (v) =>
|
||||
_save('agentMemoryDreamingEnabled', v ?? false),
|
||||
),
|
||||
Expanded(child: Text('整理记忆')),
|
||||
Expanded(child: AppText('整理记忆')),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.info_outline, size: 18),
|
||||
tooltip: '整理记忆',
|
||||
tooltip: tr('整理记忆'),
|
||||
onPressed: _dreamingInfo,
|
||||
),
|
||||
],
|
||||
@@ -270,7 +279,7 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
),
|
||||
child: Text(name,
|
||||
child: AppText(name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 13)),
|
||||
@@ -286,9 +295,9 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
style: TextStyle(
|
||||
fontSize: 13, color: theme.colorScheme.onSurface),
|
||||
items: [
|
||||
const DropdownMenuItem(value: '', child: Text('默认')),
|
||||
const DropdownMenuItem(value: '', child: AppText('默认')),
|
||||
for (final v in variants)
|
||||
DropdownMenuItem(value: v, child: Text(v)),
|
||||
DropdownMenuItem(value: v, child: AppText(v)),
|
||||
],
|
||||
onChanged: (v) => _save('agentMemoryDreamingVariant', v ?? ''),
|
||||
),
|
||||
@@ -312,12 +321,12 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialog) => AlertDialog(
|
||||
title: const Text('整理记忆'),
|
||||
content: const Text(
|
||||
title: const AppText('整理记忆'),
|
||||
content: const AppText(
|
||||
'每天一次,在没有会话运行时,智能体会在后台整理记忆:合并重复条目,删除已过时或项目文档中已有的内容。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialog), child: const Text('知道了')),
|
||||
onPressed: () => Navigator.pop(dialog), child: const AppText('知道了')),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -328,7 +337,7 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
||||
if (!mounted) return;
|
||||
if (models.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('你的提供商中没有图像模型')),
|
||||
const SnackBar(content: AppText('你的提供商中没有图像模型')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -398,7 +407,7 @@ Future<String?> _chooseFromSheet({
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: Text(title,
|
||||
child: AppText(title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
@@ -407,7 +416,7 @@ Future<String?> _chooseFromSheet({
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(noneLabel),
|
||||
title: AppText(noneLabel),
|
||||
trailing: selected.isEmpty
|
||||
? const Icon(Icons.check, size: 20)
|
||||
: null,
|
||||
@@ -415,9 +424,9 @@ Future<String?> _chooseFromSheet({
|
||||
),
|
||||
for (final option in options)
|
||||
ListTile(
|
||||
title: Text(option.name,
|
||||
title: AppText(option.name,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
subtitle: option.note.isEmpty ? null : Text(option.note),
|
||||
subtitle: option.note.isEmpty ? null : AppText(option.note),
|
||||
trailing: selected == option.value
|
||||
? const Icon(Icons.check, size: 20)
|
||||
: null,
|
||||
@@ -432,6 +441,62 @@ Future<String?> _chooseFromSheet({
|
||||
);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- language
|
||||
|
||||
/// The UI language: follow the system, or pin Chinese or English.
|
||||
class LanguageSettingsPage extends StatelessWidget {
|
||||
const LanguageSettingsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = L10n.instance;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const AppText('语言')),
|
||||
body: ListenableBuilder(
|
||||
listenable: l10n,
|
||||
builder: (context, _) {
|
||||
final english = l10n.isEnglish;
|
||||
final systemName = l10n.locale.languageCode == 'zh'
|
||||
? AppLanguage.zh.labelFor(english)
|
||||
: AppLanguage.en.labelFor(english);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
||||
children: [
|
||||
RadioGroup<AppLanguage>(
|
||||
groupValue: l10n.choice,
|
||||
onChanged: (value) {
|
||||
if (value != null) l10n.setLanguage(value);
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
for (final choice in AppLanguage.values)
|
||||
RadioListTile<AppLanguage>(
|
||||
value: choice,
|
||||
title: AppText(choice.labelFor(english)),
|
||||
subtitle: choice == AppLanguage.system
|
||||
? AppText(trArgs('当前:{0}', [systemName]))
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
|
||||
child: AppText(
|
||||
'界面文字与系统自带的日期、时间选择器会一起切换。',
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: Theme.of(context).hintColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- chat
|
||||
|
||||
class ChatSettingsPage extends StatefulWidget {
|
||||
@@ -454,7 +519,7 @@ class _ChatSettingsPageState extends State<ChatSettingsPage> {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('聊天')),
|
||||
appBar: AppBar(title: const AppText('聊天')),
|
||||
body: ListenableBuilder(
|
||||
listenable: widget.app,
|
||||
builder: (context, _) {
|
||||
@@ -463,8 +528,8 @@ class _ChatSettingsPageState extends State<ChatSettingsPage> {
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
||||
children: [
|
||||
const ListTile(
|
||||
title: Text('追问处理行为'),
|
||||
subtitle: Text('运行中按发送时,消息默认怎么处理。与网页端设置同步。'),
|
||||
title: AppText('追问处理行为'),
|
||||
subtitle: AppText('运行中按发送时,消息默认怎么处理。与网页端设置同步。'),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 6),
|
||||
@@ -473,12 +538,12 @@ class _ChatSettingsPageState extends State<ChatSettingsPage> {
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
label: const Text('转向'),
|
||||
label: const AppText('转向'),
|
||||
selected: steer,
|
||||
onSelected: (_) => _setFollowUp('steer'),
|
||||
),
|
||||
ChoiceChip(
|
||||
label: const Text('排队'),
|
||||
label: const AppText('排队'),
|
||||
selected: !steer,
|
||||
onSelected: (_) => _setFollowUp('queue'),
|
||||
),
|
||||
@@ -487,7 +552,7 @@ class _ChatSettingsPageState extends State<ChatSettingsPage> {
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
steer ? '转向:在下一步加入当前回合,工作继续。' : '排队:等当前回合结束后再发送。',
|
||||
style: TextStyle(fontSize: 12.5, color: theme.hintColor),
|
||||
),
|
||||
@@ -503,7 +568,7 @@ class _ChatSettingsPageState extends State<ChatSettingsPage> {
|
||||
final ok = await widget.app.setFollowUpBehavior(value);
|
||||
if (!ok && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(widget.app.lastError ?? '保存失败')),
|
||||
SnackBar(content: AppText(widget.app.lastError ?? '保存失败')),
|
||||
);
|
||||
widget.app.clearLastError();
|
||||
}
|
||||
@@ -525,7 +590,7 @@ class ThemeSettingsPage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final look = AppearancePrefs.instance;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('主题')),
|
||||
appBar: AppBar(title: const AppText('主题')),
|
||||
body: ListenableBuilder(
|
||||
listenable: look,
|
||||
builder: (context, _) {
|
||||
@@ -535,7 +600,7 @@ class ThemeSettingsPage extends StatelessWidget {
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Text('主题只保存在本机,不随服务器同步。',
|
||||
child: AppText('主题只保存在本机,不随服务器同步。',
|
||||
style: TextStyle(fontSize: 12.5)),
|
||||
),
|
||||
const _Label('主题模式'),
|
||||
@@ -547,7 +612,7 @@ class ThemeSettingsPage extends StatelessWidget {
|
||||
children: [
|
||||
for (final (mode, label) in _modes)
|
||||
ChoiceChip(
|
||||
label: Text(label),
|
||||
label: AppText(label),
|
||||
selected: look.themeMode == mode,
|
||||
onSelected: (_) => look.setThemeMode(mode),
|
||||
),
|
||||
@@ -579,7 +644,7 @@ class ThemeSettingsPage extends StatelessWidget {
|
||||
return Semantics(
|
||||
button: true,
|
||||
selected: selected,
|
||||
label: '主题色 ${seed.toRadixString(16)}',
|
||||
label: trArgs('主题色 {0}', [seed.toRadixString(16)]),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
onTap: () => look.setSeedColor(seed),
|
||||
@@ -625,7 +690,7 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('宠物')),
|
||||
appBar: AppBar(title: const AppText('宠物')),
|
||||
body: ListenableBuilder(
|
||||
listenable: PetLibrary.instance,
|
||||
builder: (context, _) {
|
||||
@@ -636,7 +701,7 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Text('默认不提供宠物;宠物包只存放在本机。',
|
||||
child: AppText('默认不提供宠物;宠物包只存放在本机。',
|
||||
style: TextStyle(fontSize: 12.5)),
|
||||
),
|
||||
if (pack == null) ..._empty(theme) else ..._loaded(theme, pack),
|
||||
@@ -649,15 +714,15 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
|
||||
List<Widget> _empty(ThemeData theme) => [
|
||||
const ListTile(
|
||||
title: Text('尚未导入宠物'),
|
||||
subtitle: Text('导入一个宠物包(.zip)后,它会站在输入框上方。'),
|
||||
title: AppText('尚未导入宠物'),
|
||||
subtitle: AppText('导入一个宠物包(.zip)后,它会站在输入框上方。'),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: FilledButton.tonalIcon(
|
||||
onPressed: _importPet,
|
||||
icon: const Icon(Icons.file_upload_outlined, size: 18),
|
||||
label: const Text('导入宠物包'),
|
||||
label: const AppText('导入宠物包'),
|
||||
),
|
||||
),
|
||||
];
|
||||
@@ -668,14 +733,14 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
[pack.author, pack.license].where((s) => s.trim().isNotEmpty).join(' · ');
|
||||
return [
|
||||
ListTile(
|
||||
title: Text(pack.name.isEmpty ? pack.id : pack.name),
|
||||
title: AppText(pack.name.isEmpty ? pack.id : pack.name),
|
||||
subtitle: info.isEmpty
|
||||
? null
|
||||
: Text(info, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
: AppText(info, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('启用宠物'),
|
||||
subtitle: const Text('站在输入框上方,默认关闭'),
|
||||
title: const AppText('启用宠物'),
|
||||
subtitle: const AppText('站在输入框上方,默认关闭'),
|
||||
value: library.enabled,
|
||||
onChanged: (v) => library.setEnabled(v),
|
||||
),
|
||||
@@ -691,7 +756,7 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
(64.0, '大'),
|
||||
])
|
||||
ChoiceChip(
|
||||
label: Text(label),
|
||||
label: AppText(label),
|
||||
selected: (library.size - size).abs() < 0.5,
|
||||
onSelected: (_) => library.setSize(size),
|
||||
),
|
||||
@@ -705,12 +770,12 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: _importPet,
|
||||
icon: const Icon(Icons.swap_horiz, size: 18),
|
||||
label: const Text('更换宠物包'),
|
||||
label: const AppText('更换宠物包'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TextButton(
|
||||
onPressed: _confirmRemovePet,
|
||||
child: const Text('移除'),
|
||||
child: const AppText('移除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -721,7 +786,7 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
Future<void> _importPet() async {
|
||||
try {
|
||||
final file = await FilePicker.pickFile(
|
||||
dialogTitle: '选择宠物包(.zip)',
|
||||
dialogTitle: tr('选择宠物包(.zip)'),
|
||||
type: FileType.custom,
|
||||
allowedExtensions: const ['zip'],
|
||||
);
|
||||
@@ -730,12 +795,14 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
final pack = await PetLibrary.instance.importZip(bytes);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('已导入 ${pack.name.isEmpty ? pack.id : pack.name}')),
|
||||
SnackBar(
|
||||
content: AppText(trArgs(
|
||||
'已导入 {0}', [pack.name.isEmpty ? pack.id : pack.name]))),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('导入失败:$e')),
|
||||
SnackBar(content: AppText(trArgs('导入失败:{0}', [e]))),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -744,15 +811,15 @@ class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialog) => AlertDialog(
|
||||
title: const Text('移除宠物?'),
|
||||
content: const Text('本机保存的宠物包会被删除。'),
|
||||
title: const AppText('移除宠物?'),
|
||||
content: const AppText('本机保存的宠物包会被删除。'),
|
||||
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('移除')),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -812,7 +879,7 @@ class _AboutSettingsPageState extends State<AboutSettingsPage> {
|
||||
: value.isEmpty
|
||||
? '未获取到'
|
||||
: value;
|
||||
return Text(text,
|
||||
return AppText(text,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: text == value && value.isNotEmpty
|
||||
@@ -826,11 +893,11 @@ class _AboutSettingsPageState extends State<AboutSettingsPage> {
|
||||
final versions = _versions;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('关于'),
|
||||
title: const AppText('关于'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: '重新获取服务端版本',
|
||||
tooltip: tr('重新获取服务端版本'),
|
||||
onPressed: _loading ? null : _load,
|
||||
),
|
||||
],
|
||||
@@ -857,10 +924,10 @@ class _AboutSettingsPageState extends State<AboutSettingsPage> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('OpenChamber',
|
||||
AppText('OpenChamber',
|
||||
style: theme.textTheme.titleLarge
|
||||
?.copyWith(fontWeight: FontWeight.w600)),
|
||||
Text('手机客户端',
|
||||
AppText('手机客户端',
|
||||
style: TextStyle(
|
||||
fontSize: 12.5, color: theme.hintColor)),
|
||||
],
|
||||
@@ -873,16 +940,16 @@ class _AboutSettingsPageState extends State<AboutSettingsPage> {
|
||||
_Section(children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.tag, size: 20),
|
||||
title: const Text('版本'),
|
||||
trailing: Text(
|
||||
title: const AppText('版本'),
|
||||
trailing: AppText(
|
||||
appVersion.isEmpty ? '未知' : appVersion,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.description_outlined, size: 20),
|
||||
title: const Text('开源许可'),
|
||||
subtitle: const Text('本应用使用的第三方组件与它们的许可证'),
|
||||
title: const AppText('开源许可'),
|
||||
subtitle: const AppText('本应用使用的第三方组件与它们的许可证'),
|
||||
trailing: const Icon(Icons.chevron_right, size: 20),
|
||||
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (_) => const LicensesPage(),
|
||||
@@ -893,12 +960,12 @@ class _AboutSettingsPageState extends State<AboutSettingsPage> {
|
||||
_Section(children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.terminal, size: 20),
|
||||
title: const Text('OpenCode'),
|
||||
title: const AppText('OpenCode'),
|
||||
trailing: _version(context, versions?.opencode ?? ''),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.hub_outlined, size: 20),
|
||||
title: const Text('OpenChamber'),
|
||||
title: const AppText('OpenChamber'),
|
||||
trailing: _version(context, versions?.openchamber ?? ''),
|
||||
),
|
||||
]),
|
||||
@@ -948,7 +1015,7 @@ class _LicensesPageState extends State<LicensesPage> {
|
||||
final theme = Theme.of(context);
|
||||
final licenses = _licenses;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('开源许可')),
|
||||
appBar: AppBar(title: const AppText('开源许可')),
|
||||
body: licenses == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView.separated(
|
||||
@@ -960,7 +1027,7 @@ class _LicensesPageState extends State<LicensesPage> {
|
||||
if (i == 0) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 14, 20, 14),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
'下面列出随本应用打包的第三方组件;点开可阅读完整许可证。',
|
||||
style:
|
||||
TextStyle(fontSize: 12.5, color: theme.hintColor),
|
||||
@@ -969,7 +1036,7 @@ class _LicensesPageState extends State<LicensesPage> {
|
||||
}
|
||||
final name = licenses.keys.elementAt(i - 1);
|
||||
return ListTile(
|
||||
title: Text(name),
|
||||
title: AppText(name),
|
||||
trailing: const Icon(Icons.chevron_right, size: 20),
|
||||
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (_) => _LicenseTextPage(
|
||||
@@ -1006,11 +1073,11 @@ class _LicenseTextPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(name)),
|
||||
appBar: AppBar(title: AppText(name)),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: SelectableText(
|
||||
text.isEmpty ? '该组件没有附带许可证文本。' : text,
|
||||
text.isEmpty ? tr('该组件没有附带许可证文本。') : text,
|
||||
style: const TextStyle(fontSize: 12, fontFamily: 'monospace', height: 1.45),
|
||||
),
|
||||
),
|
||||
@@ -1065,8 +1132,8 @@ class _NavTile extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Icon(icon, size: 22),
|
||||
title: Text(title),
|
||||
subtitle: Text(subtitle),
|
||||
title: AppText(title),
|
||||
subtitle: AppText(subtitle),
|
||||
trailing: const Icon(Icons.chevron_right, size: 20),
|
||||
onTap: () => Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: builder)),
|
||||
@@ -1087,7 +1154,7 @@ class _SectionHeader extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title,
|
||||
AppText(title,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
@@ -1096,7 +1163,7 @@ class _SectionHeader extends StatelessWidget {
|
||||
if (note != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: Text(note!,
|
||||
child: AppText(note!,
|
||||
style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
),
|
||||
],
|
||||
@@ -1113,7 +1180,7 @@ class _Label extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 2, 20, 6),
|
||||
child: Text(text,
|
||||
child: AppText(text,
|
||||
style: const TextStyle(fontSize: 13.5, fontWeight: FontWeight.w500)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:xterm/xterm.dart';
|
||||
import '../api/terminal.dart';
|
||||
import '../state.dart';
|
||||
import '../terminal_state.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
/// A light palette, so the terminal does not turn into a black hole in the
|
||||
/// light theme. (xterm ships only dark ones.)
|
||||
@@ -120,19 +121,20 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
ThemeData theme, TerminalTab tab, TerminalSessionState state) {
|
||||
final scheme = theme.colorScheme;
|
||||
final (label, color) = switch (state.link) {
|
||||
TerminalLinkState.idle => ('未启动', theme.hintColor),
|
||||
TerminalLinkState.creating => ('正在创建…', theme.hintColor),
|
||||
TerminalLinkState.connecting => ('正在连接…', theme.hintColor),
|
||||
TerminalLinkState.reconnecting => ('连接中断,正在重连…', scheme.error),
|
||||
TerminalLinkState.open => ('运行中', scheme.primary),
|
||||
TerminalLinkState.exited => (state.detail ?? '已退出', theme.hintColor),
|
||||
TerminalLinkState.error => (state.detail ?? '连接失败', scheme.error),
|
||||
TerminalLinkState.idle => (tr('未启动'), theme.hintColor),
|
||||
TerminalLinkState.creating => (tr('正在创建…'), theme.hintColor),
|
||||
TerminalLinkState.connecting => (tr('正在连接…'), theme.hintColor),
|
||||
TerminalLinkState.reconnecting =>
|
||||
(tr('连接中断,正在重连…'), scheme.error),
|
||||
TerminalLinkState.open => (tr('运行中'), scheme.primary),
|
||||
TerminalLinkState.exited => (state.detail ?? tr('已退出'), theme.hintColor),
|
||||
TerminalLinkState.error => (state.detail ?? tr('连接失败'), scheme.error),
|
||||
};
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PopupMenuButton<int>(
|
||||
tooltip: '切换终端',
|
||||
tooltip: tr('切换终端'),
|
||||
position: PopupMenuPosition.under,
|
||||
onSelected: _onTabMenu,
|
||||
itemBuilder: (_) => [
|
||||
@@ -152,7 +154,7 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
_workspace.tabs[i].label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -168,7 +170,7 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
children: [
|
||||
Icon(Icons.add, size: 18),
|
||||
SizedBox(width: 10),
|
||||
Text('新建终端'),
|
||||
AppText('新建终端'),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -181,7 +183,7 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
Icon(Icons.circle, size: 8, color: color),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
tab.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -191,7 +193,7 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
'· $label',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -205,13 +207,13 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '键盘',
|
||||
tooltip: tr('键盘'),
|
||||
visualDensity: VisualDensity.compact,
|
||||
icon: const Icon(Icons.keyboard_outlined, size: 18),
|
||||
onPressed: () => _focus.requestFocus(),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '重新启动',
|
||||
tooltip: tr('重新启动'),
|
||||
visualDensity: VisualDensity.compact,
|
||||
icon: const Icon(Icons.restart_alt, size: 18),
|
||||
onPressed: state.link == TerminalLinkState.exited ||
|
||||
@@ -221,7 +223,7 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
: null,
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
tooltip: '更多',
|
||||
tooltip: tr('更多'),
|
||||
icon: const Icon(Icons.more_vert, size: 18),
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
@@ -234,8 +236,8 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
}
|
||||
},
|
||||
itemBuilder: (_) => const [
|
||||
PopupMenuItem(value: 'clear', child: Text('清屏')),
|
||||
PopupMenuItem(value: 'close', child: Text('关闭此终端')),
|
||||
PopupMenuItem(value: 'clear', child: AppText('清屏')),
|
||||
PopupMenuItem(value: 'close', child: AppText('关闭此终端')),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -334,7 +336,7 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
border: Border.all(
|
||||
color: active ? scheme.primary : Colors.transparent, width: 1),
|
||||
),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
label,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
@@ -353,4 +355,4 @@ class _TerminalPanelState extends State<TerminalPanel> {
|
||||
|
||||
void _sendText(TerminalSessionState state, String text) =>
|
||||
state.model.textInput(text);
|
||||
}
|
||||
}
|
||||
+30
-29
@@ -13,6 +13,7 @@ import 'api/client.dart';
|
||||
import 'api/models.dart';
|
||||
import 'api/pairing.dart';
|
||||
import 'api/relay_transport.dart';
|
||||
import 'l10n.dart';
|
||||
import 'storage.dart';
|
||||
import 'terminal_state.dart';
|
||||
|
||||
@@ -174,7 +175,7 @@ class AppState extends ChangeNotifier {
|
||||
/// The name of the connected server, for the sidebar footer.
|
||||
String get connectionName {
|
||||
final c = conn;
|
||||
if (c == null) return '未连接';
|
||||
if (c == null) return tr('未连接');
|
||||
final label = c.label.trim();
|
||||
if (label.isNotEmpty) return label;
|
||||
final host = Uri.tryParse(c.url)?.host ?? '';
|
||||
@@ -253,7 +254,7 @@ class AppState extends ChangeNotifier {
|
||||
} catch (e) {
|
||||
if (client == cl) {
|
||||
followUpBehavior = before;
|
||||
_lastError = '保存失败:$e';
|
||||
_lastError = trArgs('保存失败:{0}', [e]);
|
||||
notifyListeners();
|
||||
}
|
||||
return false;
|
||||
@@ -300,7 +301,7 @@ class AppState extends ChangeNotifier {
|
||||
final payload = parsePairingLink(link);
|
||||
if (payload == null) {
|
||||
debugPrint('pair: invalid link (${link.length} chars)');
|
||||
_lastError = '配对链接无效或已过期';
|
||||
_lastError = tr('配对链接无效或已过期');
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
@@ -337,7 +338,7 @@ class AppState extends ChangeNotifier {
|
||||
? const Duration(seconds: 30)
|
||||
: const Duration(seconds: 15));
|
||||
if (redeemed.token.isEmpty) {
|
||||
throw ApiError(401, '服务器没有返回设备令牌');
|
||||
throw ApiError(401, tr('服务器没有返回设备令牌'));
|
||||
}
|
||||
final connection = _pairingConnection(candidate, payload, redeemed.response);
|
||||
await storage.saveToken(connection.id, redeemed.token);
|
||||
@@ -358,7 +359,7 @@ class AppState extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
busy = false;
|
||||
final message = friendlyConnectError(failure ?? '配对失败');
|
||||
final message = friendlyConnectError(failure ?? tr('配对失败'));
|
||||
debugPrint('pair: failed: $message');
|
||||
error = message;
|
||||
_lastError = message;
|
||||
@@ -389,7 +390,7 @@ class AppState extends ChangeNotifier {
|
||||
if (candidate.isRelay) {
|
||||
return Connection(
|
||||
id: existing?.id ?? Storage.newId(),
|
||||
label: label.isNotEmpty ? label : (existing?.label ?? 'Relay 服务器'),
|
||||
label: label.isNotEmpty ? label : (existing?.label ?? tr('Relay 服务器')),
|
||||
url: 'relay://${candidate.serverId}',
|
||||
relayUrl: candidate.relayUrl,
|
||||
serverId: candidate.serverId,
|
||||
@@ -418,7 +419,7 @@ class AppState extends ChangeNotifier {
|
||||
if (c.isRelay) {
|
||||
// A relay connection is created by pairing; a missing token means it
|
||||
// was never stored or was revoked.
|
||||
throw ApiError(401, '配对已失效,请重新配对');
|
||||
throw ApiError(401, tr('配对已失效,请重新配对'));
|
||||
}
|
||||
// No saved token: a passwordless server needs none.
|
||||
try {
|
||||
@@ -428,13 +429,13 @@ class AppState extends ChangeNotifier {
|
||||
}
|
||||
} on ApiError {
|
||||
if (password.isEmpty) {
|
||||
throw ApiError(401, '需要密码或已保存的凭据');
|
||||
throw ApiError(401, tr('需要密码或已保存的凭据'));
|
||||
}
|
||||
}
|
||||
if (token == null && password.isNotEmpty) {
|
||||
final res = await cl.login(password, await storage.installId());
|
||||
token = res['clientToken'] as String? ?? '';
|
||||
if (token.isEmpty) throw ApiError(401, '登录成功但没有返回令牌');
|
||||
if (token.isEmpty) throw ApiError(401, tr('登录成功但没有返回令牌'));
|
||||
await storage.saveToken(c.id, token);
|
||||
}
|
||||
}
|
||||
@@ -457,25 +458,25 @@ class AppState extends ChangeNotifier {
|
||||
if (e is ApiError) {
|
||||
if (e.status == 401 &&
|
||||
e.message.toLowerCase().contains('invalid credentials')) {
|
||||
return '密码错误,请重试';
|
||||
return tr('密码错误,请重试');
|
||||
}
|
||||
return e.message;
|
||||
}
|
||||
if (e is ArgumentError) return e.message?.toString() ?? e.toString();
|
||||
if (e is TimeoutException) return '连接超时:检查服务器与代理地址';
|
||||
if (e is TimeoutException) return tr('连接超时:检查服务器与代理地址');
|
||||
final s = e.toString();
|
||||
if (e is SocketException) {
|
||||
if (s.contains('Connection refused')) {
|
||||
return '连接被拒绝:服务器或代理未启动,或端口不对';
|
||||
return tr('连接被拒绝:服务器或代理未启动,或端口不对');
|
||||
}
|
||||
if (s.contains('Failed host lookup') || s.contains('nodename nor servname')) {
|
||||
return '无法解析地址:检查服务器或代理主机名';
|
||||
return tr('无法解析地址:检查服务器或代理主机名');
|
||||
}
|
||||
if (s.contains('Network is unreachable')) return '网络不可达';
|
||||
if (s.contains('Network is unreachable')) return tr('网络不可达');
|
||||
if (s.contains('Connection closed') || s.contains('reset by peer')) {
|
||||
return '连接被断开:检查代理是否可用';
|
||||
return tr('连接被断开:检查代理是否可用');
|
||||
}
|
||||
return '网络错误:$s';
|
||||
return trArgs('网络错误:{0}', [s]);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -702,10 +703,10 @@ class AppState extends ChangeNotifier {
|
||||
cl.commands(directory: directory),
|
||||
cl.skills(directory: directory),
|
||||
]);
|
||||
const local = [
|
||||
final local = [
|
||||
SlashItem(
|
||||
name: 'compact',
|
||||
description: '使用 AI 压缩会话历史以减少上下文大小',
|
||||
description: tr('使用 AI 压缩会话历史以减少上下文大小'),
|
||||
action: 'compact',
|
||||
),
|
||||
];
|
||||
@@ -740,7 +741,7 @@ class AppState extends ChangeNotifier {
|
||||
}
|
||||
|
||||
String projectLabelFor(String directory) {
|
||||
if (directory == chatTarget || isChatDirectory(directory)) return '聊天';
|
||||
if (directory == chatTarget || isChatDirectory(directory)) return tr('聊天');
|
||||
if (directory.isEmpty) return '';
|
||||
for (final project in projects) {
|
||||
if (samePath(project.canonical, directory)) return project.label;
|
||||
@@ -783,7 +784,7 @@ class AppState extends ChangeNotifier {
|
||||
await openChat(session);
|
||||
return true;
|
||||
} catch (e) {
|
||||
_lastError = '无法打开子代理会话:$e';
|
||||
_lastError = trArgs('无法打开子代理会话:{0}', [e]);
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
@@ -826,11 +827,11 @@ class AppState extends ChangeNotifier {
|
||||
/// project scope.
|
||||
Future<String> createChatDirectory() async {
|
||||
final cl = client;
|
||||
if (cl == null) throw StateError('未连接服务器');
|
||||
if (cl == null) throw StateError(tr('未连接服务器'));
|
||||
if (chatsRoot == null || chatsRoot!.isEmpty) await refreshFsHome();
|
||||
final root = chatsRoot;
|
||||
if (root == null || root.isEmpty) {
|
||||
throw StateError('服务器没有提供聊天目录');
|
||||
throw StateError(tr('服务器没有提供聊天目录'));
|
||||
}
|
||||
final now = DateTime.now();
|
||||
final date = '${now.year.toString().padLeft(4, '0')}-'
|
||||
@@ -1007,8 +1008,8 @@ class AppState extends ChangeNotifier {
|
||||
current.directory = target;
|
||||
} catch (e) {
|
||||
sendingDraft = false;
|
||||
current.error =
|
||||
'无法创建聊天目录:${e is ApiError ? e.message : e}';
|
||||
current.error = trArgs(
|
||||
'无法创建聊天目录:{0}', [e is ApiError ? e.message : e]);
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
@@ -1118,7 +1119,7 @@ class AppState extends ChangeNotifier {
|
||||
// Anything arriving means the stream is back (the server greets
|
||||
// every connection with `server.connected`), so the "reconnecting"
|
||||
// banner has done its job.
|
||||
if (error == '连接中断,正在重连…') error = null;
|
||||
if (error == tr('连接中断,正在重连…')) error = null;
|
||||
if (catchUp) {
|
||||
catchUp = false;
|
||||
_resyncActivity();
|
||||
@@ -1136,7 +1137,7 @@ class AppState extends ChangeNotifier {
|
||||
await done.future;
|
||||
if (client != cl || gen != _streamGen) return;
|
||||
afterDrop = true;
|
||||
error = '连接中断,正在重连…';
|
||||
error = tr('连接中断,正在重连…');
|
||||
notifyListeners();
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
}
|
||||
@@ -1788,7 +1789,7 @@ class ChatState extends ChangeNotifier {
|
||||
type: 'user',
|
||||
text: t,
|
||||
created: DateTime.now().millisecondsSinceEpoch,
|
||||
files: files?.map((f) => FileAttachment(f['name'] ?? '附件', '')).toList() ?? const [],
|
||||
files: files?.map((f) => FileAttachment(f['name'] ?? tr('附件'), '')).toList() ?? const [],
|
||||
));
|
||||
_sortMsgs();
|
||||
notifyListeners();
|
||||
@@ -1822,7 +1823,7 @@ class ChatState extends ChangeNotifier {
|
||||
type: 'user',
|
||||
text: t,
|
||||
created: DateTime.now().millisecondsSinceEpoch,
|
||||
files: files?.map((f) => FileAttachment(f['name'] ?? '附件', '')).toList() ?? const [],
|
||||
files: files?.map((f) => FileAttachment(f['name'] ?? tr('附件'), '')).toList() ?? const [],
|
||||
));
|
||||
_sortMsgs();
|
||||
notifyListeners();
|
||||
@@ -1857,7 +1858,7 @@ class ChatState extends ChangeNotifier {
|
||||
delivery: delivery,
|
||||
created: DateTime.now().millisecondsSinceEpoch,
|
||||
files: files
|
||||
?.map((f) => FileAttachment(f['name'] ?? '附件', ''))
|
||||
?.map((f) => FileAttachment(f['name'] ?? tr('附件'), ''))
|
||||
.toList() ??
|
||||
const [],
|
||||
);
|
||||
|
||||
+4
-2
@@ -7,6 +7,8 @@ import 'dart:convert';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'l10n.dart';
|
||||
|
||||
class Connection {
|
||||
final String id;
|
||||
final String label;
|
||||
@@ -168,7 +170,7 @@ class Storage {
|
||||
final entry = (await _terminalMap(connectionId))[directory];
|
||||
if (entry is String && entry.isNotEmpty) {
|
||||
return SavedTerminalTabs(
|
||||
[SavedTerminalTab(entry, '终端 1')], entry);
|
||||
[SavedTerminalTab(entry, tr('终端 1'))], entry);
|
||||
}
|
||||
if (entry is! Map) return null;
|
||||
final rawTabs = entry['tabs'];
|
||||
@@ -180,7 +182,7 @@ class Storage {
|
||||
final label = raw['label'];
|
||||
if (id is! String || id.isEmpty) continue;
|
||||
tabs.add(SavedTerminalTab(
|
||||
id, label is String && label.trim().isNotEmpty ? label : '终端'));
|
||||
id, label is String && label.trim().isNotEmpty ? label : tr('终端')));
|
||||
}
|
||||
if (tabs.isEmpty) return null;
|
||||
final active = entry['active'];
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:xterm/xterm.dart';
|
||||
|
||||
import 'api/terminal.dart';
|
||||
import 'l10n.dart';
|
||||
import 'state.dart';
|
||||
import 'storage.dart';
|
||||
|
||||
@@ -113,14 +114,15 @@ class TerminalWorkspace extends ChangeNotifier {
|
||||
static String freeLabel(Iterable<String> labels) {
|
||||
final used = <int>{};
|
||||
for (final label in labels) {
|
||||
final match = RegExp(r'^终端 (\d+)$').firstMatch(label.trim());
|
||||
final match = RegExp(r'^终端 (\d+)$').firstMatch(label.trim()) ??
|
||||
RegExp(r'^Terminal (\d+)$').firstMatch(label.trim());
|
||||
if (match != null) used.add(int.parse(match.group(1)!));
|
||||
}
|
||||
var n = 1;
|
||||
while (used.contains(n)) {
|
||||
n++;
|
||||
}
|
||||
return '终端 $n';
|
||||
return trArgs('终端 {0}', [n]);
|
||||
}
|
||||
|
||||
Future<SavedTerminalTabs?> _savedTabs() async {
|
||||
@@ -432,8 +434,8 @@ class TerminalSessionState extends ChangeNotifier {
|
||||
if (event.status == 'exited') {
|
||||
_set(TerminalLinkState.exited,
|
||||
detail: event.exitCode == null
|
||||
? '已退出'
|
||||
: '退出码 ${event.exitCode}');
|
||||
? tr('已退出')
|
||||
: trArgs('退出码 {0}', [event.exitCode]));
|
||||
}
|
||||
break;
|
||||
case 'restarted':
|
||||
@@ -447,8 +449,8 @@ class TerminalSessionState extends ChangeNotifier {
|
||||
case 'exit':
|
||||
_set(TerminalLinkState.exited,
|
||||
detail: event.exitCode == null
|
||||
? '已退出'
|
||||
: '退出码 ${event.exitCode}');
|
||||
? tr('已退出')
|
||||
: trArgs('退出码 {0}', [event.exitCode]));
|
||||
break;
|
||||
case 'error':
|
||||
if (event.fatal) {
|
||||
@@ -459,7 +461,7 @@ class TerminalSessionState extends ChangeNotifier {
|
||||
_recoverMissing();
|
||||
} else {
|
||||
_set(TerminalLinkState.error,
|
||||
detail: event.message ?? event.code ?? '终端连接失败');
|
||||
detail: event.message ?? event.code ?? tr('终端连接失败'));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
class ComposerAttachment {
|
||||
final String name;
|
||||
@@ -35,7 +36,7 @@ Future<List<ComposerAttachment>> pickComposerAttachments(
|
||||
if (bytes.length > 10 * 1024 * 1024) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('附件不能超过 10MB')));
|
||||
const SnackBar(content: AppText('附件不能超过 10MB')));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -83,7 +84,7 @@ class AttachmentTray extends StatelessWidget {
|
||||
: const Icon(Icons.insert_drive_file, size: 16),
|
||||
label: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 160),
|
||||
child: Text(items[i].name,
|
||||
child: AppText(items[i].name,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
onDeleted: () => onRemove(i),
|
||||
@@ -132,4 +133,4 @@ Future<String?> _keepImage(String src, String name) async {
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/models.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
enum DiffLineKind { context, add, del, hunk, meta }
|
||||
|
||||
@@ -246,8 +247,8 @@ class DiffView extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
file.path ?? '文件 ${fileIndex + 1}',
|
||||
child: AppText(
|
||||
file.path ?? trArgs('文件 {0}', [fileIndex + 1]),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
@@ -278,7 +279,7 @@ class DiffView extends StatelessWidget {
|
||||
rows.add(Container(
|
||||
color: background,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 1),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
line.text.isEmpty ? ' ' : line.text,
|
||||
style: mono.copyWith(color: foreground),
|
||||
),
|
||||
@@ -288,8 +289,8 @@ class DiffView extends StatelessWidget {
|
||||
if (total > maxLines) {
|
||||
rows.add(Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
|
||||
child: Text(
|
||||
'仅显示前 $maxLines 行,共 $total 行',
|
||||
child: AppText(
|
||||
trArgs('仅显示前 {0} 行,共 {1} 行', [maxLines, total]),
|
||||
style: TextStyle(fontSize: 11, color: theme.hintColor),
|
||||
),
|
||||
));
|
||||
@@ -332,10 +333,10 @@ class DiffStats extends StatelessWidget {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (added > 0) Text('+$added', style: style.copyWith(color: addFg)),
|
||||
if (added > 0) AppText('+$added', style: style.copyWith(color: addFg)),
|
||||
if (added > 0 && removed > 0) const SizedBox(width: 4),
|
||||
if (removed > 0)
|
||||
Text('−$removed', style: style.copyWith(color: delFg)),
|
||||
AppText('−$removed', style: style.copyWith(color: delFg)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../api/models.dart';
|
||||
import '../model_prefs.dart';
|
||||
import '../state.dart';
|
||||
import 'model_picker.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
/// `deepseek-flash · 高` — model and effort together, as dsh-Go shows them.
|
||||
class ModelPill extends StatelessWidget {
|
||||
@@ -89,7 +90,7 @@ class ModeChip extends StatelessWidget {
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 4, 20, 8),
|
||||
child: Text('模式',
|
||||
child: AppText('模式',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
||||
),
|
||||
for (final id in ids)
|
||||
@@ -98,13 +99,13 @@ class ModeChip extends StatelessWidget {
|
||||
id == 'plan' ? Icons.map_outlined : Icons.construction_outlined,
|
||||
color: id == current ? scheme.primary : null,
|
||||
),
|
||||
title: Text(
|
||||
title: AppText(
|
||||
names[id]?.isNotEmpty == true ? names[id]! : _label(id),
|
||||
style: TextStyle(
|
||||
fontWeight: id == current ? FontWeight.w700 : FontWeight.w400,
|
||||
),
|
||||
),
|
||||
subtitle: Text(id == 'plan' ? '先规划,不改动文件' : '直接构建',
|
||||
subtitle: AppText(id == 'plan' ? '先规划,不改动文件' : '直接构建',
|
||||
style: const TextStyle(fontSize: 12)),
|
||||
trailing: id == current
|
||||
? Icon(Icons.check, size: 20, color: scheme.primary)
|
||||
@@ -150,7 +151,7 @@ class _Pill extends StatelessWidget {
|
||||
Icon(icon, size: 14, color: theme.hintColor),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
||||
import '../api/models.dart';
|
||||
import '../model_prefs.dart';
|
||||
import '../state.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
Future<void> showModelPickerSheet(
|
||||
BuildContext context, {
|
||||
@@ -69,16 +70,16 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(12, 12, 12, 4),
|
||||
child: Text('选择模型',
|
||||
child: AppText('选择模型',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: TextField(
|
||||
onChanged: (v) => setState(() => _filter = v),
|
||||
decoration: const InputDecoration(
|
||||
hintText: '搜索',
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
hintText: tr('搜索'),
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true),
|
||||
),
|
||||
),
|
||||
@@ -92,7 +93,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
Widget _models() {
|
||||
final all = widget.app.modelList;
|
||||
if (all.isEmpty) {
|
||||
return const Center(child: Text('正在载入模型…'));
|
||||
return const Center(child: AppText('正在载入模型…'));
|
||||
}
|
||||
final filter = _filter.trim().toLowerCase();
|
||||
final matching = filter.isEmpty
|
||||
@@ -103,7 +104,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
m.id.toLowerCase().contains(filter))
|
||||
m,
|
||||
];
|
||||
if (matching.isEmpty) return const Center(child: Text('没有结果'));
|
||||
if (matching.isEmpty) return const Center(child: AppText('没有结果'));
|
||||
|
||||
final byKey = {
|
||||
for (final m in all) ModelPrefs.keyFor(m.providerId, m.id): m,
|
||||
@@ -125,7 +126,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
final children = <Widget>[];
|
||||
if (filter.isEmpty) {
|
||||
if (favorites.isNotEmpty) {
|
||||
children.add(_sectionHeader('收藏', 'favorites', count: favorites.length));
|
||||
children.add(_sectionHeader(tr('收藏'), 'favorites', count: favorites.length));
|
||||
if (!_collapsed.contains('favorites')) {
|
||||
for (final model in favorites) {
|
||||
children.add(_modelRow(model));
|
||||
@@ -133,7 +134,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
}
|
||||
}
|
||||
if (recents.isNotEmpty) {
|
||||
children.add(_sectionHeader('最近', 'recents', count: recents.length));
|
||||
children.add(_sectionHeader(tr('最近'), 'recents', count: recents.length));
|
||||
if (!_collapsed.contains('recents')) {
|
||||
for (final model in recents) {
|
||||
children.add(_modelRow(model));
|
||||
@@ -142,7 +143,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
}
|
||||
}
|
||||
for (final entry in providers.entries) {
|
||||
final label = entry.key.isEmpty ? '其它' : entry.key;
|
||||
final label = entry.key.isEmpty ? tr('其它') : entry.key;
|
||||
children.add(_sectionHeader(label, 'provider:${entry.key}',
|
||||
count: entry.value.length));
|
||||
if (!_collapsed.contains('provider:${entry.key}')) {
|
||||
@@ -172,8 +173,8 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
size: 16, color: Theme.of(context).hintColor),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
count == null ? label : '$label($count)',
|
||||
child: AppText(
|
||||
count == null ? label : trArgs('{0}({1})', [label, count]),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
@@ -199,7 +200,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
title: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(model.name,
|
||||
child: AppText(model.name,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
if (model.reasoning)
|
||||
@@ -211,7 +212,8 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
],
|
||||
),
|
||||
subtitle: model.context > 0
|
||||
? Text('${formatTokenCount(model.context)} 上下文',
|
||||
? AppText(
|
||||
trArgs('{0} 上下文', [formatTokenCount(model.context)]),
|
||||
style: TextStyle(fontSize: 11, color: theme.hintColor))
|
||||
: null,
|
||||
trailing: Row(
|
||||
@@ -230,7 +232,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
size: 18,
|
||||
color: favorite ? theme.colorScheme.primary : theme.hintColor,
|
||||
),
|
||||
tooltip: favorite ? '取消收藏' : '收藏',
|
||||
tooltip: favorite ? tr('取消收藏') : tr('收藏'),
|
||||
onPressed: () async {
|
||||
await _prefs.toggleFavorite(key);
|
||||
if (mounted) setState(() {});
|
||||
@@ -287,12 +289,12 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text('思考强度',
|
||||
const AppText('思考强度',
|
||||
style: TextStyle(
|
||||
fontSize: 13, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(model.name,
|
||||
child: AppText(model.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style:
|
||||
@@ -300,7 +302,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('完成'),
|
||||
child: const AppText('完成'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -310,7 +312,7 @@ class _PickerSheetState extends State<_PickerSheet> {
|
||||
children: [
|
||||
for (final option in options)
|
||||
ChoiceChip(
|
||||
label: Text(effortLabel(option),
|
||||
label: AppText(effortLabel(option),
|
||||
style: const TextStyle(fontSize: 12.5)),
|
||||
selected: (_effortVariant ?? '') == (option ?? ''),
|
||||
onSelected: (_) => _pickEffort(model, option),
|
||||
|
||||
@@ -7,6 +7,7 @@ import '../api/models.dart';
|
||||
import '../api/scheduled_tasks.dart';
|
||||
import '../state.dart';
|
||||
import 'model_picker.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
class ScheduledTaskEditor extends StatefulWidget {
|
||||
final AppState app;
|
||||
@@ -120,7 +121,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
widget.initial == null ? '新建计划任务' : '编辑计划任务',
|
||||
style: const TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.w600),
|
||||
@@ -128,7 +129,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _saving ? null : _save,
|
||||
child: Text(_saving ? '保存中…' : '保存'),
|
||||
child: AppText(_saving ? '保存中…' : '保存'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -137,16 +138,16 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 32),
|
||||
children: [
|
||||
Text('运行位置:${widget.scopeLabel}',
|
||||
AppText(trArgs('运行位置:{0}', [widget.scopeLabel]),
|
||||
style: TextStyle(fontSize: 12.5, color: theme.hintColor)),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _name,
|
||||
maxLength: 80,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '任务名称',
|
||||
hintText: '每日同步',
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
labelText: tr('任务名称'),
|
||||
hintText: tr('每日同步'),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -154,10 +155,10 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
controller: _prompt,
|
||||
minLines: 4,
|
||||
maxLines: 10,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '提示词',
|
||||
hintText: '总结未完成任务并给出下一步建议',
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
labelText: tr('提示词'),
|
||||
hintText: tr('总结未完成任务并给出下一步建议'),
|
||||
border: const OutlineInputBorder(),
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
),
|
||||
@@ -169,7 +170,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
children: [
|
||||
for (final entry in scheduledTaskKindLabels.entries)
|
||||
ChoiceChip(
|
||||
label: Text(entry.value),
|
||||
label: AppText(entry.value),
|
||||
selected: _kind == entry.key,
|
||||
onSelected: (_) => setState(() => _kind = entry.key),
|
||||
),
|
||||
@@ -180,23 +181,23 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('使用默认模型与智能体'),
|
||||
subtitle: const Text('关闭后可固定这次运行使用的模型和智能体。'),
|
||||
title: const AppText('使用默认模型与智能体'),
|
||||
subtitle: const AppText('关闭后可固定这次运行使用的模型和智能体。'),
|
||||
value: _useDefaults,
|
||||
onChanged: (v) => setState(() => _useDefaults = v),
|
||||
),
|
||||
if (!_useDefaults) ..._executionFields(theme),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('已启用'),
|
||||
subtitle: const Text('暂停的任务不会按计划运行,但可以手动运行。'),
|
||||
title: const AppText('已启用'),
|
||||
subtitle: const AppText('暂停的任务不会按计划运行,但可以手动运行。'),
|
||||
value: _enabled,
|
||||
onChanged: (v) => setState(() => _enabled = v),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
FilledButton(
|
||||
onPressed: _saving ? null : _save,
|
||||
child: Text(_saving ? '保存中…' : '保存'),
|
||||
child: AppText(_saving ? '保存中…' : '保存'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -219,7 +220,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
children: [
|
||||
for (var day = 0; day < scheduledWeekdays.length; day++)
|
||||
FilterChip(
|
||||
label: Text(scheduledWeekdays[day]),
|
||||
label: AppText(scheduledWeekdays[day]),
|
||||
selected: _weekdays.contains(day),
|
||||
onSelected: (selected) => setState(() {
|
||||
if (selected) {
|
||||
@@ -238,14 +239,14 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
return [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('日期'),
|
||||
trailing: Text(_dateText(_date)),
|
||||
title: const AppText('日期'),
|
||||
trailing: AppText(_dateText(_date)),
|
||||
onTap: _pickDate,
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('时间'),
|
||||
trailing: Text(_time),
|
||||
title: const AppText('时间'),
|
||||
trailing: AppText(_time),
|
||||
onTap: () async {
|
||||
final picked = await _pickTime(_time);
|
||||
if (picked != null) setState(() => _time = picked);
|
||||
@@ -256,10 +257,10 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
return [
|
||||
TextField(
|
||||
controller: _cron,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Cron 表达式',
|
||||
decoration: InputDecoration(
|
||||
labelText: tr('Cron 表达式'),
|
||||
hintText: '*/5 * * * *',
|
||||
border: OutlineInputBorder(),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -275,7 +276,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
('每月 1 日', '0 9 1 * *'),
|
||||
])
|
||||
ActionChip(
|
||||
label: Text(example.$1),
|
||||
label: AppText(example.$1),
|
||||
onPressed: () =>
|
||||
setState(() => _cron.text = example.$2),
|
||||
),
|
||||
@@ -302,12 +303,12 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
final picked = await _pickTime(_times[i]);
|
||||
if (picked != null) setState(() => _times[i] = picked);
|
||||
},
|
||||
child: Text(_times[i]),
|
||||
child: AppText(_times[i]),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove_circle_outline, size: 20),
|
||||
tooltip: '移除时间',
|
||||
tooltip: tr('移除时间'),
|
||||
onPressed: _times.length <= 1
|
||||
? null
|
||||
: () => setState(() => _times.removeAt(i)),
|
||||
@@ -321,9 +322,9 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
if (picked != null) setState(() => _times.add(picked));
|
||||
},
|
||||
icon: const Icon(Icons.add, size: 18),
|
||||
label: const Text('添加时间'),
|
||||
label: const AppText('添加时间'),
|
||||
),
|
||||
Text('时间按服务器所在时区。', style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
AppText('时间按服务器所在时区。', style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -337,15 +338,15 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.memory, size: 20),
|
||||
title: const Text('模型'),
|
||||
trailing: Text(model, overflow: TextOverflow.ellipsis),
|
||||
title: const AppText('模型'),
|
||||
trailing: AppText(model, overflow: TextOverflow.ellipsis),
|
||||
onTap: _pickModel,
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.smart_toy_outlined, size: 20),
|
||||
title: const Text('智能体'),
|
||||
trailing: Text(agent, overflow: TextOverflow.ellipsis),
|
||||
title: const AppText('智能体'),
|
||||
trailing: AppText(agent, overflow: TextOverflow.ellipsis),
|
||||
onTap: _pickAgent,
|
||||
),
|
||||
];
|
||||
@@ -403,13 +404,13 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
ListTile(
|
||||
title: const Text('默认智能体'),
|
||||
title: const AppText('默认智能体'),
|
||||
trailing: _agent.isEmpty ? const Icon(Icons.check, size: 20) : null,
|
||||
onTap: () => Navigator.pop(sheet, ''),
|
||||
),
|
||||
for (final agent in widget.app.agentList)
|
||||
ListTile(
|
||||
title: Text(agent.name.isEmpty ? agent.id : agent.name),
|
||||
title: AppText(agent.name.isEmpty ? agent.id : agent.name),
|
||||
trailing: _agent == agent.id
|
||||
? const Icon(Icons.check, size: 20)
|
||||
: null,
|
||||
@@ -446,7 +447,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
problem = '请选择模型,或改回使用默认模型';
|
||||
}
|
||||
if (problem != null) {
|
||||
messenger.showSnackBar(SnackBar(content: Text(problem)));
|
||||
messenger.showSnackBar(SnackBar(content: AppText(problem)));
|
||||
return;
|
||||
}
|
||||
setState(() => _saving = true);
|
||||
@@ -487,8 +488,8 @@ class _FieldLabel extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Text(text,
|
||||
child: AppText(text,
|
||||
style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-24
@@ -8,6 +8,7 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import '../api/client.dart';
|
||||
import '../api/shells.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
/// One line of "正在执行 N 条命令", folding when there are many.
|
||||
class ShellTaskBar extends StatefulWidget {
|
||||
@@ -86,8 +87,8 @@ class _ShellTaskBarState extends State<ShellTaskBar> {
|
||||
Icon(Icons.terminal, size: 15, color: theme.hintColor),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'正在执行 $count 条命令',
|
||||
child: AppText(
|
||||
trArgs('正在执行 {0} 条命令', [count]),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
@@ -130,7 +131,7 @@ class _ShellTaskRow extends StatelessWidget {
|
||||
Icon(Icons.terminal, size: 15, color: theme.hintColor),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
task.command.replaceAll(RegExp(r'\s+'), ' ').trim(),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -140,7 +141,7 @@ class _ShellTaskRow extends StatelessWidget {
|
||||
),
|
||||
if (subagent) ...[
|
||||
const SizedBox(width: 6),
|
||||
Text('子代理',
|
||||
AppText('子代理',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
@@ -194,7 +195,7 @@ class _ShellElapsedState extends State<ShellElapsed> {
|
||||
if (widget.startedAt <= 0 || !widget.running) return const SizedBox.shrink();
|
||||
final label =
|
||||
formatElapsed(DateTime.now().millisecondsSinceEpoch - widget.startedAt);
|
||||
return Text(
|
||||
return AppText(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
@@ -337,7 +338,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
|
||||
Icon(Icons.terminal, size: 18, color: theme.hintColor),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
widget.task.command,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -361,7 +362,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
|
||||
Icon(Icons.check_circle_outline,
|
||||
size: 15, color: theme.hintColor),
|
||||
const SizedBox(width: 6),
|
||||
Text('已结束',
|
||||
AppText('已结束',
|
||||
style:
|
||||
TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
],
|
||||
@@ -370,7 +371,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
|
||||
TextButton.icon(
|
||||
onPressed: _stopping ? null : _stop,
|
||||
icon: const Icon(Icons.stop_rounded, size: 17),
|
||||
label: Text(_stopping ? '停止中…' : '停止'),
|
||||
label: AppText(_stopping ? '停止中…' : '停止'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: theme.colorScheme.error,
|
||||
minimumSize: const Size(0, 32),
|
||||
@@ -380,7 +381,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
|
||||
TextButton.icon(
|
||||
onPressed: _text.isEmpty ? null : _copy,
|
||||
icon: const Icon(Icons.copy, size: 15),
|
||||
label: const Text('复制'),
|
||||
label: const AppText('复制'),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 32),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
@@ -408,7 +409,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
Text(
|
||||
AppText(
|
||||
_feed.error ??
|
||||
(!_feed.loaded
|
||||
? '读取输出…'
|
||||
@@ -446,7 +447,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
|
||||
_onFeed();
|
||||
},
|
||||
icon: const Icon(Icons.arrow_downward, size: 15),
|
||||
label: const Text('回到最新'),
|
||||
label: const AppText('回到最新'),
|
||||
style: FilledButton.styleFrom(
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
@@ -464,7 +465,7 @@ class _ShellOutputSheetState extends State<ShellOutputSheet> {
|
||||
await Clipboard.setData(ClipboardData(text: _text));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('已复制输出')));
|
||||
.showSnackBar(const SnackBar(content: AppText('已复制输出')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -541,15 +542,15 @@ class _ShellOutputInlineState extends State<ShellOutputInline> {
|
||||
children: [
|
||||
Icon(Icons.terminal, size: 15, color: theme.hintColor),
|
||||
const SizedBox(width: 8),
|
||||
Text('后台输出',
|
||||
AppText('后台输出',
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
const SizedBox(width: 8),
|
||||
if (!ended)
|
||||
Text('运行中',
|
||||
AppText('运行中',
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: theme.colorScheme.primary)),
|
||||
if (ended && text.isEmpty)
|
||||
Text('已结束',
|
||||
AppText('已结束',
|
||||
style:
|
||||
TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
const Spacer(),
|
||||
@@ -562,7 +563,7 @@ class _ShellOutputInlineState extends State<ShellOutputInline> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
textStyle: const TextStyle(fontSize: 12.5),
|
||||
),
|
||||
child: const Text('停止'),
|
||||
child: const AppText('停止'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: widget.onOpen,
|
||||
@@ -571,14 +572,14 @@ class _ShellOutputInlineState extends State<ShellOutputInline> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
textStyle: const TextStyle(fontSize: 12.5),
|
||||
),
|
||||
child: const Text('查看全部'),
|
||||
child: const AppText('查看全部'),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (tail.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Text(
|
||||
child: AppText(
|
||||
_feed.error ?? (ended ? '没有输出' : '等待输出…'),
|
||||
style: TextStyle(fontSize: 12, color: theme.hintColor)),
|
||||
)
|
||||
@@ -614,8 +615,8 @@ Future<bool?> confirmStopShell(BuildContext context, String command) {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialog) => AlertDialog(
|
||||
title: const Text('停止这个任务?'),
|
||||
content: Text(
|
||||
title: const AppText('停止这个任务?'),
|
||||
content: AppText(
|
||||
command,
|
||||
maxLines: 4,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -624,14 +625,14 @@ Future<bool?> confirmStopShell(BuildContext context, String command) {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialog, false),
|
||||
child: const Text('取消')),
|
||||
child: const AppText('取消')),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Theme.of(dialog).colorScheme.error,
|
||||
foregroundColor: Theme.of(dialog).colorScheme.onError,
|
||||
),
|
||||
onPressed: () => Navigator.pop(dialog, true),
|
||||
child: const Text('停止'),
|
||||
child: const AppText('停止'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -727,11 +728,11 @@ class ShellOutputFeed {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
} else {
|
||||
error = '读取输出失败:${e.message}';
|
||||
error = trArgs('读取输出失败:{0}', [e.message]);
|
||||
}
|
||||
_onUpdate?.call();
|
||||
} catch (e) {
|
||||
error = '读取输出失败:$e';
|
||||
error = trArgs('读取输出失败:{0}', ['$e']);
|
||||
_onUpdate?.call();
|
||||
} finally {
|
||||
_busy = false;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../state.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
const _slashLabels = {
|
||||
'compact': '压缩',
|
||||
@@ -83,11 +84,11 @@ class SlashPalette extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title,
|
||||
AppText(title,
|
||||
style:
|
||||
TextStyle(fontSize: 14, color: scheme.onSurface)),
|
||||
if (subtitle.isNotEmpty)
|
||||
Text(subtitle,
|
||||
AppText(subtitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
@@ -159,7 +160,7 @@ class SlashPalette extends StatelessWidget {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text('/${item.name}',
|
||||
AppText('/${item.name}',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -167,7 +168,7 @@ class SlashPalette extends StatelessWidget {
|
||||
if (label != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Text(label,
|
||||
child: AppText(label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant)),
|
||||
@@ -175,7 +176,7 @@ class SlashPalette extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
if (item.description.isNotEmpty)
|
||||
Text(item.description,
|
||||
AppText(item.description,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
|
||||
Reference in new issue
Block a user