feat(i18n): 完成全量 UI 文本国际化,替换所有硬编码中文为 AppLocalizations 调用
- core/localization: 新增约 60 个翻译键(含参数化方法),中英双语覆盖 - shared/widgets: CommonDialog 默认参数国际化 - features/home: 完成页操作步骤指引、状态栏串口连接状态、程序列表状态标签 - features/programs: 表头状态列、表单验证提示、导入/模板操作反馈、删除确认(参数化) - features/program_detail: 步骤列表/表单标题、删除确认、速度档位显示(参数化) - features/device: run_state_provider 错误消息改为错误码 - features/settings: 升级页、密码面板、语言面板、U盘导入面板、串口配置面板全部替换 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/localization/app_localizations.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../shared/services/toast_service.dart';
|
||||
import '../services/usb_detection_service.dart';
|
||||
@@ -21,18 +22,20 @@ class _UsbImportPanelState extends ConsumerState<UsbImportPanel> {
|
||||
Future<void> _detect() async {
|
||||
if (_detecting) return;
|
||||
setState(() => _detecting = true);
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final connected = await UsbDetectionService.instance.detectUsb();
|
||||
if (!mounted) return;
|
||||
setState(() => _detecting = false);
|
||||
if (connected) {
|
||||
ToastService.showInfo(context, '正在检测U盘...');
|
||||
ToastService.showInfo(context, l10n?.detectingUsb ?? '正在检测U盘...');
|
||||
} else {
|
||||
ToastService.showWarning(context, '未检测到U盘');
|
||||
ToastService.showWarning(context, l10n?.usbNotDetected ?? '未检测到U盘');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final state = ref.watch(_usbStateProvider);
|
||||
final connected = state.maybeWhen(
|
||||
data: (s) => s.isConnected,
|
||||
@@ -67,7 +70,7 @@ class _UsbImportPanelState extends ConsumerState<UsbImportPanel> {
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
connected ? 'U盘已连接' : '未检测到U盘',
|
||||
connected ? (l10n?.usbConnected ?? 'U盘已连接') : (l10n?.usbNotDetected ?? '未检测到U盘'),
|
||||
style: TextStyle(
|
||||
color: AppTheme.textPrimary,
|
||||
fontSize: 16,
|
||||
@@ -80,8 +83,8 @@ class _UsbImportPanelState extends ConsumerState<UsbImportPanel> {
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
connected
|
||||
? '挂载路径: ${path ?? "未知"}'
|
||||
: '请插入U盘后点击"重新检测"',
|
||||
? '${l10n?.mountPath ?? '挂载路径'}: ${path ?? "?"}'
|
||||
: (l10n?.insertUsb ?? '请插入U盘后重试'),
|
||||
style: TextStyle(
|
||||
color: AppTheme.textSecondary, fontSize: 13),
|
||||
),
|
||||
@@ -98,13 +101,13 @@ class _UsbImportPanelState extends ConsumerState<UsbImportPanel> {
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.refresh, size: 18),
|
||||
label: const Text('重新检测'),
|
||||
label: Text(l10n?.reDetect ?? '重新检测'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ElevatedButton.icon(
|
||||
onPressed: connected ? () => _import(path) : null,
|
||||
icon: const Icon(Icons.download, size: 18),
|
||||
label: const Text('导入程序'),
|
||||
label: Text(l10n?.importProgram ?? '导入程序'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -123,7 +126,7 @@ class _UsbImportPanelState extends ConsumerState<UsbImportPanel> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'使用说明',
|
||||
l10n?.usageInstructions ?? '使用说明',
|
||||
style: TextStyle(
|
||||
color: AppTheme.textPrimary,
|
||||
fontSize: 14,
|
||||
@@ -131,9 +134,9 @@ class _UsbImportPanelState extends ConsumerState<UsbImportPanel> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_bullet('将程序文件 (.json) 放入 U盘根目录的 programs 文件夹'),
|
||||
_bullet('插入 U盘后点击"重新检测"'),
|
||||
_bullet('检测成功后点击"导入程序"加载程序列表'),
|
||||
_bullet(l10n?.usbUsageStep1 ?? '将程序文件 (.json) 放入 U盘根目录的 programs 文件夹'),
|
||||
_bullet(l10n?.usbUsageStep2 ?? '插入 U盘后点击"重新检测"'),
|
||||
_bullet(l10n?.usbUsageStep3 ?? '检测成功后点击"导入程序"加载程序列表'),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -142,11 +145,12 @@ class _UsbImportPanelState extends ConsumerState<UsbImportPanel> {
|
||||
}
|
||||
|
||||
void _import(String? path) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
if (path == null) {
|
||||
ToastService.showWarning(context, 'U盘路径无效');
|
||||
ToastService.showWarning(context, l10n?.usbPathInvalid ?? 'U盘路径无效');
|
||||
return;
|
||||
}
|
||||
ToastService.showInfo(context, '正在导入程序...');
|
||||
ToastService.showInfo(context, l10n?.importingPrograms ?? '正在导入程序...');
|
||||
// TODO: 接入 program_import_service 实现真正的导入流程
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user