chore: update i18n

This commit is contained in:
wonfen
2026-07-24 11:53:50 +08:00
parent 82c486923b
commit bce83d5c6f
123 changed files with 2178 additions and 277 deletions
+52 -29
View File
@@ -1,5 +1,4 @@
use super::CmdResult;
use super::StringifyErr as _;
use super::{CmdResult, StringifyErr as _, WithErrorCode as _, coded_error};
use crate::cmd::validate::{ValidationNoticeTarget, handle_validation_notice};
use crate::config::profiles;
use crate::utils::window_manager::WindowManager;
@@ -60,7 +59,7 @@ pub async fn enhance_profiles() -> CmdResult<ValidationOutcome> {
}
Err(e) => {
logging!(error, Type::Cmd, "{}", e);
Err(e.to_string().into())
Err(coded_error("PROFILE_ENHANCE_FAILED", e))
}
}
}
@@ -78,18 +77,18 @@ pub async fn import_profile(url: std::string::String, option: Option<PrfOption>)
}
Err(e) => {
logging!(error, Type::Cmd, "[导入订阅] 下载失败: {}", e);
return Err(profile_import_error(&e).into());
return Err(coded_error("PROFILE_IMPORT_FAILED", profile_import_error(&e)));
}
};
if let Err(e) = profiles_append_item_safe(item).await {
logging!(error, Type::Cmd, "[导入订阅] 保存配置失败: {}", e);
return Err(format!("导入订阅失败: {}", e).into());
return Err(coded_error("PROFILE_IMPORT_FAILED", e));
}
if let Err(e) = profiles_save_file_safe().await {
logging!(error, Type::Cmd, "[导入订阅] 保存配置文件失败: {}", e);
return Err(format!("导入订阅失败: {}", e).into());
return Err(coded_error("PROFILE_IMPORT_FAILED", e));
}
logging!(info, Type::Cmd, "[导入订阅] 配置文件保存成功");
logging_error!(Type::Timer, Timer::global().refresh().await);
@@ -113,7 +112,7 @@ pub async fn reorder_profile(active_id: String, over_id: String) -> CmdResult {
}
Err(err) => {
logging!(error, Type::Cmd, "重新排序配置文件失败: {}", err);
Err(format!("重新排序配置文件失败: {}", err).into())
Err(coded_error("PROFILE_REORDER_FAILED", err))
}
}
}
@@ -124,7 +123,9 @@ pub async fn reorder_profile(active_id: String, over_id: String) -> CmdResult {
pub async fn create_profile(item: PrfItem, file_data: Option<String>) -> CmdResult {
match profiles_append_item_with_filedata_safe(&item, file_data).await {
Ok(_) => {
profiles_save_file_safe().await.stringify_err()?;
profiles_save_file_safe()
.await
.with_error_code("PROFILE_CREATE_FAILED")?;
logging_error!(Type::Timer, Timer::global().refresh().await);
// 发送配置变更通知
if let Some(uid) = &item.uid {
@@ -133,10 +134,7 @@ pub async fn create_profile(item: PrfItem, file_data: Option<String>) -> CmdResu
}
Ok(())
}
Err(err) => match err.to_string().as_str() {
"the file already exists" => Err("the file already exists".into()),
_ => Err(format!("add profile error: {err}").into()),
},
Err(err) => Err(coded_error("PROFILE_CREATE_FAILED", err)),
}
}
@@ -147,7 +145,7 @@ pub async fn update_profile(index: String, option: Option<PrfOption>) -> CmdResu
Ok(_) => Ok(()),
Err(e) => {
logging!(error, Type::Cmd, "{}", e);
Err(e.to_string().into())
Err(coded_error("PROFILE_UPDATE_FAILED", e))
}
}
}
@@ -156,8 +154,12 @@ pub async fn update_profile(index: String, option: Option<PrfOption>) -> CmdResu
#[tauri::command]
pub async fn delete_profile(index: String) -> CmdResult {
// 使用Send-safe helper函数
let should_update = profiles_delete_item_safe(&index).await.stringify_err()?;
profiles_save_file_safe().await.stringify_err()?;
let should_update = profiles_delete_item_safe(&index)
.await
.with_error_code("PROFILE_DELETE_FAILED")?;
profiles_save_file_safe()
.await
.with_error_code("PROFILE_DELETE_FAILED")?;
if let Err(e) = Tray::global().update_tooltip().await {
logging!(warn, Type::Cmd, "Warning: 异步更新托盘提示失败: {e}");
}
@@ -176,15 +178,18 @@ pub async fn delete_profile(index: String) -> CmdResult {
Ok(outcome) => {
logging!(warn, Type::Cmd, "删除订阅后更新配置失败: {}", outcome);
handle_validation_notice(&outcome, ValidationNoticeTarget::Runtime, "运行时配置");
return Err(outcome.to_string().into());
return Err(coded_error("PROFILE_DELETE_FAILED", outcome));
}
Err(e) => {
logging!(error, Type::Cmd, "{}", e);
return Err(e.to_string().into());
return Err(coded_error("PROFILE_DELETE_FAILED", e));
}
}
}
Timer::global().refresh().await.stringify_err()?;
Timer::global()
.refresh()
.await
.with_error_code("PROFILE_DELETE_FAILED")?;
Ok(())
}
@@ -322,7 +327,9 @@ pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult<ValidationO
Config::profiles().await.edit_draft(|d| d.patch_config(&profiles));
perform_config_update(target_profile, previous_profile.as_ref()).await
perform_config_update(target_profile, previous_profile.as_ref())
.await
.map_err(|error| coded_error("PROFILE_SWITCH_FAILED", error))
}
/// 根据profile name修改profiles
@@ -354,7 +361,9 @@ pub async fn patch_profile(index: String, profile: PrfItem) -> CmdResult {
false
};
profiles_patch_item_safe(&index, &profile).await.stringify_err()?;
profiles_patch_item_safe(&index, &profile)
.await
.with_error_code("PROFILE_UPDATE_FAILED")?;
// 如果更新间隔或允许自动更新变更,异步刷新定时器
if should_refresh_timer {
@@ -379,17 +388,22 @@ pub async fn view_profile(index: String) -> CmdResult {
let profiles_ref = profiles.latest_arc();
let file = profiles_ref
.get_item(&index)
.stringify_err()?
.with_error_code("PROFILE_OPEN_FAILED")?
.file
.as_ref()
.ok_or("the file field is null")?;
.ok_or_else(|| coded_error("PROFILE_OPEN_FAILED", "the file field is null"))?;
let path = dirs::app_profiles_dir().stringify_err()?.join(file.as_str());
let path = dirs::app_profiles_dir()
.with_error_code("PROFILE_OPEN_FAILED")?
.join(file.as_str());
if !path.exists() {
return CmdResult::Err(format!("file not found \"{}\"", path.display()).into());
return CmdResult::Err(coded_error(
"PROFILE_OPEN_FAILED",
format!("file not found \"{}\"", path.display()),
));
}
help::open_file(path).stringify_err()
help::open_file(path).with_error_code("PROFILE_OPEN_FAILED")
}
/// 读取配置文件内容
@@ -399,23 +413,32 @@ pub async fn read_profile_file(index: String) -> CmdResult<String> {
let profiles = Config::profiles().await;
let profiles_ref = profiles.latest_arc();
PrfItem {
file: profiles_ref.get_item(&index).stringify_err()?.file.to_owned(),
file: profiles_ref
.get_item(&index)
.with_error_code("PROFILE_READ_FAILED")?
.file
.to_owned(),
..Default::default()
}
};
if let Some(file) = item.file.as_ref() {
let path = dirs::app_profiles_dir().stringify_err()?.join(file.as_str());
let path = dirs::app_profiles_dir()
.with_error_code("PROFILE_READ_FAILED")?
.join(file.as_str());
match tokio::fs::try_exists(&path).await {
Ok(true) => {}
Ok(false) => return Ok(String::new()),
Err(err) => {
return Err(format!("failed to check profile file \"{}\": {err}", path.display()).into());
return Err(coded_error(
"PROFILE_READ_FAILED",
format!("failed to check profile file \"{}\": {err}", path.display()),
));
}
}
}
let data = item.read_file().await.stringify_err()?;
let data = item.read_file().await.with_error_code("PROFILE_READ_FAILED")?;
Ok(data)
}