Skip to content

Commit 36a272b

Browse files
author
smallstone
committed
Update language translations and fix UI issues
1 parent f903318 commit 36a272b

10 files changed

Lines changed: 86 additions & 68 deletions

File tree

src/util/ideaBridge.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ class IdeaBridge {
364364
}
365365

366366
resviceSettings(res) {
367+
console.log("resviceSettings res: ", res);
367368
// 用户设置的回调
368369
const setting = res.payload.setting;
369370

@@ -372,6 +373,9 @@ class IdeaBridge {
372373
value: setting.currentModel,
373374
});
374375
this.handle.getUserAccessKey({
376+
accessKey: setting.apiKey,
377+
});
378+
this.handle.getUserSetting({
375379
endPoint: setting.apiBase,
376380
accessKey: setting.apiKey,
377381
keyType: setting.apiKey.startsWith("DC") ? "DevChat" : "OpenAi",

src/views/components/BalanceTip/index.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Group,
1010
LoadingOverlay,
1111
} from "@mantine/core";
12+
import { Trans } from "react-i18next";
1213

1314
const currencyMap = {
1415
USD: "$",
@@ -19,7 +20,10 @@ function formatBalance(balance: number) {
1920
return Math.round(balance * 1000) / 1000;
2021
}
2122

22-
function formatCurrency(balance: number, currency: string) {
23+
function formatCurrency(balance: number | null, currency: string) {
24+
if (balance === null || balance === undefined) {
25+
return "";
26+
}
2327
return `${currencyMap[currency] || currency}${balance}`;
2428
}
2529

@@ -34,13 +38,13 @@ const envMap = {
3438
},
3539
};
3640

37-
// eslint-disable-next-line @typescript-eslint/naming-convention
3841
export default function WechatTip() {
3942
const [bindWechat, setBindWechat] = useState(false);
4043
const [balance, setBalance] = useState<null | number>(null);
4144
const [currency, setCurrency] = useState("USD");
4245
const [accessKey, setAccessKey] = useState("");
4346
const [env, setEnv] = useState("prod");
47+
4448
const [loading, setLoading] = useState(false);
4549
const platform = process.env.platform;
4650

@@ -82,7 +86,7 @@ export default function WechatTip() {
8286
useEffect(() => {
8387
getSettings();
8488
messageUtil.registerHandler(
85-
"getUserAccessKey",
89+
"getUserSetting",
8690
(message: { endPoint: string; accessKey: string; keyType: string }) => {
8791
if (message.keyType === "DevChat" && message.accessKey) {
8892
if (message.endPoint.includes("api-test.devchat.ai")) {
@@ -105,6 +109,8 @@ export default function WechatTip() {
105109
});
106110
};
107111

112+
const formatedCurrency = formatCurrency(balance, currency);
113+
108114
if (balance === null || balance === undefined) {
109115
return null;
110116
}
@@ -138,18 +144,19 @@ export default function WechatTip() {
138144
>
139145
<Group style={{ width: "90%" }}>
140146
<Text size="sm">
141-
Your remaining credit is {formatCurrency(balance, currency)}. Sign
142-
in to{" "}
143-
{platform === "idea" ? (
144-
<Text td="underline" c="blue" onClick={(e) => openLink(e)}>
145-
web.devchat.ai{" "}
146-
</Text>
147-
) : (
148-
<a href={envMap[env].link} target="_blank">
149-
web.devchat.ai{" "}
150-
</a>
151-
)}
152-
to {bindWechat ? "purchase more tokens." : "earn additional ¥8"}
147+
<Trans i18nKey="balance" formatedCurrency={formatedCurrency}>
148+
Your remaining credit is {{ formatedCurrency }}. Sign in to{" "}
149+
{platform === "idea" ? (
150+
<Text td="underline" c="blue" onClick={(e) => openLink(e)}>
151+
web.devchat.ai{" "}
152+
</Text>
153+
) : (
154+
<a href={envMap[env].link} target="_blank">
155+
web.devchat.ai{" "}
156+
</a>
157+
)}
158+
to purchase more tokens.
159+
</Trans>
153160
</Text>
154161
<LoadingOverlay visible={loading} />
155162
</Group>

src/views/components/Header/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ export default function Head() {
6868
<IconSettings size="1.125rem" />
6969
</ActionIcon>
7070
</div>
71-
<div>
71+
{/* <div>
7272
<ActionIcon size="sm" onClick={switchLang}>
7373
<IconLanguage size="1.125rem" />
7474
</ActionIcon>
75-
</div>
75+
</div> */}
7676
</Flex>
7777
</Flex>
7878
</Header>

src/views/components/InputMessage/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Topic from "./Topic";
3434
import { observer } from "mobx-react-lite";
3535
import { useMst } from "@/views/stores/RootStore";
3636
import { ChatContext } from "@/views/stores/InputStore";
37-
import { Message } from "@/views/stores/ChatStore";
37+
import { useTranslation } from "react-i18next";
3838

3939
const useStyles = createStyles((theme) => ({
4040
actionIcon: {
@@ -60,6 +60,7 @@ const useStyles = createStyles((theme) => ({
6060
const InputMessage = observer((props: any) => {
6161
const { classes } = useStyles();
6262
const { input, chat } = useMst();
63+
const { t } = useTranslation();
6364
const {
6465
contexts,
6566
menuOpend,
@@ -515,7 +516,7 @@ const InputMessage = observer((props: any) => {
515516
marginTop: 5,
516517
marginBottom: 5,
517518
}}
518-
placeholder="Ask DevChat a question or type ‘/’ for workflow"
519+
placeholder={t("Ask DevChat a question or type ‘/’ for workflow")}
519520
styles={{
520521
rightSection: {
521522
alignItems: "flex-end",

src/views/components/MessageAvatar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const MessageAvatar = observer((props: IProps) => {
6060
) : (
6161
<Avatar color="cyan" size={25} radius="xl" src={SvgAvatarUser} />
6262
)}
63-
<Text weight="bold">{avatarType === "bot" ? "DevChat" : "User"}</Text>
63+
<Text weight="bold">{avatarType === "bot" ? "DevChat" : t("User")}</Text>
6464
{avatarType === "user" ? (
6565
<Flex
6666
gap="xs"
@@ -142,7 +142,7 @@ const MessageAvatar = observer((props: IProps) => {
142142
padding: "3px",
143143
fontSize: "var(--vscode-editor-font-size)",
144144
}}
145-
label={copied ? "Copied" : "Copy message"}
145+
label={copied ? t("Copied") : t("Copy message")}
146146
withArrow
147147
position="left"
148148
color="gray"
Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
1-
import { Container, createStyles ,Text} from "@mantine/core";
1+
import { Container, createStyles, Text } from "@mantine/core";
22
import React from "react";
33
import { observer } from "mobx-react-lite";
44
import MessageMarkdown from "@/views/components/MessageMarkdown";
55
import { useMst } from "@/views/stores/RootStore";
6+
import { useTranslation } from "react-i18next";
67

78
interface IProps {
8-
messageType: string,
9-
children: string,
10-
messageDone?: boolean,
11-
temp?: boolean
9+
messageType: string;
10+
children: string;
11+
messageDone?: boolean;
12+
temp?: boolean;
1213
}
1314

14-
15-
const useStyles = createStyles((theme, options:any) => ({
16-
bodyWidth:{
17-
width: options.chatPanelWidth - 20,
18-
},
19-
userContent:{
20-
fontFamily: theme.fontFamily,
21-
whiteSpace: 'pre-wrap',
22-
wordBreak: 'break-word',
23-
}
15+
const useStyles = createStyles((theme, options: any) => ({
16+
bodyWidth: {
17+
width: options.chatPanelWidth - 20,
18+
},
19+
userContent: {
20+
fontFamily: theme.fontFamily,
21+
whiteSpace: "pre-wrap",
22+
wordBreak: "break-word",
23+
},
2424
}));
2525

2626
const MessageBody = observer((props: IProps) => {
27-
const { children, messageType, temp=false ,messageDone} = props;
28-
const { chat } = useMst();
29-
const {classes} = useStyles({
30-
chatPanelWidth:chat.chatPanelWidth
31-
});
32-
return (
33-
messageType === 'bot'
34-
? <MessageMarkdown className={classes.bodyWidth} temp={temp} messageDone={messageDone}>
35-
{children}
36-
</MessageMarkdown>
37-
: <Container
38-
sx={{
39-
margin: 0,
40-
padding: 0,
41-
width: chat.chatPanelWidth - 20
42-
}}>
43-
<pre className={classes.userContent}>{children}</pre>
44-
</Container>
45-
);
27+
const { children, messageType, temp = false, messageDone } = props;
28+
const { chat } = useMst();
29+
const { classes } = useStyles({
30+
chatPanelWidth: chat.chatPanelWidth,
31+
});
32+
const { t } = useTranslation();
33+
34+
return messageType === "bot" ? (
35+
<MessageMarkdown
36+
className={classes.bodyWidth}
37+
temp={temp}
38+
messageDone={messageDone}
39+
>
40+
{children}
41+
</MessageMarkdown>
42+
) : (
43+
<Container
44+
sx={{
45+
margin: 0,
46+
padding: 0,
47+
width: chat.chatPanelWidth - 20,
48+
}}
49+
>
50+
<pre className={classes.userContent}>{t(children)}</pre>
51+
</Container>
52+
);
4653
});
4754

48-
export default MessageBody;
55+
export default MessageBody;

src/views/i18n/en.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"Delete message": "Delete message"
3-
}
1+
{}

src/views/i18n/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { initReactI18next } from "react-i18next";
33

44
import enTranslations from "./en.json";
55
import zhTranslations from "./zh.json";
6-
console.log("enTranslations: ", enTranslations);
7-
console.log("zhTranslations 233: ", zhTranslations);
86

97
i18n.use(initReactI18next).init({
108
resources: {
@@ -19,7 +17,7 @@ i18n.use(initReactI18next).init({
1917
},
2018
},
2119
},
22-
lng: "en",
20+
lng: "zh",
2321
fallbackLng: "en",
2422
interpolation: {
2523
escapeValue: false,

src/views/i18n/zh.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2-
"Delete message": "11删除消息"
2+
"Delete message": "删除",
3+
"Copied": "已复制",
4+
"Copy message": "复制",
5+
"Refilled": "已发送",
6+
"Refill message": "再次发送",
7+
"User": "用户",
8+
"Ask DevChat a question or type ‘/’ for workflow": "向 DevChat 提问或输入 '/' 以查看工作流",
9+
"How do I use DevChat?": "如何使用 DevChat?",
10+
"balance": "您的余额为 {{formatedCurrency}},登录 <4>web.devchat.ai</4> 以获得更多 tokens"
311
}

webpack.idea.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ const webviewConfig = {
7373
],
7474
include: /views/,
7575
},
76-
{
77-
test: /\.json$/i,
78-
use: "json-loader",
79-
type: "asset/source",
80-
},
8176
{
8277
test: /\.(png|jpg|jpeg|gif|svg)$/, // 匹配文件类型
8378
type: "asset/inline",

0 commit comments

Comments
 (0)