From 66782ef19c3d0dd26670e6d1b6f567d80521f6b9 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 25 May 2023 22:13:43 +0800 Subject: [PATCH] chore: title support i18n (#212) --- web/app/(commonLayout)/apps/Apps.tsx | 3 +++ web/app/(commonLayout)/apps/page.tsx | 4 ---- web/app/components/explore/index.tsx | 3 +++ web/i18n/lang/app.en.ts | 1 + web/i18n/lang/app.zh.ts | 1 + web/i18n/lang/explore.en.ts | 1 + web/i18n/lang/explore.zh.ts | 1 + 7 files changed, 10 insertions(+), 4 deletions(-) diff --git a/web/app/(commonLayout)/apps/Apps.tsx b/web/app/(commonLayout)/apps/Apps.tsx index 13f983acec..f0edc3ac99 100644 --- a/web/app/(commonLayout)/apps/Apps.tsx +++ b/web/app/(commonLayout)/apps/Apps.tsx @@ -9,6 +9,7 @@ import { AppListResponse } from '@/models/app' import { fetchAppList } from '@/service/apps' import { useSelector } from '@/context/app-context' import { NEED_REFRESH_APP_LIST_KEY } from '@/config' +import { useTranslation } from 'react-i18next' const getKey = (pageIndex: number, previousPageData: AppListResponse) => { if (!pageIndex || previousPageData.has_more) @@ -17,12 +18,14 @@ const getKey = (pageIndex: number, previousPageData: AppListResponse) => { } const Apps = () => { + const { t } = useTranslation() const { data, isLoading, setSize, mutate } = useSWRInfinite(getKey, fetchAppList, { revalidateFirstPage: false }) const loadingStateRef = useRef(false) const pageContainerRef = useSelector(state => state.pageContainerRef) const anchorRef = useRef(null) useEffect(() => { + document.title = `${t('app.title')} - Dify`; if(localStorage.getItem(NEED_REFRESH_APP_LIST_KEY) === '1') { localStorage.removeItem(NEED_REFRESH_APP_LIST_KEY) mutate() diff --git a/web/app/(commonLayout)/apps/page.tsx b/web/app/(commonLayout)/apps/page.tsx index bc5a0b583f..bc3c8553ea 100644 --- a/web/app/(commonLayout)/apps/page.tsx +++ b/web/app/(commonLayout)/apps/page.tsx @@ -29,8 +29,4 @@ const AppList = async () => { ) } -export const metadata = { - title: 'Apps - Dify', -} - export default AppList diff --git a/web/app/components/explore/index.tsx b/web/app/components/explore/index.tsx index 54222293db..03486ececf 100644 --- a/web/app/components/explore/index.tsx +++ b/web/app/components/explore/index.tsx @@ -5,6 +5,7 @@ import Sidebar from '@/app/components/explore/sidebar' import { useAppContext } from '@/context/app-context' import { fetchMembers } from '@/service/common' import { InstalledApp } from '@/models/explore' +import { useTranslation } from 'react-i18next' export interface IExploreProps { children: React.ReactNode @@ -13,12 +14,14 @@ export interface IExploreProps { const Explore: FC = ({ children }) => { + const { t } = useTranslation() const [controlUpdateInstalledApps, setControlUpdateInstalledApps] = useState(0) const { userProfile } = useAppContext() const [hasEditPermission, setHasEditPermission] = useState(false) const [installedApps, setInstalledApps] = useState([]) useEffect(() => { + document.title = `${t('explore.title')} - Dify`; (async () => { const { accounts } = await fetchMembers({ url: '/workspaces/current/members', params: {}}) if(!accounts) return diff --git a/web/i18n/lang/app.en.ts b/web/i18n/lang/app.en.ts index aea93eb168..cfa99606dd 100644 --- a/web/i18n/lang/app.en.ts +++ b/web/i18n/lang/app.en.ts @@ -1,4 +1,5 @@ const translation = { + title: 'Apps', createApp: 'Create new App', modes: { completion: 'Text Generator', diff --git a/web/i18n/lang/app.zh.ts b/web/i18n/lang/app.zh.ts index 467d85feeb..10eb8aab20 100644 --- a/web/i18n/lang/app.zh.ts +++ b/web/i18n/lang/app.zh.ts @@ -1,4 +1,5 @@ const translation = { + title: '应用', createApp: '创建应用', modes: { completion: '文本生成型', diff --git a/web/i18n/lang/explore.en.ts b/web/i18n/lang/explore.en.ts index 2f1d16c604..572516a599 100644 --- a/web/i18n/lang/explore.en.ts +++ b/web/i18n/lang/explore.en.ts @@ -1,4 +1,5 @@ const translation = { + title: 'My Apps', sidebar: { discovery: 'Discovery', workspace: 'Workspace', diff --git a/web/i18n/lang/explore.zh.ts b/web/i18n/lang/explore.zh.ts index 0b5c5e55e0..9311fcb9ff 100644 --- a/web/i18n/lang/explore.zh.ts +++ b/web/i18n/lang/explore.zh.ts @@ -1,4 +1,5 @@ const translation = { + title: '我的应用', sidebar: { discovery: '发现', workspace: '工作区',