refactor(language): move language constants to common module and improve language handling

This commit is contained in:
2025-11-14 17:42:10 +08:00
parent ef8076d87f
commit 4356813820
8 changed files with 124 additions and 88 deletions

View File

@@ -9,6 +9,7 @@ import type { LLMFactory } from "@/constants/llm";
import type { IMcpServer, IMcpServerListResponse } from "@/interfaces/database/mcp";
import type { IImportMcpServersRequestBody, ITestMcpRequestBody, ICreateMcpServerRequestBody } from "@/interfaces/request/mcp";
import type { IPaginationBody } from "@/interfaces/request/base";
import { LanguageAbbreviation, LanguageAbbreviationKeysMap, LanguageTranslationMap } from "@/constants/common";
/**
* 个人中心设置
@@ -49,6 +50,28 @@ export function useProfileSetting() {
};
}
export function useLanguageSetting() {
const { userInfo, updateUserInfo } = useProfileSetting();
const [language, setLanguage] = useState(userInfo?.language || 'English');
const changeLanguage = async (language: LanguageAbbreviation) => {
try {
// LanguageAbbreviation to language
const translatedLanguage = LanguageAbbreviationKeysMap[language];
await updateUserInfo({ language: translatedLanguage });
setLanguage(translatedLanguage);
} catch (error) {
logger.error('更新语言设置失败:', error);
throw error;
}
}
return {
language,
changeLanguage,
}
}
/**
* LLM 模型设置
*/