Skip to content

Commit 906aa2a

Browse files
committed
feat: Support for internationalization settings
Signed-off-by: Fang Yuan <wojiushifangyuanlove@gmail.com>
1 parent b754e2d commit 906aa2a

23 files changed

+550
-196
lines changed

frontend/package-lock.json

+115-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12+
"antd": "^5.22.5",
13+
"i18next": "^24.2.0",
1214
"react": "^18.2.0",
1315
"react-dom": "^18.2.0",
14-
"antd": "^5.22.5"
16+
"react-i18next": "^15.2.0"
1517
},
1618
"devDependencies": {
1719
"@types/react": "^18.0.17",
1820
"@types/react-dom": "^18.0.6",
1921
"@vitejs/plugin-react": "^2.0.1",
20-
"typescript": "^4.6.4",
22+
"typescript": "^5.7.2",
2123
"vite": "^3.0.7"
2224
}
23-
}
25+
}

frontend/package.json.md5

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6e0124b4ef11e61fdca1e746197685fa
1+
7ffde1767b8ee8d6317e605354923815

frontend/src/App.tsx

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1+
import './i18n';
12
import React, { useState } from 'react';
23
import { Layout, Menu, theme } from 'antd';
4+
import { useTranslation } from 'react-i18next';
35
import './App.css';
46
import { DownloadProvider } from './context/DownloadContext';
57
import DownloadNovel from './components/DownloadNovel';
68
import CheckUpdate from './components/CheckUpdate';
79
import ViewConfig from './components/ViewConfig';
810
import UsageInfo from './components/UsageInfo';
11+
import LanguageSwitcher from './components/LanguageSwitcher';
912

1013
const { Header, Content, Footer } = Layout;
11-
const options = [
12-
"下载小说",
13-
"检查更新",
14-
"查看配置文件",
15-
"使用须知",
16-
];
1714

1815
const App: React.FC = () => {
16+
const { t } = useTranslation();
1917
const {
2018
token: { colorBgContainer, borderRadiusLG },
2119
} = theme.useToken();
2220

2321
const [selectedOption, setSelectedOption] = useState<number>(0);
2422

23+
const options = [
24+
{ key: '0', label: t('app.menu.downloadNovel') },
25+
{ key: '1', label: t('app.menu.checkUpdate') },
26+
{ key: '2', label: t('app.menu.viewConfig') },
27+
{ key: '3', label: t('app.menu.usageInfo') },
28+
];
29+
2530
const handleMenuClick = (e: any) => {
2631
const index = parseInt(e.key, 10);
2732
setSelectedOption(index);
@@ -42,31 +47,25 @@ const App: React.FC = () => {
4247
case 3:
4348
return <UsageInfo />;
4449
default:
45-
return <p>请选择一个选项</p>;
50+
return <p>{t('app.menu.selectOption')}</p>;
4651
}
4752
};
4853

49-
const items = options.map((option, index) => ({
50-
key: index.toString(),
51-
label: option,
52-
}));
53-
5454
return (
5555
<Layout>
56-
<Header style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
56+
<Header style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
5757
<Menu
5858
theme="dark"
5959
mode="horizontal"
60-
items={items}
61-
defaultSelectedKeys={[`0`]}
60+
items={options}
61+
defaultSelectedKeys={['0']}
6262
style={{
63-
flex: 'none',
63+
flex: 1,
6464
minWidth: 0,
65-
display: 'flex',
66-
justifyContent: 'center',
6765
}}
6866
onClick={handleMenuClick}
6967
/>
68+
<LanguageSwitcher />
7069
</Header>
7170
<Content style={{ padding: '0 48px' }}>
7271
<div
@@ -81,7 +80,7 @@ const App: React.FC = () => {
8180
</div>
8281
</Content>
8382
<Footer style={{ textAlign: 'center' }}>
84-
我是混子 ©{new Date().getFullYear()} Created by 呵呵呵
83+
{t('app.footer', { year: new Date().getFullYear() })}
8584
</Footer>
8685
</Layout>
8786
);

0 commit comments

Comments
 (0)