Skip to content

Commit

Permalink
Improve the i18n configuration of the chat page (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
F-loat committed Jan 10, 2024
1 parent dfa6586 commit 414b693
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
9 changes: 8 additions & 1 deletion projects/app/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@
"Mark Description": "The annotation feature is currently in beta. \n\n After clicking Add annotation, you need to select a knowledge base in order to store annotation data. You can use this feature to quickly annotate questions and expected answers to guide the model to the next answer. At present, the annotation function, like other data in the knowledge base, is affected by the model, which does not mean that the annotation meets 100% expectations. The \n\n annotation data is only unidirectional synchronization with the knowledge base. If the knowledge base modifies the annotation data, the annotation data displayed in the log cannot be synchronized",
"Mark Description Title": "Mark Description",
"New Chat": "New Chat",
"Fresh Chat": "New Chat",
"Question Guide Tips": "I guess what you're asking is",
"Quote": "Quote",
"Pin": "Pin",
"Unpin": "Unpin",
"Read Mark Description": "Read mark description",
"Select Mark Kb": "Select Dataset",
"Select Mark Kb Desc": "Select a dataset to store the expected answers",
"You need to a chat app": "You need to a chat app",
"Failed to initialize chat": "Failed to initialize chat",
"Custom History Title": "Custom history title",
"Custom History Title Description": "If set to empty, chat history will be followed automatically.",
"History Amount": "{{amount}} records",
"logs": {
"api": "API",
"online": "Online Chat",
Expand Down Expand Up @@ -1062,4 +1069,4 @@
"qa": "QA Generation"
}
}
}
}
9 changes: 8 additions & 1 deletion projects/app/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@
"Mark Description": "当前标注功能为测试版。\n\n点击添加标注后,需要选择一个知识库,以便存储标注数据。你可以通过该功能快速的标注问题和预期回答,以便引导模型下次的回答。\n\n目前,标注功能同知识库其他数据一样,受模型的影响,不代表标注后 100% 符合预期。\n\n标注数据仅单向与知识库同步,如果知识库修改了该标注数据,日志展示的标注数据无法同步",
"Mark Description Title": "标注功能介绍",
"New Chat": "新对话",
"Fresh Chat": "新的对话",
"Question Guide Tips": "猜你想问",
"Quote": "引用",
"Pin": "置顶",
"Unpin": "取消置顶",
"Read Mark Description": "查看标注功能介绍",
"Select Mark Kb": "选择知识库",
"Select Mark Kb Desc": "选择一个知识库存储预期答案",
"You need to a chat app": "你需要创建一个应用",
"Failed to initialize chat": "初始化聊天失败",
"Custom History Title": "自定义历史记录标题",
"Custom History Title Description": "如果设置为空,会自动跟随聊天记录。",
"History Amount": "{{amount}}条记录",
"logs": {
"api": "API 调用",
"online": "在线使用",
Expand Down Expand Up @@ -1062,4 +1069,4 @@
"qa": "QA 拆分"
}
}
}
}
10 changes: 8 additions & 2 deletions projects/app/src/pages/chat/components/ChatHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Avatar from '@/components/Avatar';
import ToolMenu from './ToolMenu';
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
import { useRouter } from 'next/router';
import { useTranslation } from 'next-i18next';
import { chatContentReplaceBlock } from '@fastgpt/global/core/chat/utils';

const ChatHeader = ({
Expand All @@ -28,12 +29,13 @@ const ChatHeader = ({
}) => {
const router = useRouter();
const theme = useTheme();
const { t } = useTranslation();
const { isPc } = useSystemStore();
const title = useMemo(
() =>
chatContentReplaceBlock(history[history.length - 2]?.value)?.slice(0, 8) ||
appName ||
'新对话',
t('chat.New Chat'),
[appName, history]
);

Expand All @@ -52,7 +54,11 @@ const ChatHeader = ({
</Box>
<Tag>
<MyIcon name={'history'} w={'14px'} />
<Box ml={1}>{history.length === 0 ? '新的对话' : `${history.length}条记录`}</Box>
<Box ml={1}>
{history.length === 0
? t('chat.Fresh Chat')
: t('chat.History Amount', { amount: history.length })}
</Box>
</Tag>
{!!chatModels && chatModels.length > 0 && (
<Tag ml={2} colorSchema={'green'}>
Expand Down
8 changes: 4 additions & 4 deletions projects/app/src/pages/chat/components/ChatHistorySlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ const ChatHistorySlider = ({

// custom title edit
const { onOpenModal, EditModal: EditTitleModal } = useEditTitle({
title: '自定义历史记录标题',
placeholder: '如果设置为空,会自动跟随聊天记录。'
title: t('chat.Custom History Title'),
placeholder: t('chat.Custom History Title Description')
});
const { openConfirm, ConfirmModal } = useConfirm({
content: isShare
Expand Down Expand Up @@ -240,7 +240,7 @@ const ChatHistorySlider = ({
}}
>
<MyIcon mr={2} name={'core/chat/setTopLight'} w={'16px'}></MyIcon>
{item.top ? '取消置顶' : '置顶'}
{item.top ? t('chat.Unpin') : t('chat.Pin')}
</MenuItem>
)}
{onSetCustomTitle && (
Expand Down Expand Up @@ -272,7 +272,7 @@ const ChatHistorySlider = ({
}}
>
<MyIcon mr={2} name={'delete'} w={'16px'}></MyIcon>
删除
{t('common.Delete')}
</MenuItem>
</MenuList>
</Menu>
Expand Down
14 changes: 10 additions & 4 deletions projects/app/src/pages/chat/components/ToolMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import React, { useMemo } from 'react';
import { useChatBox } from '@/components/ChatBox';
import type { ChatItemType } from '@fastgpt/global/core/chat/type.d';
import { Menu, MenuButton, MenuList, MenuItem, Box } from '@chakra-ui/react';
import { useTranslation } from 'next-i18next';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { useRouter } from 'next/router';

const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
const { t } = useTranslation();
const { onExportChat } = useChatBox();
const router = useRouter();

const menuList = useMemo(
() => [
{
icon: 'core/chat/chatLight',
label: '新对话',
label: t('chat.New Chat'),
onClick: () => {
router.replace({
query: {
Expand All @@ -25,15 +27,19 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
},
{
icon: 'core/app/appApiLight',
label: 'HTML导出',
label: `HTML ${t('Export')}`,
onClick: () => onExportChat({ type: 'html', history })
},
{
icon: 'file/markdown',
label: 'Markdown导出',
label: `Markdown ${t('Export')}`,
onClick: () => onExportChat({ type: 'md', history })
},
{ icon: 'file/pdf', label: 'PDF导出', onClick: () => onExportChat({ type: 'pdf', history }) }
{
icon: 'file/pdf',
label: `PDF ${t('Export')}`,
onClick: () => onExportChat({ type: 'pdf', history })
}
],
[history, onExportChat, router]
);
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/pages/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
const newTitle =
chatContentReplaceBlock(prompts[0].content).slice(0, 20) ||
prompts[1]?.value?.slice(0, 20) ||
'新对话';
t('chat.New Chat');

// new chat
if (completionChatId !== chatId) {
Expand Down Expand Up @@ -166,7 +166,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
setLastChatAppId('');
setLastChatId('');
toast({
title: getErrText(e, '初始化聊天失败'),
title: getErrText(e, t('chat.Failed to initialize chat')),
status: 'error'
});
if (e?.code === 501) {
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/pages/chat/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const OutLink = ({
const newTitle =
chatContentReplaceBlock(prompts[0].content).slice(0, 20) ||
prompts[1]?.value?.slice(0, 20) ||
'新对话';
t('chat.New Chat');

// new chat
if (completionChatId !== chatId) {
Expand Down

0 comments on commit 414b693

Please sign in to comment.