feat: English and Chinese, and selectable chat text

- settings → general → language picks system, Chinese or English; the
  choice is stored on the device and read before the first frame
- our Chinese strings are translated through tr()/trArgs() and AppText,
  with the English in lib/l10n/en_*.dart; a missing entry falls back to
  Chinese and a test checks that every literal in lib has one
- AppText rebuilds on a language change (it depends on the resolved
  locale), so const text and whole pages switch at once; the built-in
  date/time pickers and selection menu follow the same language
- server and user data (titles, messages, prompts, paths) is never
  translated
- the chat list sits in a SelectionArea: long-press selects message text
  and shows the copy/select-all menu
- bump to 0.5.2
This commit is contained in:
blumia committed 2026-11-26 09:04:25 +08:00
1 parent da4bfb6826
commit 7b5bccf28f
42 files changed
+1943 -735

No files matched your search

+18 -15
View File
@@ -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;
}
}