From 0bb8090686cb256ca8e9c9762f8d7fc96bb43ed9 Mon Sep 17 00:00:00 2001 From: Chebotov Nickolay Date: Fri, 6 Feb 2026 15:08:53 +0300 Subject: [PATCH] fix: address language review feedback --- src/i18n/locales/ru.json | 6 +++--- src/pages/LoginPage.tsx | 12 ++++-------- src/stores/useLanguageStore.ts | 7 +++---- src/utils/constants.ts | 11 +++++++++++ src/utils/language.ts | 10 +++++----- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 54954df..0945efc 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -47,8 +47,8 @@ "model_alias_placeholder": "Псевдоним модели (необязательно)" }, "title": { - "main": "CLI Proxy API Management Center", - "login": "CLI Proxy API Management Center", + "main": "Центр управления CLI Proxy API", + "login": "Центр управления CLI Proxy API", "abbr": "CPAMC" }, "auto_login": { @@ -108,7 +108,7 @@ }, "dashboard": { "title": "Панель управления", - "subtitle": "Добро пожаловать в CLI Proxy API Management Center", + "subtitle": "Добро пожаловать в Центр управления CLI Proxy API", "openai_providers": "Поставщики OpenAI", "quick_actions": "Быстрые действия", "current_config": "Текущая конфигурация", diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index 39f4cc4..7290683 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -6,6 +6,7 @@ import { Input } from '@/components/ui/Input'; import { IconEye, IconEyeOff } from '@/components/ui/icons'; import { useAuthStore, useLanguageStore, useNotificationStore } from '@/stores'; import { detectApiBaseFromLocation, normalizeApiBase } from '@/utils/connection'; +import { LANGUAGE_LABEL_KEYS, LANGUAGE_ORDER } from '@/utils/constants'; import { INLINE_LOGO_JPEG } from '@/assets/logoInline'; import type { ApiError, Language } from '@/types'; import styles from './LoginPage.module.scss'; @@ -78,14 +79,9 @@ export function LoginPage() { const [error, setError] = useState(''); const detectedBase = useMemo(() => detectApiBaseFromLocation(), []); - const nextLanguage: Language = language === 'zh-CN' ? 'en' : language === 'en' ? 'ru' : 'zh-CN'; - const nextLanguageLabel = t( - nextLanguage === 'zh-CN' - ? 'language.chinese' - : nextLanguage === 'en' - ? 'language.english' - : 'language.russian' - ); + const nextLanguageIndex = LANGUAGE_ORDER.indexOf(language); + const nextLanguage: Language = LANGUAGE_ORDER[(nextLanguageIndex + 1) % LANGUAGE_ORDER.length]; + const nextLanguageLabel = t(LANGUAGE_LABEL_KEYS[nextLanguage]); useEffect(() => { const init = async () => { diff --git a/src/stores/useLanguageStore.ts b/src/stores/useLanguageStore.ts index e04a516..e80183e 100644 --- a/src/stores/useLanguageStore.ts +++ b/src/stores/useLanguageStore.ts @@ -6,7 +6,7 @@ import { create } from 'zustand'; import { persist } from 'zustand/middleware'; import type { Language } from '@/types'; -import { STORAGE_KEY_LANGUAGE } from '@/utils/constants'; +import { LANGUAGE_ORDER, STORAGE_KEY_LANGUAGE } from '@/utils/constants'; import i18n from '@/i18n'; import { getInitialLanguage } from '@/utils/language'; @@ -29,9 +29,8 @@ export const useLanguageStore = create()( toggleLanguage: () => { const { language, setLanguage } = get(); - const order: Language[] = ['zh-CN', 'en', 'ru']; - const currentIndex = order.indexOf(language); - const nextLanguage = order[(currentIndex + 1) % order.length]; + const currentIndex = LANGUAGE_ORDER.indexOf(language); + const nextLanguage = LANGUAGE_ORDER[(currentIndex + 1) % LANGUAGE_ORDER.length]; setLanguage(nextLanguage); } }), diff --git a/src/utils/constants.ts b/src/utils/constants.ts index eb1b650..1b9ac60 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -3,6 +3,8 @@ * 从原项目 src/utils/constants.js 迁移 */ +import type { Language } from '@/types'; + // 缓存过期时间(毫秒) export const CACHE_EXPIRY_MS = 30 * 1000; // 与基线保持一致,减少管理端压力 @@ -33,6 +35,15 @@ export const STORAGE_KEY_LANGUAGE = 'cli-proxy-language'; export const STORAGE_KEY_SIDEBAR = 'cli-proxy-sidebar-collapsed'; export const STORAGE_KEY_AUTH_FILES_PAGE_SIZE = 'cli-proxy-auth-files-page-size'; +// 语言配置 +export const LANGUAGE_ORDER: Language[] = ['zh-CN', 'en', 'ru']; +export const LANGUAGE_LABEL_KEYS: Record = { + 'zh-CN': 'language.chinese', + en: 'language.english', + ru: 'language.russian' +}; +export const SUPPORTED_LANGUAGES: Language[] = LANGUAGE_ORDER; + // 通知持续时间 export const NOTIFICATION_DURATION_MS = 3000; diff --git a/src/utils/language.ts b/src/utils/language.ts index 1975384..8aa1767 100644 --- a/src/utils/language.ts +++ b/src/utils/language.ts @@ -1,16 +1,16 @@ import type { Language } from '@/types'; -import { STORAGE_KEY_LANGUAGE } from '@/utils/constants'; +import { STORAGE_KEY_LANGUAGE, SUPPORTED_LANGUAGES } from '@/utils/constants'; const parseStoredLanguage = (value: string): Language | null => { try { const parsed = JSON.parse(value); const candidate = parsed?.state?.language ?? parsed?.language ?? parsed; - if (candidate === 'zh-CN' || candidate === 'en' || candidate === 'ru') { - return candidate; + if (SUPPORTED_LANGUAGES.includes(candidate as Language)) { + return candidate as Language; } } catch { - if (value === 'zh-CN' || value === 'en' || value === 'ru') { - return value; + if (SUPPORTED_LANGUAGES.includes(value as Language)) { + return value as Language; } } return null;