feat(i18n): static type on i18n (#2225)

This commit is contained in:
Himself65
2023-05-04 00:35:09 -05:00
committed by GitHub
parent 66c3b09c67
commit 3d43e61087
80 changed files with 585 additions and 444 deletions
@@ -1,5 +1,5 @@
import { initPage } from '@affine/env/blocksuite';
import { useTranslation } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { PageBlockModel } from '@blocksuite/blocks';
import { PlusIcon } from '@blocksuite/icons';
import { assertEquals, nanoid } from '@blocksuite/store';
@@ -27,7 +27,7 @@ export const Footer: React.FC<FooterProps> = ({
router,
}) => {
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const { t } = useTranslation();
const t = useAFFiNEI18N();
const { jumpToPage } = useRouterHelper(router);
const MAX_QUERY_SHOW_LENGTH = 20;
const normalizedQuery =
@@ -60,9 +60,9 @@ export const Footer: React.FC<FooterProps> = ({
<StyledModalFooterContent>
<PlusIcon />
{query ? (
<span>{t('New Keyword Page', { query: normalizedQuery })}</span>
<span>{t['New Keyword Page']({ query: normalizedQuery })}</span>
) : (
<span>{t('New Page')}</span>
<span>{t['New Page']()}</span>
)}
</StyledModalFooterContent>
</Command.Item>
@@ -1,4 +1,4 @@
import { useTranslation } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { Command } from 'cmdk';
@@ -41,7 +41,7 @@ export const PublishedResults: FC<PublishedResultsProps> = ({
// router.push('/404');
// });
// }, [router, dataCenter, setPublishWorkspaceName]);
const { t } = useTranslation();
const t = useAFFiNEI18N();
useEffect(() => {
setResults(blockSuiteWorkspace.search(query));
//Save the Map<BlockId, PageId> obtained from the search as state
@@ -57,7 +57,7 @@ export const PublishedResults: FC<PublishedResultsProps> = ({
{query ? (
resultsPageMeta.length ? (
<Command.Group
heading={t('Find results', { number: resultsPageMeta.length })}
heading={t['Find results']({ number: `${resultsPageMeta.length}` })}
>
{resultsPageMeta.map(result => {
return (
@@ -85,7 +85,7 @@ export const PublishedResults: FC<PublishedResultsProps> = ({
</Command.Group>
) : (
<StyledNotFound>
<span>{t('Find 0 result')}</span>
<span>{t['Find 0 result']()}</span>
<Image
src="/imgs/no-result.svg"
alt="no result"
@@ -1,5 +1,5 @@
import { UNTITLED_WORKSPACE_NAME } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
import { assertExists } from '@blocksuite/store';
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
@@ -36,7 +36,7 @@ export const Results: FC<ResultsProps> = ({
const List = useSwitchToConfig(blockSuiteWorkspace.id);
const recentlyViewed = useRecentlyViewed();
const { t } = useTranslation();
const t = useAFFiNEI18N();
const { jumpToPage } = useRouterHelper(router);
const results = blockSuiteWorkspace.search(query);
@@ -61,7 +61,7 @@ export const Results: FC<ResultsProps> = ({
return (
<>
{recentlyViewedItem.length > 0 && (
<Command.Group heading={t('Recent')}>
<Command.Group heading={t['Recent']()}>
{recentlyViewedItem.map(recent => {
const page = pageList.find(page => recent.id === page.id);
assertExists(page);
@@ -87,7 +87,7 @@ export const Results: FC<ResultsProps> = ({
})}
</Command.Group>
)}
<Command.Group heading={t('Jump to')}>
<Command.Group heading={t['Jump to']()}>
{List.map(link => {
return (
<Command.Item
@@ -112,7 +112,7 @@ export const Results: FC<ResultsProps> = ({
if (!resultsPageMeta.length) {
return (
<StyledNotFound>
<span>{t('Find 0 result')}</span>
<span>{t['Find 0 result']()}</span>
<Image
src="/imgs/no-result.svg"
alt="no result"
@@ -124,7 +124,7 @@ export const Results: FC<ResultsProps> = ({
}
return (
<Command.Group
heading={t('Find results', { number: resultsPageMeta.length })}
heading={t['Find results']({ number: `${resultsPageMeta.length}` })}
>
{resultsPageMeta.map(result => {
return (
@@ -1,4 +1,4 @@
import { useTranslation } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import {
DeleteTemporarilyIcon,
FavoriteIcon,
@@ -16,26 +16,26 @@ export const useSwitchToConfig = (
href: string;
icon: FC<SVGProps<SVGSVGElement>>;
}[] => {
const { t } = useTranslation();
const t = useAFFiNEI18N();
return useMemo(
() => [
{
title: t('All pages'),
title: t['All pages'](),
href: pathGenerator.all(workspaceId),
icon: FolderIcon,
},
{
title: t('Favorites'),
title: t['Favorites'](),
href: pathGenerator.favorite(workspaceId),
icon: FavoriteIcon,
},
{
title: t('Workspace Settings'),
title: t['Workspace Settings'](),
href: pathGenerator.setting(workspaceId),
icon: SettingsIcon,
},
{
title: t('Trash'),
title: t['Trash'](),
href: pathGenerator.trash(workspaceId),
icon: DeleteTemporarilyIcon,
},
@@ -1,6 +1,6 @@
import { Modal, ModalWrapper } from '@affine/component';
import { getEnvironment } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { Command } from 'cmdk';
import type { NextRouter } from 'next/router';
import type React from 'react';
@@ -45,7 +45,7 @@ export const QuickSearchModal: React.FC<QuickSearchModalProps> = ({
router,
blockSuiteWorkspace,
}) => {
const { t } = useTranslation();
const t = useAFFiNEI18N();
const inputRef = useRef<HTMLInputElement>(null);
const [loading, startTransition] = useTransition();
const [query, _setQuery] = useState('');
@@ -145,10 +145,10 @@ export const QuickSearchModal: React.FC<QuickSearchModalProps> = ({
}}
placeholder={
isPublicWorkspace
? t('Quick search placeholder2', {
? t['Quick search placeholder2']({
workspace: publishWorkspaceName,
})
: t('Quick search placeholder')
: t['Quick search placeholder']()
}
/>
<StyledShortcut>{isMac() ? '⌘ + K' : 'Ctrl + K'}</StyledShortcut>
@@ -1,5 +1,5 @@
import { IconButton, Tooltip, TreeView } from '@affine/component';
import { useTranslation } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import {
ArrowRightSmallIcon,
CollapseIcon,
@@ -35,7 +35,7 @@ export const NavigationPath = ({
}) => {
const metas = useBlockSuitePageMeta(blockSuiteWorkspace);
const router = useRouter();
const { t } = useTranslation();
const t = useAFFiNEI18N();
const [openExtend, setOpenExtend] = useState(false);
const pageId = propsPageId ?? router.query.pageId;
@@ -59,7 +59,7 @@ export const NavigationPath = ({
<>
<StyledNavigationPathContainer data-testid="navigation-path">
{openExtend ? (
<span>{t('Navigation Path')}</span>
<span>{t['Navigation Path']()}</span>
) : (
pathData.path.map((meta, index) => {
const isLast = index === pathData.path.length - 1;
@@ -96,7 +96,9 @@ export const NavigationPath = ({
)}
<Tooltip
content={
openExtend ? t('Back to Quick Search') : t('View Navigation Path')
openExtend
? t['Back to Quick Search']()
: t['View Navigation Path']()
}
placement="top"
disablePortal={true}