refactor(language): move language constants to common module and improve language handling
This commit is contained in:
@@ -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 模型设置
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user