Skip to content

Commit 60f68ad

Browse files
committed
feat(i18n): add translation files and integrate i18n in AI page
- Add English and Chinese translation JSON files with comprehensive app translations - Update i18n config to use relative import paths for locale files - Integrate i18n in AI page to display translated error messages and UI labels - Add desktop shortcut button to widget search item with translation support
1 parent b120b31 commit 60f68ad

6 files changed

Lines changed: 67 additions & 22 deletions

File tree

.eslintcache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/i18n/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import i18n from 'i18next'
22
import LanguageDetector from 'i18next-browser-languagedetector'
33
import { initReactI18next } from 'react-i18next'
4-
import enTranslation from '../locales/en/translation.json'
5-
import zhTranslation from '../locales/zh/translation.json'
4+
import enTranslation from './locales/en/translation.json'
5+
import zhTranslation from './locales/zh/translation.json'
66

77
i18n
88
.use(LanguageDetector)
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"overlap": "Overlap",
222222
"tray": "Tray",
223223
"upgrade": "Upgrade",
224-
"installOffline": "Install Offline Widget"
224+
"installOffline": "Install Offline Widget",
225+
"desktopShortcut": "Shortcut"
225226
},
226227
"tags": {
227228
"all": "All",
@@ -253,5 +254,24 @@
253254
"unexpected": "Sorry, an unexpected error has occurred.",
254255
"unknown": "Unknown error",
255256
"backToHome": "Back to Home"
257+
},
258+
"aiPage": {
259+
"loadPackagesFailed": "Failed to load packages",
260+
"loadHistoryFailed": "Failed to load history",
261+
"tokenPackages": "Token Packages",
262+
"purchasePackage": "Purchase Package",
263+
"expirationDate": "Expiration Date:",
264+
"lifetime": "Lifetime",
265+
"used": "Used:",
266+
"total": "Total:",
267+
"noPackages": "No packages available",
268+
"usageHistory": "Usage History",
269+
"time": "Time",
270+
"model": "Model",
271+
"type": "Type",
272+
"tokens": "Tokens",
273+
"remark": "Remark",
274+
"loading": "Loading...",
275+
"noHistory": "No history records"
256276
}
257277
}
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"overlap": "悬浮窗",
222222
"tray": "托盘",
223223
"upgrade": "升级",
224-
"installOffline": "安装离线组件"
224+
"installOffline": "安装离线组件",
225+
"desktopShortcut": "桌面图标"
225226
},
226227
"tags": {
227228
"all": "全部",
@@ -253,5 +254,24 @@
253254
"unexpected": "抱歉,发生了意外错误。",
254255
"unknown": "未知错误",
255256
"backToHome": "返回首页"
257+
},
258+
"aiPage": {
259+
"loadPackagesFailed": "加载套餐失败",
260+
"loadHistoryFailed": "加载历史记录失败",
261+
"tokenPackages": "Token套餐",
262+
"purchasePackage": "购买套餐",
263+
"expirationDate": "过期时间:",
264+
"lifetime": "永久有效",
265+
"used": "已用:",
266+
"total": "总量:",
267+
"noPackages": "暂无可用套餐",
268+
"usageHistory": "使用记录",
269+
"time": "时间",
270+
"model": "模型",
271+
"type": "类型",
272+
"tokens": "Token数",
273+
"remark": "备注",
274+
"loading": "加载中...",
275+
"noHistory": "暂无历史记录"
256276
}
257277
}

src/pages/add/components/search-item.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ export function SearchItem({ widget }: SearchItemProps) {
177177
DevTools
178178
</Button>
179179
)}
180+
<Button variant="outline" onClick={() => DeployedWidgetApi.createDesktopShortcut(widget.name)} className="rounded-full">
181+
{t('search.desktopShortcut', '桌面图标')}
182+
</Button>
180183
</>
181184
)
182185
: (

src/pages/ai/ai-page.tsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { AiTokenHistory, AiTokenPackage } from '@/api/ai'
22
import { History, Package, ShoppingCart } from 'lucide-react'
33
import * as React from 'react'
44
import { useEffect, useState } from 'react'
5+
import { useTranslation } from 'react-i18next'
56
import { toast } from 'sonner'
67
import { AiApi } from '@/api/ai'
78
import { LoginCheck } from '@/components/login-check'
@@ -32,6 +33,7 @@ import {
3233
import { useUser } from '@/hooks/use-user'
3334

3435
export default function AiPage() {
36+
const { t } = useTranslation()
3537
const { user } = useUser()
3638
const [packages, setPackages] = useState<AiTokenPackage[]>([])
3739
const [history, setHistory] = useState<AiTokenHistory[]>([])
@@ -50,7 +52,7 @@ export default function AiPage() {
5052
}
5153
catch (error) {
5254
console.error(error)
53-
toast.error('加载套餐失败')
55+
toast.error(t('aiPage.loadPackagesFailed', '加载套餐失败'))
5456
}
5557
}
5658

@@ -69,7 +71,7 @@ export default function AiPage() {
6971
}
7072
catch (error) {
7173
console.error(error)
72-
toast.error('加载历史记录失败')
74+
toast.error(t('aiPage.loadHistoryFailed', '加载历史记录失败'))
7375
}
7476
finally {
7577
setLoading(false)
@@ -91,7 +93,7 @@ export default function AiPage() {
9193
<section>
9294
<h2 className="text-2xl font-bold mb-4 flex items-center gap-2">
9395
<Package className="h-6 w-6" />
94-
Token套餐
96+
{t('aiPage.tokenPackages', 'Token套餐')}
9597
</h2>
9698
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
9799
<Card
@@ -100,7 +102,7 @@ export default function AiPage() {
100102
>
101103
<div className="flex flex-col items-center gap-2 text-muted-foreground hover:text-primary">
102104
<ShoppingCart className="h-8 w-8" />
103-
<span className="font-medium">购买套餐</span>
105+
<span className="font-medium">{t('aiPage.purchasePackage', '购买套餐')}</span>
104106
</div>
105107
</Card>
106108

@@ -109,19 +111,19 @@ export default function AiPage() {
109111
<CardHeader className="pb-2">
110112
<CardTitle className="text-lg">{pkg.name}</CardTitle>
111113
<CardDescription>
112-
过期时间:
114+
{t('aiPage.expirationDate', '过期时间:')}
113115
{' '}
114-
{pkg.expireTime ? new Date(pkg.expireTime).toLocaleDateString() : '永久有效'}
116+
{pkg.expireTime ? new Date(pkg.expireTime).toLocaleDateString() : t('aiPage.lifetime', '永久有效')}
115117
</CardDescription>
116118
</CardHeader>
117119
<CardContent>
118120
<div className="flex flex-col gap-1">
119121
<div className="flex justify-between text-sm">
120-
<span className="text-muted-foreground">已用:</span>
122+
<span className="text-muted-foreground">{t('aiPage.used', '已用:')}</span>
121123
<span>{pkg.usedToken.toLocaleString()}</span>
122124
</div>
123125
<div className="flex justify-between text-sm">
124-
<span className="text-muted-foreground">总量:</span>
126+
<span className="text-muted-foreground">{t('aiPage.total', '总量:')}</span>
125127
<span>{pkg.maxToken.toLocaleString()}</span>
126128
</div>
127129
<div className="w-full bg-secondary h-2 rounded-full mt-2 overflow-hidden">
@@ -136,7 +138,7 @@ export default function AiPage() {
136138
))}
137139
{packages.length === 0 && (
138140
<div className="col-span-3 flex text-center justify-center items-center text-muted-foreground py-8 border rounded-lg border-dashed">
139-
暂无可用套餐
141+
{t('aiPage.noPackages', '暂无可用套餐')}
140142
</div>
141143
)}
142144
</div>
@@ -152,26 +154,26 @@ export default function AiPage() {
152154
<section>
153155
<h2 className="text-2xl font-bold mb-4 flex items-center gap-2">
154156
<History className="h-6 w-6" />
155-
使用记录
157+
{t('aiPage.usageHistory', '使用记录')}
156158
</h2>
157159
<Card>
158160
<CardContent className="p-0">
159161
<Table>
160162
<TableHeader>
161163
<TableRow>
162-
<TableHead>时间</TableHead>
163-
<TableHead>模型</TableHead>
164-
<TableHead>类型</TableHead>
165-
<TableHead>Token数</TableHead>
166-
<TableHead>备注</TableHead>
164+
<TableHead>{t('aiPage.time', '时间')}</TableHead>
165+
<TableHead>{t('aiPage.model', '模型')}</TableHead>
166+
<TableHead>{t('aiPage.type', '类型')}</TableHead>
167+
<TableHead>{t('aiPage.tokens', 'Token数')}</TableHead>
168+
<TableHead>{t('aiPage.remark', '备注')}</TableHead>
167169
</TableRow>
168170
</TableHeader>
169171
<TableBody>
170172
{loading
171173
? (
172174
<TableRow>
173175
<TableCell colSpan={5} className="text-center py-8">
174-
加载中...
176+
{t('aiPage.loading', '加载中...')}
175177
</TableCell>
176178
</TableRow>
177179
)
@@ -190,7 +192,7 @@ export default function AiPage() {
190192
: (
191193
<TableRow>
192194
<TableCell colSpan={5} className="text-center py-8 text-muted-foreground">
193-
暂无历史记录
195+
{t('aiPage.noHistory', '暂无历史记录')}
194196
</TableCell>
195197
</TableRow>
196198
)}

0 commit comments

Comments
 (0)