From f92dd4cc5a6567dcacf158dc99e86dcb98cef5c4 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 5 Nov 2025 08:52:36 +0800 Subject: [PATCH] fix(i18n): internationalize test script related error messages Fixed 5 hardcoded Chinese error messages to support bilingual display: Backend changes (services): - provider.rs: Fixed 4 error messages: * Data format error when deserializing array (line 731) * Data format error when deserializing single object (line 738) * Regex initialization failure (line 1163) * App type not found (line 1191) - speedtest.rs: Fixed 1 error message: * HTTP client creation failure (line 104) All errors now use AppError::localized to provide both Chinese and English messages. Impact: - Users will now see properly localized error messages when testing usage scripts - Error messages respect the application language setting - Better user experience for English-speaking users --- src-tauri/src/services/provider.rs | 24 ++++++++++++++++++++---- src-tauri/src/services/speedtest.rs | 6 +++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/services/provider.rs b/src-tauri/src/services/provider.rs index 564e706..a5911ba 100644 --- a/src-tauri/src/services/provider.rs +++ b/src-tauri/src/services/provider.rs @@ -728,10 +728,18 @@ impl ProviderService { Ok(data) => { let usage_list: Vec = if data.is_array() { serde_json::from_value(data) - .map_err(|e| AppError::Message(format!("数据格式错误: {}", e)))? + .map_err(|e| AppError::localized( + "usage_script.data_format_error", + format!("数据格式错误: {}", e), + format!("Data format error: {}", e) + ))? } else { let single: UsageData = serde_json::from_value(data) - .map_err(|e| AppError::Message(format!("数据格式错误: {}", e)))?; + .map_err(|e| AppError::localized( + "usage_script.data_format_error", + format!("数据格式错误: {}", e), + format!("Data format error: {}", e) + ))?; vec![single] }; @@ -1152,7 +1160,11 @@ impl ProviderService { let base_url = if config_toml.contains("base_url") { let re = Regex::new(r#"base_url\s*=\s*["']([^"']+)["']"#) - .map_err(|e| AppError::Message(format!("正则初始化失败: {}", e)))?; + .map_err(|e| AppError::localized( + "provider.regex_init_failed", + format!("正则初始化失败: {}", e), + format!("Failed to initialize regex: {}", e) + ))?; re.captures(config_toml) .and_then(|caps| caps.get(1)) .map(|m| m.as_str().to_string()) @@ -1177,7 +1189,11 @@ impl ProviderService { } fn app_not_found(app_type: &AppType) -> AppError { - AppError::Message(format!("应用类型不存在: {:?}", app_type)) + AppError::localized( + "provider.app_not_found", + format!("应用类型不存在: {:?}", app_type), + format!("App type not found: {:?}", app_type) + ) } fn now_millis() -> i64 { diff --git a/src-tauri/src/services/speedtest.rs b/src-tauri/src/services/speedtest.rs index 83ec872..cc0896f 100644 --- a/src-tauri/src/services/speedtest.rs +++ b/src-tauri/src/services/speedtest.rs @@ -101,7 +101,11 @@ impl SpeedtestService { .redirect(reqwest::redirect::Policy::limited(5)) .user_agent("cc-switch-speedtest/1.0") .build() - .map_err(|e| AppError::Message(format!("创建 HTTP 客户端失败: {e}"))) + .map_err(|e| AppError::localized( + "speedtest.client_create_failed", + format!("创建 HTTP 客户端失败: {e}"), + format!("Failed to create HTTP client: {e}") + )) } fn sanitize_timeout(timeout_secs: Option) -> u64 {