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 '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,
|
||||
|
||||
Reference in new issue
Block a user