From 346484ed4452c5f4e0ed3cd301d8b8ff6c519691 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 18 Apr 2023 13:34:21 +0800 Subject: [PATCH] chore: add translation (#2001) --- .../src/components/pure/help-island/index.tsx | 2 +- apps/web/src/layouts/workspace-layout.tsx | 22 +++++++++++++------ apps/web/src/pages/index.tsx | 6 +++-- .../workspace/[workspaceId]/[pageId].tsx | 9 +++++--- packages/i18n/src/resources/en.json | 9 +++++++- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/apps/web/src/components/pure/help-island/index.tsx b/apps/web/src/components/pure/help-island/index.tsx index cddb89265d..51fb0ebca5 100644 --- a/apps/web/src/components/pure/help-island/index.tsx +++ b/apps/web/src/components/pure/help-island/index.tsx @@ -58,7 +58,7 @@ export const HelpIsland = ({ style={{ height: spread ? `${showList.length * 44}px` : 0 }} > {showList.includes('whatNew') && ( - + { diff --git a/apps/web/src/layouts/workspace-layout.tsx b/apps/web/src/layouts/workspace-layout.tsx index c9364f0720..6fb1d58e59 100644 --- a/apps/web/src/layouts/workspace-layout.tsx +++ b/apps/web/src/layouts/workspace-layout.tsx @@ -153,21 +153,22 @@ export const CurrentWorkspaceContext = ({ useRouterWithWorkspaceIdDefense(router); const metadata = useAtomValue(rootWorkspacesMetadataAtom); const exist = metadata.find(m => m.id === workspaceId); + const { t } = useTranslation(); if (!router.isReady) { - return ; + return ; } if (!workspaceId) { - return ; + return ; } if (!exist) { - return ; + return ; } return <>{children}; }; export const WorkspaceLayout: FC = function WorkspacesSuspense({ children }) { - const { i18n } = useTranslation(); + const { i18n, t } = useTranslation(); useEffect(() => { document.documentElement.lang = i18n.language; // todo(himself65): this is a hack, we should use a better way to set the language @@ -236,7 +237,9 @@ export const WorkspaceLayout: FC = - }> + } + > {children} @@ -251,6 +254,7 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { const router = useRouter(); const { jumpToPage } = useRouterHelper(router); const [isLoading, setIsLoading] = useState(true); + const { t } = useTranslation(); useEffect(() => { logger.info('currentWorkspace: ', currentWorkspace); @@ -437,8 +441,12 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { - }> - {isLoading ? : children} + }> + {isLoading ? ( + + ) : ( + children + )} {/* fixme(himself65): remove this */} diff --git a/apps/web/src/pages/index.tsx b/apps/web/src/pages/index.tsx index 01977d62d7..f5490b54d7 100644 --- a/apps/web/src/pages/index.tsx +++ b/apps/web/src/pages/index.tsx @@ -1,7 +1,8 @@ import { DebugLogger } from '@affine/debug'; +import { useTranslation } from '@affine/i18n'; import type { NextPage } from 'next'; import { useRouter } from 'next/router'; -import React, { Suspense, useEffect } from 'react'; +import { Suspense, useEffect } from 'react'; import { PageLoading } from '../components/pure/loading'; import { useLastWorkspaceId } from '../hooks/affine/use-last-leave-workspace-id'; @@ -62,8 +63,9 @@ const IndexPageInner = () => { }; const IndexPage: NextPage = () => { + const { t } = useTranslation(); return ( - }> + }> ); diff --git a/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx b/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx index fb74348073..afe722d277 100644 --- a/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx +++ b/apps/web/src/pages/workspace/[workspaceId]/[pageId].tsx @@ -1,3 +1,4 @@ +import { useTranslation } from '@affine/i18n'; import { rootCurrentPageIdAtom } from '@affine/workspace/atom'; import { WorkspaceFlavour } from '@affine/workspace/type'; import { assertExists } from '@blocksuite/store'; @@ -40,6 +41,7 @@ const WorkspaceDetail: React.FC = () => { const { openPage } = useRouterHelper(router); const currentPageId = useAtomValue(rootCurrentPageIdAtom); const [currentWorkspace] = useCurrentWorkspace(); + const { t } = useTranslation(); assertExists(currentWorkspace); const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace; const { setPageMeta, getPageMeta } = usePageMetaHelper(blockSuiteWorkspace); @@ -84,7 +86,7 @@ const WorkspaceDetail: React.FC = () => { } }, [currentWorkspace]); if (!currentPageId) { - return ; + return ; } if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) { const PageDetail = WorkspacePlugins[currentWorkspace.flavour].UI.PageDetail; @@ -110,15 +112,16 @@ const WorkspaceDetailPage: NextPageWithLayout = () => { const router = useRouter(); const currentWorkspace = useAtomValue(rootCurrentWorkspaceAtom); const currentPageId = useAtomValue(rootCurrentPageIdAtom); + const { t } = useTranslation(); useRouterAndWorkspaceWithPageIdDefense(router); const page = useBlockSuiteWorkspacePage( currentWorkspace.blockSuiteWorkspace, currentPageId ); if (!router.isReady) { - return ; + return ; } else if (!currentPageId || !page) { - return ; + return ; } return ; }; diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 286036d9aa..a885ff99ef 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -219,5 +219,12 @@ "Shared Pages In Public Workspace Description": "The entire Workspace is published on the web and can be edited via <1>Workspace Settings.", "Open Workspace Settings": "Open Workspace Settings", "Share Menu Public Workspace Description1": "Invite others to join the Workspace or publish it to web.", - "Share Menu Public Workspace Description2": "Current workspace has been published to the web as a public workspace." + "Share Menu Public Workspace Description2": "Current workspace has been published to the web as a public workspace.", + "Router is Loading": "Router is Loading", + "Finding Workspace ID": "Finding Workspace ID", + "Workspace Not Found": "Workspace Not Found", + "Finding Current Workspace": "Finding Current Workspace", + "Page is Loading": "Page is Loading", + "Loading All Workspaces": "Loading All Workspaces", + "Loading Page": "Loading Page" }