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
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user