mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
fix: classify agents as Chinese and English (#7287)
* feat: Create i18n for agents in Chinese * fix: enhance agent loading by supporting language-specific agent files --------- Co-authored-by: Pleasurecruise <3196812536@qq.com>
This commit is contained in:
parent
5d9fc292b7
commit
804f9235cd
9098
resources/data/agents-en.json
Normal file
9098
resources/data/agents-en.json
Normal file
File diff suppressed because one or more lines are too long
9098
resources/data/agents-zh.json
Normal file
9098
resources/data/agents-zh.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,5 +1,7 @@
|
||||
import { groupTranslations } from '@renderer/pages/agents/agentGroupTranslations'
|
||||
import { DynamicIcon, IconName } from 'lucide-react/dynamic'
|
||||
import { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
interface Props {
|
||||
groupName: string
|
||||
@ -8,6 +10,25 @@ interface Props {
|
||||
}
|
||||
|
||||
export const AgentGroupIcon: FC<Props> = ({ groupName, size = 20, strokeWidth = 1.2 }) => {
|
||||
const { i18n } = useTranslation()
|
||||
const currentLanguage = i18n.language as keyof (typeof groupTranslations)[string]
|
||||
|
||||
const findOriginalKey = (name: string): string => {
|
||||
if (groupTranslations[name]) {
|
||||
return name
|
||||
}
|
||||
|
||||
for (const key in groupTranslations) {
|
||||
if (groupTranslations[key][currentLanguage] === name) {
|
||||
return key
|
||||
}
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
const originalKey = findOriginalKey(groupName)
|
||||
|
||||
const iconMap: { [key: string]: IconName } = {
|
||||
我的: 'user-check',
|
||||
精选: 'star',
|
||||
@ -46,5 +67,5 @@ export const AgentGroupIcon: FC<Props> = ({ groupName, size = 20, strokeWidth =
|
||||
搜索: 'search'
|
||||
} as const
|
||||
|
||||
return <DynamicIcon name={iconMap[groupName] || 'bot-message-square'} size={size} strokeWidth={strokeWidth} />
|
||||
return <DynamicIcon name={iconMap[originalKey] || 'bot-message-square'} size={size} strokeWidth={strokeWidth} />
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import store from '@renderer/store'
|
||||
import { Agent } from '@renderer/types'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
let _agents: Agent[] = []
|
||||
|
||||
@ -22,6 +23,8 @@ export function useSystemAgents() {
|
||||
const [agents, setAgents] = useState<Agent[]>([])
|
||||
const { resourcesPath } = useRuntime()
|
||||
const { agentssubscribeUrl } = store.getState().settings
|
||||
const { i18n } = useTranslation()
|
||||
const currentLanguage = i18n.language
|
||||
|
||||
useEffect(() => {
|
||||
const loadAgents = async () => {
|
||||
@ -44,9 +47,21 @@ export function useSystemAgents() {
|
||||
}
|
||||
|
||||
// 如果没有远程配置或获取失败,加载本地代理
|
||||
if (resourcesPath && _agents.length === 0) {
|
||||
const localAgentsData = await window.api.fs.read(resourcesPath + '/data/agents.json', 'utf-8')
|
||||
_agents = JSON.parse(localAgentsData) as Agent[]
|
||||
if (resourcesPath) {
|
||||
try {
|
||||
let fileName = 'agents.json'
|
||||
if (currentLanguage === 'zh-CN') {
|
||||
fileName = 'agents-zh.json'
|
||||
} else {
|
||||
fileName = 'agents-en.json'
|
||||
}
|
||||
|
||||
const localAgentsData = await window.api.fs.read(`${resourcesPath}/data/${fileName}`, 'utf-8')
|
||||
_agents = JSON.parse(localAgentsData) as Agent[]
|
||||
} catch (error) {
|
||||
const localAgentsData = await window.api.fs.read(resourcesPath + '/data/agents.json', 'utf-8')
|
||||
_agents = JSON.parse(localAgentsData) as Agent[]
|
||||
}
|
||||
}
|
||||
|
||||
setAgents(_agents)
|
||||
@ -58,7 +73,7 @@ export function useSystemAgents() {
|
||||
}
|
||||
|
||||
loadAgents()
|
||||
}, [defaultAgent, resourcesPath, agentssubscribeUrl])
|
||||
}, [defaultAgent, resourcesPath, agentssubscribeUrl, currentLanguage])
|
||||
|
||||
return agents
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user