mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 15:49:29 +08:00
feat(翻译): 添加翻译成功提醒并跟踪当前路由
在翻译完成后添加成功提示,但仅在非翻译页面显示 添加activeRoute状态以跟踪当前路由路径
This commit is contained in:
parent
6d929c322b
commit
8f6bea490f
@ -10,6 +10,8 @@ import useNavBackgroundColor from '@renderer/hooks/useNavBackgroundColor'
|
|||||||
import { modelGenerating, useRuntime } from '@renderer/hooks/useRuntime'
|
import { modelGenerating, useRuntime } from '@renderer/hooks/useRuntime'
|
||||||
import { useSettings } from '@renderer/hooks/useSettings'
|
import { useSettings } from '@renderer/hooks/useSettings'
|
||||||
import i18n from '@renderer/i18n'
|
import i18n from '@renderer/i18n'
|
||||||
|
import { useAppDispatch } from '@renderer/store'
|
||||||
|
import { setActiveRoute } from '@renderer/store/runtime'
|
||||||
import { ThemeMode } from '@renderer/types'
|
import { ThemeMode } from '@renderer/types'
|
||||||
import { isEmoji } from '@renderer/utils'
|
import { isEmoji } from '@renderer/utils'
|
||||||
import type { MenuProps } from 'antd'
|
import type { MenuProps } from 'antd'
|
||||||
@ -144,6 +146,7 @@ const MainMenus: FC = () => {
|
|||||||
const { minappShow } = useRuntime()
|
const { minappShow } = useRuntime()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
|
|
||||||
const isRoute = (path: string): string => (pathname === path && !minappShow ? 'active' : '')
|
const isRoute = (path: string): string => (pathname === path && !minappShow ? 'active' : '')
|
||||||
const isRoutes = (path: string): string => (pathname.startsWith(path) && !minappShow ? 'active' : '')
|
const isRoutes = (path: string): string => (pathname.startsWith(path) && !minappShow ? 'active' : '')
|
||||||
@ -179,6 +182,7 @@ const MainMenus: FC = () => {
|
|||||||
hideMinappPopup()
|
hideMinappPopup()
|
||||||
await modelGenerating()
|
await modelGenerating()
|
||||||
navigate(path)
|
navigate(path)
|
||||||
|
dispatch(setActiveRoute(path))
|
||||||
}}>
|
}}>
|
||||||
<Icon theme={theme} className={isActive}>
|
<Icon theme={theme} className={isActive}>
|
||||||
{iconMap[icon]}
|
{iconMap[icon]}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import {
|
|||||||
} from '@renderer/store/translate'
|
} from '@renderer/store/translate'
|
||||||
import { Assistant, TranslateHistory } from '@renderer/types'
|
import { Assistant, TranslateHistory } from '@renderer/types'
|
||||||
import { uuid } from '@renderer/utils'
|
import { uuid } from '@renderer/utils'
|
||||||
|
import { t } from 'i18next'
|
||||||
|
|
||||||
export default function useTranslate() {
|
export default function useTranslate() {
|
||||||
const translatedContent = useAppSelector((state) => state.translate.translatedContent)
|
const translatedContent = useAppSelector((state) => state.translate.translatedContent)
|
||||||
@ -40,6 +41,13 @@ export default function useTranslate() {
|
|||||||
await saveTranslateHistory(text, translatedContent, actualSourceLanguage, actualTargetLanguage)
|
await saveTranslateHistory(text, translatedContent, actualSourceLanguage, actualTargetLanguage)
|
||||||
|
|
||||||
setTranslating(false)
|
setTranslating(false)
|
||||||
|
|
||||||
|
const pathname = store.getState().runtime.activeRoute
|
||||||
|
console.log('get pathname', pathname)
|
||||||
|
if (pathname !== '/translate') {
|
||||||
|
// ALTERNATIVE: 也许可以改成通知的形式
|
||||||
|
window.message.success(t('translate.success'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveTranslateHistory = async (
|
const saveTranslateHistory = async (
|
||||||
|
|||||||
@ -2018,6 +2018,7 @@
|
|||||||
},
|
},
|
||||||
"error.failed": "Translation failed",
|
"error.failed": "Translation failed",
|
||||||
"error.not_configured": "Translation model is not configured",
|
"error.not_configured": "Translation model is not configured",
|
||||||
|
"success": "Translation completed",
|
||||||
"history": {
|
"history": {
|
||||||
"clear": "Clear History",
|
"clear": "Clear History",
|
||||||
"clear_description": "Clear history will delete all translation history, continue?",
|
"clear_description": "Clear history will delete all translation history, continue?",
|
||||||
|
|||||||
@ -2017,6 +2017,7 @@
|
|||||||
},
|
},
|
||||||
"error.failed": "翻訳に失敗しました",
|
"error.failed": "翻訳に失敗しました",
|
||||||
"error.not_configured": "翻訳モデルが設定されていません",
|
"error.not_configured": "翻訳モデルが設定されていません",
|
||||||
|
"success": "翻訳が完了しました。",
|
||||||
"history": {
|
"history": {
|
||||||
"clear": "履歴をクリア",
|
"clear": "履歴をクリア",
|
||||||
"clear_description": "履歴をクリアすると、すべての翻訳履歴が削除されます。続行しますか?",
|
"clear_description": "履歴をクリアすると、すべての翻訳履歴が削除されます。続行しますか?",
|
||||||
|
|||||||
@ -2017,6 +2017,7 @@
|
|||||||
},
|
},
|
||||||
"error.failed": "Перевод не удалось",
|
"error.failed": "Перевод не удалось",
|
||||||
"error.not_configured": "Модель перевода не настроена",
|
"error.not_configured": "Модель перевода не настроена",
|
||||||
|
"success": "Перевод завершен",
|
||||||
"history": {
|
"history": {
|
||||||
"clear": "Очистить историю",
|
"clear": "Очистить историю",
|
||||||
"clear_description": "Очистка истории удалит все записи переводов. Продолжить?",
|
"clear_description": "Очистка истории удалит все записи переводов. Продолжить?",
|
||||||
|
|||||||
@ -2015,6 +2015,7 @@
|
|||||||
"content": "翻译后将覆盖原文,是否继续?",
|
"content": "翻译后将覆盖原文,是否继续?",
|
||||||
"title": "翻译确认"
|
"title": "翻译确认"
|
||||||
},
|
},
|
||||||
|
"success": "翻译完成",
|
||||||
"error.failed": "翻译失败",
|
"error.failed": "翻译失败",
|
||||||
"error.not_configured": "翻译模型未配置",
|
"error.not_configured": "翻译模型未配置",
|
||||||
"history": {
|
"history": {
|
||||||
|
|||||||
@ -2017,6 +2017,7 @@
|
|||||||
},
|
},
|
||||||
"error.failed": "翻譯失敗",
|
"error.failed": "翻譯失敗",
|
||||||
"error.not_configured": "翻譯模型未設定",
|
"error.not_configured": "翻譯模型未設定",
|
||||||
|
"success": "翻譯完成",
|
||||||
"history": {
|
"history": {
|
||||||
"clear": "清空歷史",
|
"clear": "清空歷史",
|
||||||
"clear_description": "清空歷史將刪除所有翻譯歷史記錄,是否繼續?",
|
"clear_description": "清空歷史將刪除所有翻譯歷史記錄,是否繼續?",
|
||||||
|
|||||||
@ -40,6 +40,7 @@ export interface RuntimeState {
|
|||||||
searching: boolean
|
searching: boolean
|
||||||
filesPath: string
|
filesPath: string
|
||||||
resourcesPath: string
|
resourcesPath: string
|
||||||
|
activeRoute: string
|
||||||
update: UpdateState
|
update: UpdateState
|
||||||
export: ExportState
|
export: ExportState
|
||||||
chat: ChatState
|
chat: ChatState
|
||||||
@ -60,6 +61,7 @@ const initialState: RuntimeState = {
|
|||||||
searching: false,
|
searching: false,
|
||||||
filesPath: '',
|
filesPath: '',
|
||||||
resourcesPath: '',
|
resourcesPath: '',
|
||||||
|
activeRoute: '/',
|
||||||
update: {
|
update: {
|
||||||
info: null,
|
info: null,
|
||||||
checking: false,
|
checking: false,
|
||||||
@ -114,6 +116,9 @@ const runtimeSlice = createSlice({
|
|||||||
setResourcesPath: (state, action: PayloadAction<string>) => {
|
setResourcesPath: (state, action: PayloadAction<string>) => {
|
||||||
state.resourcesPath = action.payload
|
state.resourcesPath = action.payload
|
||||||
},
|
},
|
||||||
|
setActiveRoute: (state, action: PayloadAction<string>) => {
|
||||||
|
state.activeRoute = action.payload
|
||||||
|
},
|
||||||
setUpdateState: (state, action: PayloadAction<Partial<UpdateState>>) => {
|
setUpdateState: (state, action: PayloadAction<Partial<UpdateState>>) => {
|
||||||
state.update = { ...state.update, ...action.payload }
|
state.update = { ...state.update, ...action.payload }
|
||||||
},
|
},
|
||||||
@ -163,6 +168,7 @@ export const {
|
|||||||
setSearching,
|
setSearching,
|
||||||
setFilesPath,
|
setFilesPath,
|
||||||
setResourcesPath,
|
setResourcesPath,
|
||||||
|
setActiveRoute,
|
||||||
setUpdateState,
|
setUpdateState,
|
||||||
setExportState,
|
setExportState,
|
||||||
// Chat related actions
|
// Chat related actions
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user