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
This commit is contained in:
@@ -728,10 +728,18 @@ impl ProviderService {
|
|||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let usage_list: Vec<UsageData> = if data.is_array() {
|
let usage_list: Vec<UsageData> = if data.is_array() {
|
||||||
serde_json::from_value(data)
|
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 {
|
} else {
|
||||||
let single: UsageData = serde_json::from_value(data)
|
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]
|
vec![single]
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1152,7 +1160,11 @@ impl ProviderService {
|
|||||||
|
|
||||||
let base_url = if config_toml.contains("base_url") {
|
let base_url = if config_toml.contains("base_url") {
|
||||||
let re = Regex::new(r#"base_url\s*=\s*["']([^"']+)["']"#)
|
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)
|
re.captures(config_toml)
|
||||||
.and_then(|caps| caps.get(1))
|
.and_then(|caps| caps.get(1))
|
||||||
.map(|m| m.as_str().to_string())
|
.map(|m| m.as_str().to_string())
|
||||||
@@ -1177,7 +1189,11 @@ impl ProviderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn app_not_found(app_type: &AppType) -> AppError {
|
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 {
|
fn now_millis() -> i64 {
|
||||||
|
|||||||
@@ -101,7 +101,11 @@ impl SpeedtestService {
|
|||||||
.redirect(reqwest::redirect::Policy::limited(5))
|
.redirect(reqwest::redirect::Policy::limited(5))
|
||||||
.user_agent("cc-switch-speedtest/1.0")
|
.user_agent("cc-switch-speedtest/1.0")
|
||||||
.build()
|
.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>) -> u64 {
|
fn sanitize_timeout(timeout_secs: Option<u64>) -> u64 {
|
||||||
|
|||||||
Reference in New Issue
Block a user