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
@@ -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('配对并连接'),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user