I18n Translations (#2267)

* rebase

* i18n-1

* add error info i18n

* fix

* fix

* refactor: 删除error.json

* delete useI18n
This commit is contained in:
papapatrick
2024-08-05 18:42:21 +08:00
committed by GitHub
parent 025d405fe2
commit 10dcdb5491
107 changed files with 1128 additions and 416 deletions

View File

@@ -6,12 +6,13 @@ import { ChatBoxContext } from '../Provider';
import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { useTranslation } from 'next-i18next';
const isLLMNode = (item: ChatHistoryItemResType) =>
item.moduleType === FlowNodeTypeEnum.chatNode || item.moduleType === FlowNodeTypeEnum.tools;
const ContextModal = ({ onClose, dataId }: { onClose: () => void; dataId: string }) => {
const { getHistoryResponseData } = useContextSelector(ChatBoxContext, (v) => v);
const { t } = useTranslation();
const { loading: isLoading, data: contextModalData } = useRequest2(
() =>
getHistoryResponseData({ dataId }).then((res) => {
@@ -34,7 +35,7 @@ const ContextModal = ({ onClose, dataId }: { onClose: () => void; dataId: string
onClose={onClose}
isLoading={isLoading}
iconSrc="/imgs/modal/chatHistory.svg"
title={`上下文预览(${contextModalData?.length || 0}条)`}
title={t('chat:contextual_preview', { num: contextModalData?.length || 0 })}
h={['90vh', '80vh']}
minW={['90vw', '600px']}
isCentered

View File

@@ -175,28 +175,28 @@ const ResponseTags = ({
{showDetail && (
<Flex alignItems={'center'} mt={3} flexWrap={'wrap'} gap={2}>
{quoteList.length > 0 && (
<MyTooltip label="查看引用">
<MyTooltip label={t('chat:view_citations')}>
<MyTag
colorSchema="blue"
type="borderSolid"
cursor={'pointer'}
onClick={() => setQuoteModalData({ rawSearch: quoteList })}
>
{quoteList.length}
{t('chat:citations', { num: quoteList.length })}
</MyTag>
</MyTooltip>
)}
{llmModuleAccount === 1 && (
<>
{historyPreviewLength > 0 && (
<MyTooltip label={'点击查看上下文预览'}>
<MyTooltip label={t('chat:click_contextual_preview')}>
<MyTag
colorSchema="green"
cursor={'pointer'}
type="borderSolid"
onClick={onOpenContextModal}
>
{historyPreviewLength}
{t('chat:contextual', { num: historyPreviewLength })}
</MyTag>
</MyTooltip>
)}
@@ -204,12 +204,12 @@ const ResponseTags = ({
)}
{llmModuleAccount > 1 && (
<MyTag type="borderSolid" colorSchema="blue">
AI
{t('chat:multiple_AI_conversations')}
</MyTag>
)}
{isPc && runningTime > 0 && (
<MyTooltip label={'模块运行时间和'}>
<MyTooltip label={t('chat:module_runtime_and')}>
<MyTag colorSchema="purple" type="borderSolid" cursor={'default'}>
{runningTime}s
</MyTag>

View File

@@ -90,7 +90,7 @@ const SelectMarkCollection = ({
})()
)}
</Grid>
{datasets.length === 0 && <EmptyTip text={'这个目录已经没东西可选了~'}></EmptyTip>}
{datasets.length === 0 && <EmptyTip text={t('chat:empty_directory')}></EmptyTip>}
</ModalBody>
</DatasetSelectModal>
)}

View File

@@ -4,8 +4,9 @@ import { useCallback } from 'react';
import { htmlTemplate } from '@/web/core/chat/constants';
import { fileDownload } from '@/web/common/file/utils';
import { ChatItemValueTypeEnum } from '@fastgpt/global/core/chat/constants';
import { useTranslation } from 'next-i18next';
export const useChatBox = () => {
const { t } = useTranslation();
const onExportChat = useCallback(
({ type, history }: { type: ExportChatType; history: ChatItemType[] }) => {
const getHistoryHtml = () => {
@@ -74,7 +75,7 @@ ${JSON.stringify(item.tools, null, 2)}
fileDownload({
text: html,
type: 'text/html',
filename: '聊天记录.html'
filename: `${t('chat:chat_history')}.html`
});
},
pdf: () => {
@@ -84,7 +85,7 @@ ${JSON.stringify(item.tools, null, 2)}
// @ts-ignore
html2pdf(html, {
margin: 0,
filename: `聊天记录.pdf`
filename: `${t('chat:chat_history')}.pdf`
});
}
};

View File

@@ -372,7 +372,7 @@ const ChatBox = (
if (!onStartChat) return;
if (isChatting) {
toast({
title: '正在聊天中...请等待结束',
title: t('chat:is_chatting'),
status: 'warning'
});
return;
@@ -384,7 +384,7 @@ const ChatBox = (
if (!text && files.length === 0) {
toast({
title: '内容为空',
title: t('chat:content_empty'),
status: 'warning'
});
return;

View File

@@ -5,10 +5,10 @@ import { PluginRunContext } from '../context';
import Markdown from '@/components/Markdown';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import AIResponseBox from '../../../components/AIResponseBox';
import { useTranslation } from 'next-i18next';
const RenderOutput = () => {
const { histories, isChatting } = useContextSelector(PluginRunContext, (v) => v);
const { t } = useTranslation();
const pluginOutputs = useMemo(() => {
const pluginOutputs = histories?.[1]?.responseData?.find(
(item) => item.moduleType === FlowNodeTypeEnum.pluginOutput
@@ -22,7 +22,7 @@ const RenderOutput = () => {
<Box border={'base'} rounded={'md'} bg={'myGray.25'}>
<Box p={4} color={'myGray.900'}>
<Box color={'myGray.900'} fontWeight={'bold'}>
{t('chat:stream_output')}
</Box>
{histories.length > 0 && histories[1]?.value.length > 0 ? (
<Box mt={2}>
@@ -46,7 +46,7 @@ const RenderOutput = () => {
</Box>
<Box border={'base'} mt={4} rounded={'md'} bg={'myGray.25'}>
<Box p={4} color={'myGray.900'} fontWeight={'bold'}>
<Box></Box>
<Box>{t('chat:plugins_output')}</Box>
{histories.length > 0 && histories[1].responseData ? (
<Markdown source={`~~~json\n${pluginOutputs}`} />
) : null}

View File

@@ -3,14 +3,14 @@ import React from 'react';
import { useContextSelector } from 'use-context-selector';
import { PluginRunContext } from '../context';
import { Box } from '@chakra-ui/react';
import { useTranslation } from 'next-i18next';
const RenderResponseDetail = () => {
const { histories, isChatting } = useContextSelector(PluginRunContext, (v) => v);
const { t } = useTranslation();
const responseData = histories?.[1]?.responseData || [];
return isChatting ? (
<>{'进行中'}</>
<>{t('chat:in_progress')}</>
) : (
<Box flex={'1 0 0'} h={'100%'} overflow={'auto'}>
<ResponseBox useMobile={true} response={responseData} showDetail={true} />

View File

@@ -11,7 +11,7 @@ import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/c
import { generatingMessageProps } from '../type';
import { SseResponseEventEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import { getPluginRunContent } from '@fastgpt/global/core/app/plugin/utils';
import { useTranslation } from 'next-i18next';
type PluginRunContextType = PluginRunBoxProps & {
isChatting: boolean;
onSubmit: (e: FieldValues) => Promise<any>;
@@ -44,7 +44,7 @@ const PluginRunContextProvider = ({
const { toast } = useToast();
const chatController = useRef(new AbortController());
const { t } = useTranslation();
/* Abort chat completions, questionGuide */
const abortRequest = useCallback(() => {
chatController.current?.abort('stop');
@@ -148,7 +148,7 @@ const PluginRunContextProvider = ({
if (!onStartChat) return;
if (isChatting) {
toast({
title: '正在聊天中...请等待结束',
title: t('chat:is_chatting'),
status: 'warning'
});
return;

View File

@@ -119,7 +119,7 @@ const WholeResponseModal = ({
title={
<Flex alignItems={'center'}>
{t('common:core.chat.response.Complete Response')}
<QuestionTip ml={2} label={'从上到下,为各个模块的响应顺序'}></QuestionTip>
<QuestionTip ml={2} label={t('chat:question_tip')}></QuestionTip>
</Flex>
}
>