Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added English Version #188

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"Choice Visual": "Visual workflow",
"Choice Visual Desc": "Visualize modular operations, easily implement complex workflows, and make your AI no longer monolithic",
"Community": "Community",
"Confirm to log out?": "Confirm to log out?",
"Dateset": "",
"Dateset Desc": "",
"Docs": "Docs",
Expand Down Expand Up @@ -122,4 +123,4 @@
"Update password succseful": "Update password succseful",
"Usage Record": "Usage"
}
}
}
3 changes: 2 additions & 1 deletion client/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"Choice Visual": "可视化工作流",
"Choice Visual Desc": "可视化模块操作,轻松实现复杂工作流,让你的 AI 不再单一",
"Community": "社区",
"Confirm to log out?": "确认退出吗?",
"Dateset": "自动数据预处理",
"Dateset Desc": "提供手动输入、直接分段、LLM 自动处理和 CSV 等多种数据导入途径",
"Docs": "文档",
Expand Down Expand Up @@ -122,4 +123,4 @@
"Update password succseful": "修改密码成功",
"Usage Record": "使用记录"
}
}
}
8 changes: 4 additions & 4 deletions client/src/api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const streamFetch = ({
});
} else {
return reject({
message: errMsg || '响应过程出现异常~',
message: errMsg || 'There is an exception in the response process~',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server error prompt can not be translated first, I think about the server error how to implement i18n

responseText
});
}
Expand Down Expand Up @@ -89,7 +89,7 @@ export const streamFetch = ({
) {
responseData = data;
} else if (eventName === sseResponseEventEnum.error) {
errMsg = getErrText(data, '流响应错误');
errMsg = getErrText(data, 'stream response error');
}
});
read();
Expand All @@ -102,14 +102,14 @@ export const streamFetch = ({
}
reject({
responseText,
message: getErrText(err, '请求异常')
message: getErrText(err, 'request exception')
});
}
};
read();
} catch (err: any) {
console.log(err, 'fetch error');

reject(getErrText(err, '请求异常'));
reject(getErrText(err, 'request exception'));
}
});
8 changes: 4 additions & 4 deletions client/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function responseSuccess(response: AxiosResponse<ResponseDataType>) {
function checkRes(data: ResponseDataType) {
if (data === undefined) {
console.log('error->', data, 'data is empty');
return Promise.reject('服务器异常');
return Promise.reject('server exception');
} else if (data.code < 200 || data.code >= 400) {
return Promise.reject(data);
}
Expand All @@ -47,10 +47,10 @@ function checkRes(data: ResponseDataType) {
* 响应错误
*/
function responseError(err: any) {
console.log('error->', '请求错误', err);
console.log('error->', 'wrong request', err);

if (!err) {
return Promise.reject({ message: '未知错误' });
return Promise.reject({ message: 'unknown mistake' });
}
if (typeof err === 'string') {
return Promise.reject({ message: err });
Expand All @@ -61,7 +61,7 @@ function responseError(err: any) {
window.location.replace(
`/login?lastRoute=${encodeURIComponent(location.pathname + location.search)}`
);
return Promise.reject({ message: 'token过期,重新登录' });
return Promise.reject({ message: 'token expires, log in again' });
}
if (err?.response?.data) {
return Promise.reject(err?.response?.data);
Expand Down
16 changes: 9 additions & 7 deletions client/src/components/APIKeyModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import { getErrText, useCopyData } from '@/utils/tools';
import { useToast } from '@/hooks/useToast';
import MyIcon from '../Icon';
import MyModal from '../MyModal';
import { useTranslation } from 'react-i18next';

const { t } = useTranslation();
const APIKeyModal = ({ onClose }: { onClose: () => void }) => {
const { Loading } = useLoading();
const { toast } = useToast();
Expand Down Expand Up @@ -63,7 +65,7 @@ const APIKeyModal = ({ onClose }: { onClose: () => void }) => {
API 秘钥管理
</Box>
<Box fontSize={'sm'} color={'myGray.600'}>
如果你不想 API 秘钥被滥用,请勿将秘钥直接放置在前端使用~
{t('如果你不想 API 秘钥被滥用,请勿将秘钥直接放置在前端使用~')}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to write it in English.
Example: t('user.Open API Tips')

en: If you do not want the API key to be abused, do not place the key directly on the front end

zh: 如果你不想 API 秘钥被滥用,请勿将秘钥直接放置在前端使用~

</Box>
</Box>
<ModalBody minH={'300px'} maxH={['70vh', '500px']} overflow={'overlay'}>
Expand All @@ -72,8 +74,8 @@ const APIKeyModal = ({ onClose }: { onClose: () => void }) => {
<Thead>
<Tr>
<Th>Api Key</Th>
<Th>创建时间</Th>
<Th>最后一次使用时间</Th>
<Th>{t('创建时间')}</Th>
<Th>{t('最后一次使用时间')}</Th>
<Th />
</Tr>
</Thead>
Expand All @@ -85,7 +87,7 @@ const APIKeyModal = ({ onClose }: { onClose: () => void }) => {
<Td>
{lastUsedTime
? dayjs(lastUsedTime).format('YYYY/MM/DD HH:mm:ss')
: '没有使用过'}
: t('没有使用过')}
</Td>
<Td>
<IconButton
Expand All @@ -110,18 +112,18 @@ const APIKeyModal = ({ onClose }: { onClose: () => void }) => {
leftIcon={<AddIcon color={'myGray.600'} fontSize={'sm'} />}
onClick={() => onclickCreateApiKey()}
>
新建秘钥
{t('新建秘钥')}
</Button>
</ModalFooter>

<Loading loading={isGetting || isCreating || isDeleting} fixed={false} />
<MyModal isOpen={!!apiKey} w={'400px'} onClose={() => setApiKey('')}>
<Box py={3} px={5}>
<Box fontWeight={'bold'} fontSize={'2xl'}>
新的 API 秘钥
{t('新的 API 秘钥')}
</Box>
<Box fontSize={'sm'} color={'myGray.600'}>
请保管好你的秘钥,秘钥不会再次展示~
{t('请保管好你的秘钥,秘钥不会再次展示~')}
</Box>
</Box>
<ModalBody>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ChatBox/ContextModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ContextModal = ({
<MyModal
isOpen={true}
onClose={onClose}
title={`完整对话记录(${context.length}条)`}
title={t(`full conversation log(${context.length}strip)`)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is a translation with variables, you need to write:
t('chat.Full Context n strip', {length: context.length})

en.json:

"chat":{
    "Full Context n strip": "Full context ({{length}}) strip"
}

zh.json

"chat":{
    "Full Context n strip": "完整对话记录 ({{length}}) 条"
}

h={['90vh', '80vh']}
minW={['90vw', '600px']}
isCentered
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/ChatBox/ResponseDetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import Tag from '../Tag';
import MyTooltip from '../MyTooltip';
const QuoteModal = dynamic(() => import('./QuoteModal'), { ssr: false });
const ContextModal = dynamic(() => import('./ContextModal'), { ssr: false });
import { useTranslation } from 'react-i18next';

const { t } = useTranslation();
const ResponseDetailModal = ({
chatId,
contentId,
Expand Down Expand Up @@ -49,7 +51,7 @@ const ResponseDetailModal = ({
return isEmpty ? null : (
<Flex alignItems={'center'} mt={2} flexWrap={'wrap'}>
{quoteList.length > 0 && (
<MyTooltip label="查看引用">
<MyTooltip label={t('查看引用')}>
<Tag
colorSchema="blue"
cursor={'pointer'}
Expand All @@ -61,7 +63,7 @@ const ResponseDetailModal = ({
</MyTooltip>
)}
{completeMessages.length > 0 && (
<MyTooltip label={'点击查看完整对话记录'}>
<MyTooltip label={t('点击查看完整对话记录')}>
<Tag
colorSchema="green"
cursor={'pointer'}
Expand Down
25 changes: 14 additions & 11 deletions client/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ import dynamic from 'next/dynamic';
const ResponseDetailModal = dynamic(() => import('./ResponseDetailModal'));

import styles from './index.module.scss';
import { useTranslation } from 'react-i18next';

const { t } = useTranslation();

const textareaMinH = '22px';
type generatingMessageProps = { text?: string; name?: string; status?: 'running' | 'finish' };
Expand Down Expand Up @@ -262,7 +265,7 @@ const ChatBox = (
async (variables: Record<string, any> = {}, inputVal = '') => {
if (isChatting) {
toast({
title: '正在聊天中...请等待结束',
title: t('正在聊天中...请等待结束'),
status: 'warning'
});
return;
Expand All @@ -272,7 +275,7 @@ const ChatBox = (

if (!val) {
toast({
title: '内容为空',
title: t('内容为空'),
status: 'warning'
});
return;
Expand Down Expand Up @@ -338,7 +341,7 @@ const ChatBox = (
}, 100);
} catch (err: any) {
toast({
title: getErrText(err, '聊天出错了~'),
title: getErrText(err, t('聊天出错了~')),
status: 'error',
duration: 5000,
isClosable: true
Expand Down Expand Up @@ -538,7 +541,7 @@ const ChatBox = (
setVariables(data);
})}
>
{'开始对话'}
{t('开始对话')}
</Button>
)}
</Card>
Expand All @@ -564,7 +567,7 @@ const ChatBox = (
<>
<Flex w={'100%'} alignItems={'center'} justifyContent={'flex-end'}>
<Flex {...controlContainerStyle} justifyContent={'flex-end'} mr={3}>
<MyTooltip label={'复制'}>
<MyTooltip label={t('复制')}>
<MyIcon
{...controlIconStyle}
name={'copy'}
Expand All @@ -573,7 +576,7 @@ const ChatBox = (
/>
</MyTooltip>
{onDelMessage && (
<MyTooltip label={'删除'}>
<MyTooltip label={t('删除')}>
<MyIcon
{...controlIconStyle}
mr={0}
Expand Down Expand Up @@ -612,7 +615,7 @@ const ChatBox = (
<Flex w={'100%'} alignItems={'flex-end'}>
<ChatAvatar src={appAvatar} type={'AI'} />
<Flex {...controlContainerStyle} ml={3}>
<MyTooltip label={'复制'}>
<MyTooltip label={t('复制')}>
<MyIcon
{...controlIconStyle}
name={'copy'}
Expand All @@ -621,7 +624,7 @@ const ChatBox = (
/>
</MyTooltip>
{onDelMessage && (
<MyTooltip label={'删除'}>
<MyTooltip label={t('删除')}>
<MyIcon
{...controlIconStyle}
name={'delete'}
Expand All @@ -639,7 +642,7 @@ const ChatBox = (
</MyTooltip>
)}
{hasVoiceApi && (
<MyTooltip label={'语音播报'}>
<MyTooltip label={t('语音播报')}>
<MyIcon
{...controlIconStyle}
name={'voice'}
Expand Down Expand Up @@ -831,7 +834,7 @@ export const useChatBox = () => {
fileDownload({
text: html,
type: 'text/html',
filename: '聊天记录.html'
filename: t('聊天记录.html')
});
},
pdf: () => {
Expand All @@ -841,7 +844,7 @@ export const useChatBox = () => {
// @ts-ignore
html2pdf(html, {
margin: 0,
filename: `聊天记录.pdf`
filename: t(`聊天记录.pdf`)
});
}
};
Expand Down
8 changes: 5 additions & 3 deletions client/src/components/CommunityModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { Button, ModalFooter, ModalBody } from '@chakra-ui/react';
import MyModal from '../MyModal';
import { useTranslation } from 'react-i18next';
import Markdown from '../Markdown';
import { useTranslation } from 'react-i18next';

const md = `
const { t } = useTranslation();
const md = t(`
| 交流群 | 小助手 |
| ----------------------- | -------------------- |
| ![](https://otnvvf-imgs.oss.laf.run/wxqun300.jpg) | ![](https://otnvvf-imgs.oss.laf.run/wx300.jpg) |
`;
`);

const CommunityModal = ({ onClose }: { onClose: () => void }) => {
const { t } = useTranslation();
Expand All @@ -20,7 +22,7 @@ const CommunityModal = ({ onClose }: { onClose: () => void }) => {

<ModalFooter>
<Button variant={'base'} onClick={onClose}>
关闭
{t('关闭')}
</Button>
</ModalFooter>
</MyModal>
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/Layout/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { useRouter } from 'next/router';
import { useToast } from '@chakra-ui/react';
import { useUserStore } from '@/store/user';
import { useQuery } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';

const { t } = useTranslation();
const unAuthPage: { [key: string]: boolean } = {
'/': true,
'/login': true,
Expand All @@ -15,7 +17,7 @@ const unAuthPage: { [key: string]: boolean } = {
const Auth = ({ children }: { children: JSX.Element }) => {
const router = useRouter();
const toast = useToast({
title: '请先登录',
title: t('请先登录'),
position: 'top',
status: 'warning'
});
Expand Down
4 changes: 2 additions & 2 deletions client/src/constants/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export enum TaskResponseKeyEnum {

export const ChatRoleMap = {
[ChatRoleEnum.System]: {
name: '系统提示词'
name: 'system prompt word'
},
[ChatRoleEnum.Human]: {
name: '用户'
name: 'user'
},
[ChatRoleEnum.AI]: {
name: 'AI'
Expand Down
6 changes: 3 additions & 3 deletions client/src/constants/flow/inputTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import { FlowInputItemTypeEnum, FlowValueTypeEnum } from './index';
export const Input_Template_TFSwitch: FlowInputItemType = {
key: SystemInputEnum.switch,
type: FlowInputItemTypeEnum.target,
label: '触发器',
label: 'trigger',
valueType: FlowValueTypeEnum.any
};

export const Input_Template_History: FlowInputItemType = {
key: SystemInputEnum.history,
type: FlowInputItemTypeEnum.target,
label: '聊天记录',
label: 'chat record',
valueType: FlowValueTypeEnum.chatHistory
};

export const Input_Template_UserChatInput: FlowInputItemType = {
key: SystemInputEnum.userChatInput,
type: FlowInputItemTypeEnum.target,
label: '用户问题',
label: 'user question',
required: true,
valueType: FlowValueTypeEnum.string
};
2 changes: 1 addition & 1 deletion client/src/constants/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum OpenAiChatEnum {
export const defaultApp: AppSchema = {
_id: '',
userId: 'userId',
name: '模型加载中',
name: 'model loading',
type: 'basic',
avatar: '/icon/logo.png',
intro: '',
Expand Down