From 2fc4299f069a9bd78742f763fee978aa66745fbc Mon Sep 17 00:00:00 2001 From: H-Chris233 Date: Fri, 1 May 2026 15:28:49 +0800 Subject: [PATCH] Keep provider validation messages locale neutral The credential validation IPC returned Chinese success text that Settings rendered directly. Return a structured model count instead and let the frontend localize success or empty-list states through existing i18n resources. Constraint: Review comment requires locale-neutral validation output. Rejected: Returning message keys from Rust | model count is simpler and keeps presentation entirely in the frontend. Confidence: high Scope-risk: narrow Tested: cargo check --manifest-path openless-all/app/src-tauri/Cargo.toml Tested: npm run build Tested: git diff --check --- openless-all/app/src-tauri/src/commands.rs | 9 +++------ openless-all/app/src/i18n/en.ts | 2 +- openless-all/app/src/i18n/zh-CN.ts | 2 +- openless-all/app/src/lib/ipc.ts | 4 ++-- openless-all/app/src/pages/Settings.tsx | 7 ++++++- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/openless-all/app/src-tauri/src/commands.rs b/openless-all/app/src-tauri/src/commands.rs index 3dc46b53..14599065 100644 --- a/openless-all/app/src-tauri/src/commands.rs +++ b/openless-all/app/src-tauri/src/commands.rs @@ -85,9 +85,10 @@ pub fn read_credential(account: String) -> Result, String> { } #[derive(Serialize)] +#[serde(rename_all = "camelCase")] pub struct ProviderCheckResult { ok: bool, - message: String, + model_count: usize, } #[derive(Serialize)] @@ -102,11 +103,7 @@ pub async fn validate_provider_credentials(kind: String) -> Result { } export function validateProviderCredentials(kind: 'llm' | 'asr'): Promise { - return invokeOrMock('validate_provider_credentials', { kind }, () => ({ ok: true, message: 'Mock credentials are valid.' })); + return invokeOrMock('validate_provider_credentials', { kind }, () => ({ ok: true, modelCount: 2 })); } export function listProviderModels(kind: 'llm' | 'asr'): Promise { diff --git a/openless-all/app/src/pages/Settings.tsx b/openless-all/app/src/pages/Settings.tsx index bc9eab3d..c4590c72 100644 --- a/openless-all/app/src/pages/Settings.tsx +++ b/openless-all/app/src/pages/Settings.tsx @@ -407,7 +407,12 @@ function ProviderTools({ kind, modelAccount, onModelSelected }: { kind: 'llm' | setResult('loading', t('settings.providers.validating')); try { const result = await validateProviderCredentials(kind); - setResult(result.ok ? 'success' : 'error', result.message || t('settings.providers.validateSuccess')); + setResult( + result.ok ? (result.modelCount === 0 ? 'empty' : 'success') : 'error', + result.modelCount === 0 + ? t('settings.providers.modelsEmpty') + : t('settings.providers.validateSuccess', { count: result.modelCount }), + ); } catch (error) { setResult('error', providerErrorMessage(error, t)); }