feat: 多语言 初步引入

This commit is contained in:
2024-03-15 00:01:06 +08:00
parent eae02be2af
commit b2c13a8a6f
45 changed files with 525 additions and 446 deletions

View File

@ -24,13 +24,13 @@ class HomeDownloaderUI extends HookConsumerWidget {
const SizedBox(width: 24),
const SizedBox(width: 12),
for (final item in <MapEntry<String, IconData>, String>{
const MapEntry("settings", FluentIcons.settings): "限速设置",
const MapEntry("settings", FluentIcons.settings): S.current.downloader_speed_limit_settings,
if (state.tasks.isNotEmpty)
const MapEntry("pause_all", FluentIcons.pause): "全部暂停",
const MapEntry("pause_all", FluentIcons.pause): S.current.downloader_action_pause_all,
if (state.waitingTasks.isNotEmpty)
const MapEntry("resume_all", FluentIcons.download): "恢复全部",
const MapEntry("resume_all", FluentIcons.download): S.current.downloader_action_resume_all,
if (state.tasks.isNotEmpty || state.waitingTasks.isNotEmpty)
const MapEntry("cancel_all", FluentIcons.cancel): "全部取消",
const MapEntry("cancel_all", FluentIcons.cancel): S.current.downloader_action_cancel_all,
}.entries)
Padding(
padding: const EdgeInsets.only(left: 6, right: 6),
@ -52,9 +52,9 @@ class HomeDownloaderUI extends HookConsumerWidget {
],
),
if (model.getTasksLen() == 0)
const Expanded(
Expanded(
child: Center(
child: Text("无下载任务"),
child: Text(S.current.downloader_info_no_download_tasks),
))
else
Expanded(
@ -171,22 +171,22 @@ class HomeDownloaderUI extends HookConsumerWidget {
if (type != "stopped")
DropDownButton(
closeAfterClick: false,
title: const Padding(
padding: EdgeInsets.all(3),
child: Text('选项'),
title: Padding(
padding: const EdgeInsets.all(3),
child: Text(S.current.downloader_action_options),
),
items: [
if (task.status == "paused")
MenuFlyoutItem(
leading:
const Icon(FluentIcons.download),
text: const Text('继续下载'),
text: Text(S.current.downloader_action_continue_download),
onPressed: () =>
model.resumeTask(task.gid))
else if (task.status == "active")
MenuFlyoutItem(
leading: const Icon(FluentIcons.pause),
text: const Text('暂停下载'),
text: Text(S.current.downloader_action_pause_download),
onPressed: () =>
model.pauseTask(task.gid)),
const MenuFlyoutSeparator(),
@ -195,7 +195,7 @@ class HomeDownloaderUI extends HookConsumerWidget {
FluentIcons.chrome_close,
size: 14,
),
text: const Text('取消下载'),
text: Text(S.current.downloader_action_cancel_download),
onPressed: () =>
model.cancelTask(context, task.gid)),
MenuFlyoutItem(
@ -203,7 +203,7 @@ class HomeDownloaderUI extends HookConsumerWidget {
FluentIcons.folder_open,
size: 14,
),
text: const Text('打开文件夹'),
text: Text(S.current.action_open_folder),
onPressed: () => model.openFolder(task)),
],
),
@ -243,4 +243,4 @@ class HomeDownloaderUI extends HookConsumerWidget {
),
useBodyContainer: true);
}
}
}

View File

@ -21,7 +21,7 @@ part 'home_downloader_ui_model.freezed.dart';
@freezed
class HomeDownloaderUIState with _$HomeDownloaderUIState {
const factory HomeDownloaderUIState({
factory HomeDownloaderUIState({
@Default([]) List<Aria2Task> tasks,
@Default([]) List<Aria2Task> waitingTasks,
@Default([]) List<Aria2Task> stoppedTasks,
@ -40,23 +40,23 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
bool _disposed = false;
final statusMap = {
"active": "下载中...",
"waiting": "等待中",
"paused": "已暂停",
"error": "下载失败",
"complete": "下载完成",
"removed": "已删除",
"active": S.current.downloader_info_downloading_status,
"waiting": S.current.downloader_info_waiting,
"paused": S.current.downloader_info_paused,
"error": S.current.downloader_info_download_failed,
"complete": S.current.downloader_info_download_completed,
"removed": S.current.downloader_info_deleted,
};
final listHeaderStatusMap = {
"active": "下载中",
"waiting": "等待中",
"stopped": "已结束",
"active": S.current.downloader_title_downloading,
"waiting": S.current.downloader_info_waiting,
"stopped": S.current.downloader_title_ended,
};
@override
HomeDownloaderUIState build() {
state = const HomeDownloaderUIState();
state = HomeDownloaderUIState();
_listenDownloader();
ref.onDispose(() {
_disposed = true;
@ -79,7 +79,7 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
return;
case "cancel_all":
final userOK = await showConfirmDialogs(
context, "确认取消全部任务?", const Text("如果文件不再需要,你可能需要手动删除下载文件。"));
context, "确认取消全部任务?", Text(S.current.downloader_info_manual_file_deletion_note));
if (userOK == true) {
if (!aria2cState.isRunning) return;
try {
@ -170,7 +170,7 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
if (gid != null) {
if (!context.mounted) return;
final ok = await showConfirmDialogs(
context, "确认取消下载?", const Text("如果文件不再需要,你可能需要手动删除下载文件。"));
context, "确认取消下载?", Text(S.current.downloader_info_manual_file_deletion_note));
if (ok == true) {
final aria2c = ref.read(aria2cModelProvider).aria2c;
await aria2c?.remove(gid);
@ -242,22 +242,22 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
if (!context.mounted) return;
final ok = await showConfirmDialogs(
context,
"限速设置",
S.current.downloader_speed_limit_settings,
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"SC 汉化盒子使用 p2p 网络来加速文件下载,如果您流量有限,可在此处将上传带宽设置为 1(byte)。",
S.current.downloader_info_p2p_network_note,
style: TextStyle(
fontSize: 14,
color: Colors.white.withOpacity(.6),
),
),
const SizedBox(height: 24),
const Text("请输入下载单位1、100k、10m 0或留空为不限速。"),
Text(S.current.downloader_info_download_unit_input_prompt),
const SizedBox(height: 12),
const Text("上传限速:"),
Text(S.current.downloader_input_upload_speed_limit),
const SizedBox(height: 6),
TextFormBox(
placeholder: "1、100k、10m、0",
@ -266,7 +266,7 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
inputFormatters: [ifr],
),
const SizedBox(height: 12),
const Text("下载限速:"),
Text(S.current.downloader_input_download_speed_limit),
const SizedBox(height: 6),
TextFormBox(
placeholder: "1、100k、10m、0",
@ -276,7 +276,7 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
),
const SizedBox(height: 24),
Text(
"* P2P 上传仅在下载文件时进行,下载完成后会关闭 p2p 连接。如您想参与做种,请通过关于页面联系我们。",
S.current.downloader_input_info_p2p_upload_note,
style: TextStyle(
fontSize: 13,
color: Colors.white.withOpacity(.6),
@ -303,4 +303,4 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
}
}
}
}
}

View File

@ -136,7 +136,7 @@ class __$$HomeDownloaderUIStateImplCopyWithImpl<$Res>
/// @nodoc
class _$HomeDownloaderUIStateImpl implements _HomeDownloaderUIState {
const _$HomeDownloaderUIStateImpl(
_$HomeDownloaderUIStateImpl(
{final List<Aria2Task> tasks = const [],
final List<Aria2Task> waitingTasks = const [],
final List<Aria2Task> stoppedTasks = const [],
@ -211,7 +211,7 @@ class _$HomeDownloaderUIStateImpl implements _HomeDownloaderUIState {
}
abstract class _HomeDownloaderUIState implements HomeDownloaderUIState {
const factory _HomeDownloaderUIState(
factory _HomeDownloaderUIState(
{final List<Aria2Task> tasks,
final List<Aria2Task> waitingTasks,
final List<Aria2Task> stoppedTasks,

View File

@ -7,7 +7,7 @@ part of 'home_downloader_ui_model.dart';
// **************************************************************************
String _$homeDownloaderUIModelHash() =>
r'947ebb9abb262aea6121c74481753da0eebb9a79';
r'88e1c9a667672d303cb244305dc0aec89d77ffe5';
/// See also [HomeDownloaderUIModel].
@ProviderFor(HomeDownloaderUIModel)