* adapt not input type

* adapt not input type

* file i18n

* publish i18n

* translate

* i18n
This commit is contained in:
Archer
2024-05-11 00:21:01 +08:00
committed by GitHub
parent 8cf643d972
commit ee8cb0915e
28 changed files with 1515 additions and 1614 deletions

View File

@@ -1,7 +1,7 @@
import React, { useMemo, useState } from 'react';
import { type ChatHistoryItemResType } from '@fastgpt/global/core/chat/type.d';
import { DispatchNodeResponseType } from '@fastgpt/global/core/workflow/runtime/type.d';
import { Flex, BoxProps, useDisclosure, useTheme, Box } from '@chakra-ui/react';
import { Flex, useDisclosure, useTheme, Box } from '@chakra-ui/react';
import { useTranslation } from 'next-i18next';
import { useSystemStore } from '@/web/common/system/useSystemStore';
import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';

View File

@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { Box, BoxProps, Image } from '@chakra-ui/react';
import { Box, BoxProps } from '@chakra-ui/react';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { getErrText } from '@fastgpt/global/common/error/utils';
import MyTooltip from '@/components/MyTooltip';
@@ -8,6 +8,7 @@ import { getFileAndOpen } from '@/web/core/dataset/utils';
import { useSystemStore } from '@/web/common/system/useSystemStore';
import { getSourceNameIcon } from '@fastgpt/global/core/dataset/utils';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { useI18n } from '@/web/context/I18n';
type Props = BoxProps & {
sourceName?: string;
@@ -17,6 +18,7 @@ type Props = BoxProps & {
const RawSourceBox = ({ sourceId, sourceName = '', canView = true, ...props }: Props) => {
const { t } = useTranslation();
const { fileT } = useI18n();
const { toast } = useToast();
const { setLoading } = useSystemStore();
@@ -25,10 +27,7 @@ const RawSourceBox = ({ sourceId, sourceName = '', canView = true, ...props }: P
const icon = useMemo(() => getSourceNameIcon({ sourceId, sourceName }), [sourceId, sourceName]);
return (
<MyTooltip
label={canPreview ? t('file.Click to view file') || '' : ''}
shouldWrapChildren={false}
>
<MyTooltip label={canPreview ? fileT('Click to view file') : ''} shouldWrapChildren={false}>
<Box
color={'myGray.900'}
fontWeight={'medium'}
@@ -44,7 +43,7 @@ const RawSourceBox = ({ sourceId, sourceName = '', canView = true, ...props }: P
await getFileAndOpen(sourceId as string);
} catch (error) {
toast({
title: t(getErrText(error, 'error.fileNotFound')),
title: getErrText(error, t('error.fileNotFound')),
status: 'error'
});
}

View File

@@ -43,6 +43,7 @@ import MyTooltip from '@/components/MyTooltip';
import { getDocPath } from '@/web/common/system/doc';
import MyMenu from '@fastgpt/web/components/common/MyMenu';
import { useConfirm } from '@fastgpt/web/hooks/useConfirm';
import { useI18n } from '@/web/context/I18n';
type EditProps = EditApiKeyProps & { _id?: string };
const defaultEditData: EditProps = {
@@ -295,6 +296,7 @@ function EditKeyModal({
onEdit: () => void;
}) {
const { t } = useTranslation();
const { publishT } = useI18n();
const isEdit = useMemo(() => !!defaultData._id, [defaultData]);
const { feConfigs } = useSystemStore();
@@ -324,13 +326,13 @@ function EditKeyModal({
<MyModal
isOpen={true}
iconSrc="/imgs/modal/key.svg"
title={isEdit ? t('outlink.Edit API Key') : t('outlink.Create API Key')}
title={isEdit ? publishT('Edit API Key') : publishT('Create API Key')}
>
<ModalBody>
<Flex alignItems={'center'}>
<Box flex={'0 0 90px'}>{t('Name')}:</Box>
<Input
placeholder={t('openapi.key alias') || 'key alias'}
placeholder={publishT('key alias') || 'key alias'}
maxLength={20}
{...register('name', {
required: t('common.Name is empty') || 'Name is empty'

View File

@@ -1,10 +1,11 @@
import React from 'react';
import { useTranslation } from 'next-i18next';
import ApiKeyTable from '@/components/support/apikey/Table';
import { useI18n } from '@/web/context/I18n';
const ApiKey = () => {
const { t } = useTranslation();
return <ApiKeyTable tips={t('openapi.key tips')}></ApiKeyTable>;
const { publishT } = useI18n();
return <ApiKeyTable tips={publishT('key tips')}></ApiKeyTable>;
};
export default ApiKey;

View File

@@ -190,7 +190,7 @@ export async function getServerSideProps(content: any) {
return {
props: {
currentTab: content?.query?.currentTab || TabEnum.info,
...(await serviceSideProps(content))
...(await serviceSideProps(content, ['publish']))
}
};
}

View File

@@ -2,12 +2,13 @@ import React, { useEffect, useState } from 'react';
import ApiKeyTable from '@/components/support/apikey/Table';
import { useTranslation } from 'next-i18next';
import { Box } from '@chakra-ui/react';
import { useI18n } from '@/web/context/I18n';
const API = ({ appId }: { appId: string }) => {
const { t } = useTranslation();
const { publishT } = useI18n();
return (
<Box pt={3}>
<ApiKeyTable tips={t('openapi.app key tips')} appId={appId} />
<ApiKeyTable tips={publishT('app key tips')} appId={appId} />
</Box>
);
};

View File

@@ -10,6 +10,7 @@ import { useForm } from 'react-hook-form';
import { useRequest } from '@/web/common/hooks/useRequest';
import dayjs from 'dayjs';
import { createShareChat, updateShareChat } from '@/web/support/outLink/api';
import { useI18n } from '@/web/context/I18n';
const FeiShuEditModal = ({
appId,
@@ -25,6 +26,7 @@ const FeiShuEditModal = ({
onEdit: () => void;
}) => {
const { t } = useTranslation();
const { publishT } = useI18n();
const {
register,
setValue,
@@ -58,13 +60,13 @@ const FeiShuEditModal = ({
<MyModal
isOpen={true}
iconSrc="/imgs/modal/shareFill.svg"
title={isEdit ? t('outlink.Edit Link') : t('outlink.Create Link')}
title={isEdit ? publishT('Edit Link') : publishT('Create Link')}
>
<ModalBody>
<Flex alignItems={'center'}>
<Box flex={'0 0 90px'}>{t('Name')}</Box>
<Input
placeholder={t('outlink.Feishu name') || 'Link Name'} // TODO: i18n
placeholder={publishT('Feishu name') || 'Link Name'} // TODO: i18n
maxLength={20}
{...register('name', {
required: t('common.Name is empty') || 'Name is empty'
@@ -74,7 +76,7 @@ const FeiShuEditModal = ({
<Flex alignItems={'center'} mt={4}>
<Flex flex={'0 0 90px'} alignItems={'center'}>
QPM
<MyTooltip label={t('outlink.QPM Tips' || '')}>
<MyTooltip label={publishT('QPM Tips' || '')}>
<QuestionOutlineIcon ml={1} />
</MyTooltip>
</Flex>
@@ -84,7 +86,7 @@ const FeiShuEditModal = ({
min: 0,
max: 1000,
valueAsNumber: true,
required: t('outlink.QPM is empty') || ''
required: publishT('QPM is empty') || ''
})}
/>
</Flex>
@@ -126,10 +128,10 @@ const FeiShuEditModal = ({
{/* TODO: i18n */}
</Flex>
<Input
placeholder={t('outlink.Default Response') || 'Link Name'}
placeholder={publishT('Default Response') || 'Link Name'}
maxLength={20}
{...register('defaultResponse', {
required: t('common.default Response is empty') || 'Name is empty'
required: true
})}
/>
</Flex>
@@ -139,10 +141,10 @@ const FeiShuEditModal = ({
{/* TODO: i18n */}
</Flex>
<Input
placeholder={t('outlink.Default Response') || 'Link Name'}
placeholder={publishT('Default Response') || 'Link Name'}
maxLength={20}
{...register('immediateResponse', {
required: t('common.default Response is empty') || 'Name is empty'
required: true
})}
/>
</Flex>
@@ -152,14 +154,14 @@ const FeiShuEditModal = ({
placeholder={t('core.module.http.appId') || 'Link Name'}
// maxLength={20}
{...register('app.appId', {
required: t('common.Name is empty') || 'Name is empty'
required: true
})}
/>
</Flex>
<Flex alignItems={'center'} mt={4}>
<Box flex={'0 0 90px'}>{t('core.module.http.AppSecret')}</Box>
<Input
placeholder={t('outlink.AppSecret') || 'Link Name'}
placeholder={'App Secret'}
// maxLength={20}
{...register('app.appSecret', {
required: t('common.Name is empty') || 'Name is empty'

View File

@@ -44,6 +44,7 @@ import { getDocPath } from '@/web/common/system/doc';
import dynamic from 'next/dynamic';
import MyMenu from '@fastgpt/web/components/common/MyMenu';
import { useConfirm } from '@fastgpt/web/hooks/useConfirm';
import { useI18n } from '@/web/context/I18n';
const SelectUsingWayModal = dynamic(() => import('./SelectUsingWayModal'));
@@ -261,6 +262,7 @@ function EditLinkModal({
}) {
const { feConfigs } = useSystemStore();
const { t } = useTranslation();
const { publishT } = useI18n();
const {
register,
setValue,
@@ -293,13 +295,13 @@ function EditLinkModal({
<MyModal
isOpen={true}
iconSrc="/imgs/modal/shareFill.svg"
title={isEdit ? t('outlink.Edit Link') : t('outlink.Create Link')}
title={isEdit ? publishT('Edit Link') : publishT('Create Link')}
>
<ModalBody>
<Flex alignItems={'center'}>
<Box flex={'0 0 90px'}>{t('Name')}</Box>
<Input
placeholder={t('outlink.Link Name') || 'Link Name'}
placeholder={publishT('Link Name')}
maxLength={20}
{...register('name', {
required: t('common.Name is empty') || 'Name is empty'
@@ -327,7 +329,7 @@ function EditLinkModal({
<Flex alignItems={'center'} mt={4}>
<Flex flex={'0 0 90px'} alignItems={'center'}>
QPM
<MyTooltip label={t('outlink.QPM Tips' || '')}>
<MyTooltip label={publishT('QPM Tips' || '')}>
<QuestionOutlineIcon ml={1} />
</MyTooltip>
</Flex>
@@ -337,7 +339,7 @@ function EditLinkModal({
min: 0,
max: 1000,
valueAsNumber: true,
required: t('outlink.QPM is empty') || ''
required: publishT('QPM is empty') || ''
})}
/>
</Flex>
@@ -360,13 +362,13 @@ function EditLinkModal({
<Flex alignItems={'center'} mt={4}>
<Flex flex={'0 0 90px'} alignItems={'center'}>
{t('outlink.token auth')}
<MyTooltip label={t('outlink.token auth Tips') || ''}>
{publishT('token auth')}
<MyTooltip label={publishT('token auth Tips') || ''}>
<QuestionOutlineIcon ml={1} />
</MyTooltip>
</Flex>
<Input
placeholder={t('outlink.token auth Tips') || ''}
placeholder={publishT('token auth Tips') || ''}
fontSize={'sm'}
{...register('limit.hookUrl')}
/>
@@ -377,7 +379,7 @@ function EditLinkModal({
fontSize={'sm'}
color={'myGray.500'}
>
{t('outlink.token auth use cases')}
{publishT('token auth use cases')}
</Link>
</>
)}

View File

@@ -196,7 +196,7 @@ export async function getServerSideProps(context: any) {
const currentTab = context?.query?.currentTab || TabEnum.simpleEdit;
return {
props: { currentTab, ...(await serviceSideProps(context, ['app'])) }
props: { currentTab, ...(await serviceSideProps(context, ['app', 'file', 'publish'])) }
};
}

View File

@@ -371,7 +371,7 @@ export async function getServerSideProps(context: any) {
props: {
appId: context?.query?.appId || '',
chatId: context?.query?.chatId || '',
...(await serviceSideProps(context))
...(await serviceSideProps(context, ['file']))
}
};
}

View File

@@ -431,7 +431,7 @@ export async function getServerSideProps(context: any) {
appName: app?.appId?.name || '',
appAvatar: app?.appId?.avatar || '',
appIntro: app?.appId?.intro || '',
...(await serviceSideProps(context))
...(await serviceSideProps(context, ['file']))
}
};
}

View File

@@ -382,7 +382,7 @@ const OutLink = () => {
export async function getServerSideProps(context: any) {
return {
props: {
...(await serviceSideProps(context))
...(await serviceSideProps(context, ['file']))
}
};
}

View File

@@ -27,9 +27,11 @@ import {
postCreateDatasetTextCollection
} from '@/web/core/dataset/api';
import Tag from '@fastgpt/web/components/common/Tag/index';
import { useI18n } from '@/web/context/I18n';
const Upload = () => {
const { t } = useTranslation();
const { fileT } = useI18n();
const { toast } = useToast();
const router = useRouter();
const { datasetDetail } = useDatasetStore();
@@ -131,7 +133,7 @@ const Upload = () => {
)
);
},
errorToast: t('common.file.Upload failed')
errorToast: fileT('Upload failed')
});
return (

View File

@@ -13,6 +13,7 @@ import { useSystemStore } from '@/web/common/system/useSystemStore';
import { uploadFile2DB } from '@/web/common/file/controller';
import { BucketNameEnum } from '@fastgpt/global/common/file/constants';
import { ImportSourceItemType } from '@/web/core/dataset/type';
import { useI18n } from '@/web/context/I18n';
export type SelectFileItemType = {
fileId: string;
@@ -35,6 +36,8 @@ const FileSelector = ({
onFinishSelect: () => void;
} & FlexProps) => {
const { t } = useTranslation();
const { fileT } = useI18n();
const { toast } = useToast();
const { feConfigs } = useSystemStore();
@@ -129,7 +132,7 @@ const FileSelector = ({
files = files.slice(0, maxCount - selectFiles.length);
toast({
status: 'warning',
title: t('common.file.Some file count exceeds limit', { maxCount })
title: fileT('Some file count exceeds limit', { maxCount })
});
}
// size check
@@ -141,7 +144,7 @@ const FileSelector = ({
if (filterFiles.length < files.length) {
toast({
status: 'warning',
title: t('common.file.Some file size exceeds limit', { maxSize: formatFileSize(maxSize) })
title: fileT('Some file size exceeds limit', { maxSize: formatFileSize(maxSize) })
});
}
@@ -203,7 +206,7 @@ const FileSelector = ({
let isErr = files.some((item) => item.type === '');
if (isErr) {
return toast({
title: t('file.upload error description'),
title: fileT('upload error description'),
status: 'error'
});
}
@@ -262,18 +265,18 @@ const FileSelector = ({
<>
<Box fontWeight={'bold'}>
{isDragging
? t('file.Release the mouse to upload the file')
: t('common.file.Select and drag file tip')}
? fileT('Release the mouse to upload the file')
: fileT('Select and drag file tip')}
</Box>
{/* file type */}
<Box color={'myGray.500'} fontSize={'xs'}>
{t('common.file.Support file type', { fileType })}
{fileT('Support file type', { fileType })}
</Box>
<Box color={'myGray.500'} fontSize={'xs'}>
{/* max count */}
{maxCount && t('common.file.Support max count', { maxCount })}
{maxCount && fileT('Support max count', { maxCount })}
{/* max size */}
{maxSize && t('common.file.Support max size', { maxSize: formatFileSize(maxSize) })}
{maxSize && fileT('Support max size', { maxSize: formatFileSize(maxSize) })}
</Box>
<File

View File

@@ -16,6 +16,7 @@ import MyIcon from '@fastgpt/web/components/common/Icon';
import { useTranslation } from 'next-i18next';
import MyTooltip from '@/components/MyTooltip';
import dynamic from 'next/dynamic';
import { useI18n } from '@/web/context/I18n';
const PreviewRawText = dynamic(() => import('./PreviewRawText'));
@@ -29,6 +30,7 @@ export const RenderUploadFiles = ({
showPreviewContent?: boolean;
}) => {
const { t } = useTranslation();
const { fileT } = useI18n();
const [previewFile, setPreviewFile] = useState<ImportSourceItemType>();
return files.length > 0 ? (
@@ -38,13 +40,13 @@ export const RenderUploadFiles = ({
<Thead draggable={false}>
<Tr bg={'myGray.100'} mb={2}>
<Th borderLeftRadius={'md'} borderBottom={'none'} py={4}>
{t('common.file.File Name')}
{fileT('File Name')}
</Th>
<Th borderBottom={'none'} py={4}>
{t('core.dataset.import.Upload file progress')}
</Th>
<Th borderBottom={'none'} py={4}>
{t('common.file.File Size')}
{fileT('File Size')}
</Th>
<Th borderRightRadius={'md'} borderBottom={'none'} py={4}>
{t('common.Action')}

View File

@@ -295,7 +295,7 @@ export async function getServerSideProps(context: any) {
const datasetId = context?.query?.datasetId;
return {
props: { currentTab, datasetId, ...(await serviceSideProps(context)) }
props: { currentTab, datasetId, ...(await serviceSideProps(context, ['file'])) }
};
}

View File

@@ -1,12 +1,16 @@
import 'i18next';
import common from '../../i18n/en/common.json';
import dataset from '../../i18n/en/dataset.json';
import app from '../../i18n/en/app.json';
import common from '../../i18n/zh/common.json';
import dataset from '../../i18n/zh/dataset.json';
import app from '../../i18n/zh/app.json';
import file from '../../i18n/zh/file.json';
import publish from '../../i18n/zh/publish.json';
export interface I18nNamespaces {
common: typeof common;
dataset: typeof dataset;
app: typeof app;
file: typeof file;
publish: typeof publish;
}
export type I18nNsType = (keyof I18nNamespaces)[];

View File

@@ -2,6 +2,7 @@ import React, { useRef, useCallback } from 'react';
import { Box } from '@chakra-ui/react';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { useTranslation } from 'next-i18next';
import { useI18n } from '@/web/context/I18n';
export const useSelectFile = (props?: {
fileType?: string;
@@ -9,6 +10,7 @@ export const useSelectFile = (props?: {
maxCount?: number;
}) => {
const { t } = useTranslation();
const { fileT } = useI18n();
const { fileType = '*', multiple = false, maxCount = 10 } = props || {};
const { toast } = useToast();
const SelectFileDom = useRef<HTMLInputElement>(null);
@@ -30,7 +32,7 @@ export const useSelectFile = (props?: {
if (fileList.length > maxCount) {
toast({
status: 'warning',
title: t('common.file.Select file amount limit', { max: maxCount })
title: fileT('Select file amount limit', { max: maxCount })
});
fileList = fileList.slice(0, maxCount);
}
@@ -39,7 +41,7 @@ export const useSelectFile = (props?: {
/>
</Box>
),
[fileType, maxCount, multiple, t, toast]
[fileT, fileType, maxCount, multiple, toast]
);
const onOpen = useCallback((sign?: any) => {

View File

@@ -6,6 +6,8 @@ type I18nContextType = {
commonT: TFunction<['common'], undefined>;
appT: TFunction<['app'], undefined>;
datasetT: TFunction<['dataset'], undefined>;
fileT: TFunction<['file'], undefined>;
publishT: TFunction<['publish'], undefined>;
};
export const I18nContext = createContext<I18nContextType>({
@@ -17,13 +19,17 @@ const I18nContextProvider = ({ children }: { children: React.ReactNode }) => {
const { t: commonT } = useTranslation('common');
const { t: appT } = useTranslation('app');
const { t: datasetT } = useTranslation('dataset');
const { t: fileT } = useTranslation('file');
const { t: publishT } = useTranslation('publish');
return (
<I18nContext.Provider
value={{
commonT,
appT,
datasetT
datasetT,
fileT,
publishT
}}
>
{children}