From 8f6bea490f11be041e5f48d883891bd44583eb58 Mon Sep 17 00:00:00 2001 From: icarus Date: Mon, 7 Jul 2025 15:55:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=BF=BB=E8=AF=91):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E6=88=90=E5=8A=9F=E6=8F=90=E9=86=92=E5=B9=B6?= =?UTF-8?q?=E8=B7=9F=E8=B8=AA=E5=BD=93=E5=89=8D=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在翻译完成后添加成功提示,但仅在非翻译页面显示 添加activeRoute状态以跟踪当前路由路径 --- src/renderer/src/components/app/Sidebar.tsx | 4 ++++ src/renderer/src/hooks/useTranslate.ts | 8 ++++++++ src/renderer/src/i18n/locales/en-us.json | 1 + src/renderer/src/i18n/locales/ja-jp.json | 1 + src/renderer/src/i18n/locales/ru-ru.json | 1 + src/renderer/src/i18n/locales/zh-cn.json | 1 + src/renderer/src/i18n/locales/zh-tw.json | 1 + src/renderer/src/store/runtime.ts | 6 ++++++ 8 files changed, 23 insertions(+) diff --git a/src/renderer/src/components/app/Sidebar.tsx b/src/renderer/src/components/app/Sidebar.tsx index 5e4365c3c9..853cf364fa 100644 --- a/src/renderer/src/components/app/Sidebar.tsx +++ b/src/renderer/src/components/app/Sidebar.tsx @@ -10,6 +10,8 @@ import useNavBackgroundColor from '@renderer/hooks/useNavBackgroundColor' import { modelGenerating, useRuntime } from '@renderer/hooks/useRuntime' import { useSettings } from '@renderer/hooks/useSettings' import i18n from '@renderer/i18n' +import { useAppDispatch } from '@renderer/store' +import { setActiveRoute } from '@renderer/store/runtime' import { ThemeMode } from '@renderer/types' import { isEmoji } from '@renderer/utils' import type { MenuProps } from 'antd' @@ -144,6 +146,7 @@ const MainMenus: FC = () => { const { minappShow } = useRuntime() const navigate = useNavigate() const { theme } = useTheme() + const dispatch = useAppDispatch() const isRoute = (path: string): string => (pathname === path && !minappShow ? 'active' : '') const isRoutes = (path: string): string => (pathname.startsWith(path) && !minappShow ? 'active' : '') @@ -179,6 +182,7 @@ const MainMenus: FC = () => { hideMinappPopup() await modelGenerating() navigate(path) + dispatch(setActiveRoute(path)) }}> {iconMap[icon]} diff --git a/src/renderer/src/hooks/useTranslate.ts b/src/renderer/src/hooks/useTranslate.ts index b414f77be3..f3b6b9634a 100644 --- a/src/renderer/src/hooks/useTranslate.ts +++ b/src/renderer/src/hooks/useTranslate.ts @@ -7,6 +7,7 @@ import { } from '@renderer/store/translate' import { Assistant, TranslateHistory } from '@renderer/types' import { uuid } from '@renderer/utils' +import { t } from 'i18next' export default function useTranslate() { const translatedContent = useAppSelector((state) => state.translate.translatedContent) @@ -40,6 +41,13 @@ export default function useTranslate() { await saveTranslateHistory(text, translatedContent, actualSourceLanguage, actualTargetLanguage) 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 ( diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index d0574c2028..2ed00d77cc 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -2018,6 +2018,7 @@ }, "error.failed": "Translation failed", "error.not_configured": "Translation model is not configured", + "success": "Translation completed", "history": { "clear": "Clear History", "clear_description": "Clear history will delete all translation history, continue?", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 8f9d621b89..b008b019f7 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -2017,6 +2017,7 @@ }, "error.failed": "翻訳に失敗しました", "error.not_configured": "翻訳モデルが設定されていません", + "success": "翻訳が完了しました。", "history": { "clear": "履歴をクリア", "clear_description": "履歴をクリアすると、すべての翻訳履歴が削除されます。続行しますか?", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index 902e2b51df..d78f6a3a26 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -2017,6 +2017,7 @@ }, "error.failed": "Перевод не удалось", "error.not_configured": "Модель перевода не настроена", + "success": "Перевод завершен", "history": { "clear": "Очистить историю", "clear_description": "Очистка истории удалит все записи переводов. Продолжить?", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 2d603470e0..9b03ea98fa 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -2015,6 +2015,7 @@ "content": "翻译后将覆盖原文,是否继续?", "title": "翻译确认" }, + "success": "翻译完成", "error.failed": "翻译失败", "error.not_configured": "翻译模型未配置", "history": { diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 0b8e0b7e2d..14801e944c 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -2017,6 +2017,7 @@ }, "error.failed": "翻譯失敗", "error.not_configured": "翻譯模型未設定", + "success": "翻譯完成", "history": { "clear": "清空歷史", "clear_description": "清空歷史將刪除所有翻譯歷史記錄,是否繼續?", diff --git a/src/renderer/src/store/runtime.ts b/src/renderer/src/store/runtime.ts index d1e3752d10..c091369f28 100644 --- a/src/renderer/src/store/runtime.ts +++ b/src/renderer/src/store/runtime.ts @@ -40,6 +40,7 @@ export interface RuntimeState { searching: boolean filesPath: string resourcesPath: string + activeRoute: string update: UpdateState export: ExportState chat: ChatState @@ -60,6 +61,7 @@ const initialState: RuntimeState = { searching: false, filesPath: '', resourcesPath: '', + activeRoute: '/', update: { info: null, checking: false, @@ -114,6 +116,9 @@ const runtimeSlice = createSlice({ setResourcesPath: (state, action: PayloadAction) => { state.resourcesPath = action.payload }, + setActiveRoute: (state, action: PayloadAction) => { + state.activeRoute = action.payload + }, setUpdateState: (state, action: PayloadAction>) => { state.update = { ...state.update, ...action.payload } }, @@ -163,6 +168,7 @@ export const { setSearching, setFilesPath, setResourcesPath, + setActiveRoute, setUpdateState, setExportState, // Chat related actions