Skip to content

Commit 94ea2f6

Browse files
committed
i18n(vscode): localize auth status messages by VS Code UI language
Add English counterparts for AUTH_MESSAGES and a getAuthMessage(key, language) helper. loginService now picks zh/en via vscode.env.language for user-facing error fields (e.g. 'No valid authentication information found').
1 parent 4c48e86 commit 94ea2f6

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

packages/vscode-ui-plugin/src/i18n/messages.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ export const AUTH_MESSAGES = {
203203
AUTH_STATUS_CHECK_FAILED: '登录状态检查失败',
204204
LOGIN_FLOW_START_FAILED: '登录流程启动失败',
205205
LOGIN_TIMEOUT: '登录超时(5分钟)',
206+
207+
// 🎯 English counterparts (selected at runtime via vscode.env.language)
208+
NO_VALID_AUTH_INFO_EN: 'No valid authentication information found',
209+
NO_VALID_AUTH_INFO_NEEDS_LOGIN_EN: 'No valid authentication information found, login required',
210+
AUTH_STATUS_CHECK_FAILED_EN: 'Failed to check login status',
211+
LOGIN_FLOW_START_FAILED_EN: 'Failed to start login flow',
212+
LOGIN_TIMEOUT_EN: 'Login timed out (5 minutes)',
206213
} as const;
207214

208215
// =============================================================================
@@ -287,5 +294,31 @@ export const I18N_MESSAGES = {
287294
COMMON: COMMON_MESSAGES,
288295
} as const;
289296

297+
/**
298+
* Returns true when the VS Code UI language is Chinese (zh-*).
299+
* Imported lazily to avoid coupling this constants module to the vscode API at
300+
* load time; callers in the extension host can pass the result of
301+
* `vscode.env.language` directly.
302+
*/
303+
export function isChineseLocale(language: string): boolean {
304+
return language.toLowerCase().startsWith('zh');
305+
}
306+
307+
/**
308+
* Picks the localized auth message based on the given VS Code UI language.
309+
* @param key A base key in AUTH_MESSAGES (the zh variant); the `_EN` suffixed
310+
* entry is used for non-Chinese locales.
311+
* @param language Typically `vscode.env.language`.
312+
*/
313+
export function getAuthMessage(
314+
key: 'NO_VALID_AUTH_INFO' | 'NO_VALID_AUTH_INFO_NEEDS_LOGIN' | 'AUTH_STATUS_CHECK_FAILED' | 'LOGIN_FLOW_START_FAILED' | 'LOGIN_TIMEOUT',
315+
language: string,
316+
): string {
317+
if (isChineseLocale(language)) {
318+
return AUTH_MESSAGES[key];
319+
}
320+
return AUTH_MESSAGES[`${key}_EN`];
321+
}
322+
290323
export default I18N_MESSAGES;
291324

packages/vscode-ui-plugin/src/services/loginService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as vscode from 'vscode';
77
import { ProxyAuthManager, AuthType, AuthServer, AuthTemplates } from 'deepv-code-core';
88
import { Logger } from '../utils/logger';
9-
import { AUTH_MESSAGES } from '../i18n/messages';
9+
import { AUTH_MESSAGES, getAuthMessage } from '../i18n/messages';
1010

1111
export interface LoginResult {
1212
success: boolean;
@@ -103,14 +103,14 @@ export class LoginService {
103103
this.logger.info(`❌ ${AUTH_MESSAGES.NO_VALID_AUTH_INFO_NEEDS_LOGIN}`);
104104
return {
105105
isLoggedIn: false,
106-
error: AUTH_MESSAGES.NO_VALID_AUTH_INFO
106+
error: getAuthMessage('NO_VALID_AUTH_INFO', vscode.env.language)
107107
};
108108

109109
} catch (error) {
110110
this.logger.error('❌ 检查登录状态失败', error instanceof Error ? error : undefined);
111111
return {
112112
isLoggedIn: false,
113-
error: error instanceof Error ? error.message : AUTH_MESSAGES.AUTH_STATUS_CHECK_FAILED
113+
error: error instanceof Error ? error.message : getAuthMessage('AUTH_STATUS_CHECK_FAILED', vscode.env.language)
114114
};
115115
}
116116
}

0 commit comments

Comments
 (0)