feat: 全量英文界面(i18n 翻译表接入全部页面与服务层文案)

This commit is contained in:
ZV Team committed 2026-10-24 09:39:51 +08:00
1 parent 2eb3f42731
commit 71e76b1c2b
26 files changed
+775 -325

No files matched your search

@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import '../../core/services/dependency_index_service.dart';
import '../../providers/download_provider.dart';
import '../../providers/server_provider.dart';
import '../../core/l10n/strings.dart';
/// 依赖仓库页:服务器本地仓库增量同步 + 依赖树查询 + 缺失依赖一键补齐 + 重复检测。
class DependencyTreePage extends StatefulWidget {
@@ -48,7 +49,7 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
if (!mounted) return;
setState(() {
_syncing = false;
_syncInfo = '同步失败:$e';
_syncInfo = S.f('同步失败:{0}', [e]);
});
}
}
@@ -66,24 +67,24 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
Text('${tree.mod.name ?? tree.mod.fileName} ${tree.mod.version ?? ''}',
style: Theme.of(context).textTheme.titleMedium),
const Divider(),
const Text('该模组依赖:'),
T('该模组依赖:'),
...tree.dependsOn.map((m) => ListTile(
dense: true,
leading: const Icon(Icons.link, size: 18),
title: Text('${m.name ?? m.fileName} ${m.version ?? ''}'),
)),
if (tree.dependsOn.isEmpty) const Text('无', style: TextStyle(color: Colors.grey)),
if (tree.dependsOn.isEmpty) T('无', style: TextStyle(color: Colors.grey)),
const SizedBox(height: 8),
const Text('被以下模组依赖:'),
T('被以下模组依赖:'),
...tree.dependents.map((m) => ListTile(
dense: true,
leading: const Icon(Icons.link, size: 18),
title: Text('${m.name ?? m.fileName} ${m.version ?? ''}'),
)),
if (tree.dependents.isEmpty) const Text('无', style: TextStyle(color: Colors.grey)),
if (tree.dependents.isEmpty) T('无', style: TextStyle(color: Colors.grey)),
if (tree.missing.isNotEmpty) ...[
const SizedBox(height: 8),
const Text('缺失依赖(可一键补齐):',
T('缺失依赖(可一键补齐):',
style: TextStyle(color: Colors.red, fontWeight: FontWeight.w600)),
...tree.missing.map((d) => ListTile(
dense: true,
@@ -91,7 +92,7 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
title: Text(d),
trailing: TextButton(
onPressed: () => _fetchMissing(d),
child: const Text('从 Modrinth 补齐'),
child: T('从 Modrinth 补齐'),
),
)),
],
@@ -105,21 +106,21 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
final dp = context.read<DownloadProvider>();
try {
final results = await dp.search(name, projectType: 'mod', limit: 1);
if (results.isEmpty) throw '未找到 $name';
if (results.isEmpty) throw S.f('未找到 {0}', [name]);
final project = results.first;
final versions = await dp.versions(project.projectId);
if (versions.isEmpty) throw '该项目没有可用版本';
if (versions.isEmpty) throw S.t('该项目没有可用版本');
final v = versions.first;
if (v.files.isEmpty) throw '没有可用文件';
if (v.files.isEmpty) throw S.t('没有可用文件');
final primary = v.files.firstWhere((f) => f['primary'] == true, orElse: () => v.files.first);
await dp.download(url: primary['url'], fileName: primary['filename'], projectType: 'mod');
if (mounted) {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('已下载 $name(${v.versionNumber})')));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(S.f('已下载 {0}({1})', [name, v.versionNumber]))));
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('补齐失败:$e')));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(S.f('补齐失败:{0}', [e]))));
}
}
}
@@ -134,18 +135,18 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
shrinkWrap: true,
padding: const EdgeInsets.all(16),
children: [
Text('版本冲突 / 重复 jar', style: Theme.of(context).textTheme.titleMedium),
Text(S.t('版本冲突 / 重复 jar'), style: Theme.of(context).textTheme.titleMedium),
const Divider(),
if (dups.isEmpty) const Text('未发现重复'),
if (dups.isEmpty) T('未发现重复'),
...dups.map((g) => ExpansionTile(
title: Text(g.modId,
style: const TextStyle(color: Colors.orange, fontWeight: FontWeight.w600)),
subtitle: Text('${g.items.length} 个版本共存'),
subtitle: Text(S.f('{0} 个版本共存', [g.items.length])),
children: g.items
.map((m) => ListTile(
dense: true,
title: Text(m.fileName),
subtitle: Text('版本 ${m.version ?? '未知'} · ${m.remotePath}'),
subtitle: Text('${m.version ?? S.t('未知')} · ${m.remotePath}'),
))
.toList(),
)),
@@ -159,11 +160,11 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('依赖仓库'),
title: T('依赖仓库'),
actions: [
IconButton(
icon: const Icon(Icons.rule),
tooltip: '重复检测',
tooltip: S.t('重复检测'),
onPressed: _checkDuplicates,
),
],
@@ -181,7 +182,7 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
icon: _syncing
? const SizedBox(width: 16, height: 16, child: CircularProgressIndicator(strokeWidth: 2))
: const Icon(Icons.sync),
label: const Text('同步'),
label: T('同步'),
onPressed: _syncing ? null : _sync,
),
],
@@ -195,11 +196,11 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('索引为空,先点击「同步」'),
T('索引为空,先点击「同步」'),
if (!widget.server.hasSsh)
const Padding(
padding: EdgeInsets.all(8),
child: Text('(该服务器未配置 SSH,无法同步)',
child: T('(该服务器未配置 SSH,无法同步)',
style: TextStyle(color: Colors.red)),
),
],
@@ -213,7 +214,7 @@ class _DependencyTreePageState extends State<DependencyTreePage> {
leading: const Icon(Icons.inventory_2_outlined),
title: Text('${m.name ?? m.fileName} ${m.version ?? ''}'),
subtitle: Text(
'${m.fileName} · 依赖 ${m.depends.length} · 软依赖 ${m.softDepends.length}',
S.f('{0} · 依赖 {1} · 软依赖 {2}', [m.fileName, m.depends.length, m.softDepends.length]),
),
trailing: const Icon(Icons.account_tree_outlined),
onTap: () => _showTree(m),
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import '../mod_manager/mod_provider.dart';
import '../../core/l10n/strings.dart';
/// 模组详情页:展示 jar 元数据(名称 / 版本 / 作者 / 依赖 / 描述)。
class ModDetailPage extends StatelessWidget {
@@ -18,9 +19,9 @@ class ModDetailPage extends StatelessWidget {
children: [
ListTile(
leading: const Icon(Icons.extension),
title: Text(meta.name ?? '未知名称',
title: Text(meta.name ?? S.t('未知名称'),
style: Theme.of(context).textTheme.titleLarge),
subtitle: Text('版本 ${meta.version ?? '未知'}'),
subtitle: Text(S.f('版本 {0}', [meta.version ?? '未知'])),
),
const Divider(),
_kv('文件名', file.fileName),
@@ -30,10 +31,10 @@ class ModDetailPage extends StatelessWidget {
_kv('元数据来源', meta.source),
if (meta.description != null) _kv('描述', meta.description!),
const Divider(),
Text('硬依赖', style: Theme.of(context).textTheme.titleMedium),
T('硬依赖', style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 4),
if (meta.depends.isEmpty)
const Text('无')
T('无')
else
Wrap(
spacing: 6,
@@ -42,10 +43,10 @@ class ModDetailPage extends StatelessWidget {
.toList(),
),
const SizedBox(height: 12),
Text('软依赖', style: Theme.of(context).textTheme.titleMedium),
T('软依赖', style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 4),
if (meta.softDepends.isEmpty)
const Text('无')
T('无')
else
Wrap(spacing: 6, children: meta.softDepends.map((d) => Chip(label: Text(d))).toList()),
],
+23 -22
View File
@@ -7,6 +7,7 @@ import '../dashboard/server_picker_bar.dart';
import 'mod_provider.dart';
import 'mod_detail_page.dart';
import 'dependency_tree_page.dart';
import '../../core/l10n/strings.dart';
/// 模组/插件管理页:列出服务器 mods / plugins 目录中的 jar 文件,
/// 支持上传 / 删除 / 重命名 / 查看详情(M1)。
@@ -53,7 +54,7 @@ class _ModListPageState extends State<ModListPage>
super.build(context);
final server = context.watch<SelectedServerHolder>().server;
if (server == null) {
return const Center(child: Text('请先在「服务器」页选择一台服务器'));
return const Center(child: T('请先在「服务器」页选择一台服务器'));
}
if (!server.hasSsh) {
return _NoSshHint(serverName: server.name);
@@ -67,16 +68,16 @@ class _ModListPageState extends State<ModListPage>
return Scaffold(
backgroundColor: hasWallpaper ? Colors.transparent : null,
appBar: AppBar(
title: const Text('模组管理'),
title: T('模组管理'),
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: mod.loading ? null : mod.refresh,
tooltip: '刷新',
tooltip: S.t('刷新'),
),
IconButton(
icon: const Icon(Icons.account_tree_outlined),
tooltip: '依赖仓库',
tooltip: S.t('依赖仓库'),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
@@ -107,9 +108,9 @@ class _ModListPageState extends State<ModListPage>
icon: const Icon(Icons.sort),
onSelected: (m) => mod.setSortMode(m),
itemBuilder: (_) => const [
PopupMenuItem(value: ModSortMode.name, child: Text('按名称')),
PopupMenuItem(value: ModSortMode.size, child: Text('按大小')),
PopupMenuItem(value: ModSortMode.mtime, child: Text('按修改时间')),
PopupMenuItem(value: ModSortMode.name, child: T('按名称')),
PopupMenuItem(value: ModSortMode.size, child: T('按大小')),
PopupMenuItem(value: ModSortMode.mtime, child: T('按修改时间')),
],
),
],
@@ -119,12 +120,12 @@ class _ModListPageState extends State<ModListPage>
if (mod.error != null)
Padding(
padding: const EdgeInsets.all(12),
child: Text('加载失败:${mod.error}',
child: Text(S.f('加载失败:{0}', [mod.error.toString()]),
style: TextStyle(color: Theme.of(context).colorScheme.error)),
),
Expanded(
child: mod.files.isEmpty && !mod.loading
? const Center(child: Text('目录下没有 .jar 文件'))
? const Center(child: T('目录下没有 .jar 文件'))
: ListView.builder(
itemCount: mod.files.length,
itemBuilder: (context, i) {
@@ -139,9 +140,9 @@ class _ModListPageState extends State<ModListPage>
trailing: PopupMenuButton<String>(
onSelected: (a) => _onAction(context, mod, f, a),
itemBuilder: (_) => const [
PopupMenuItem(value: 'detail', child: Text('详情')),
PopupMenuItem(value: 'rename', child: Text('重命名')),
PopupMenuItem(value: 'delete', child: Text('删除')),
PopupMenuItem(value: 'detail', child: T('详情')),
PopupMenuItem(value: 'rename', child: T('重命名')),
PopupMenuItem(value: 'delete', child: T('删除')),
],
),
onTap: () => Navigator.push(
@@ -158,7 +159,7 @@ class _ModListPageState extends State<ModListPage>
),
floatingActionButton: FloatingActionButton.extended(
icon: const Icon(Icons.upload_file),
label: const Text('上传 jar'),
label: T('上传 jar'),
onPressed: mod.loading ? null : () => _upload(context, mod),
),
);
@@ -177,7 +178,7 @@ class _ModListPageState extends State<ModListPage>
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('上传失败:$e')));
.showSnackBar(SnackBar(content: Text(S.f('上传失败:{0}', [e.toString()]))));
}
}
}
@@ -189,11 +190,11 @@ class _ModListPageState extends State<ModListPage>
final ok = await showDialog<bool>(
context: context,
builder: (_) => AlertDialog(
title: const Text('确认删除'),
content: Text('确定要删除 ${f.fileName} 吗?此操作不可恢复。'),
title: T('确认删除'),
content: Text(S.f('确定要删除 {0} 吗?此操作不可恢复。', [f.fileName])),
actions: [
TextButton(onPressed: () => Navigator.pop(context, false), child: const Text('取消')),
FilledButton(onPressed: () => Navigator.pop(context, true), child: const Text('删除')),
TextButton(onPressed: () => Navigator.pop(context, false), child: T('取消')),
FilledButton(onPressed: () => Navigator.pop(context, true), child: T('删除')),
],
),
);
@@ -204,13 +205,13 @@ class _ModListPageState extends State<ModListPage>
final newName = await showDialog<String>(
context: context,
builder: (_) => AlertDialog(
title: const Text('重命名'),
title: T('重命名'),
content: TextField(controller: ctrl, autofocus: true),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('取消')),
TextButton(onPressed: () => Navigator.pop(context), child: T('取消')),
FilledButton(
onPressed: () => Navigator.pop(context, ctrl.text.trim()),
child: const Text('确定')),
child: T('确定')),
],
),
);
@@ -242,7 +243,7 @@ class _NoSshHint extends StatelessWidget {
children: [
const Icon(Icons.no_encryption_outlined, size: 56),
const SizedBox(height: 12),
Text('$serverName 未配置 SSH'),
Text(S.f('{0} 未配置 SSH', [serverName])),
const SizedBox(height: 8),
const Text(
'模组管理需要 SSH 连接。请在「服务器」页编辑该服务器,\n开启 SSH 并填写用户名和密码。',