feat(frontend): 控制台 next-intl 中英双语

接入无 URL 前缀的 zh-CN/en,顶栏与外观设置可切换语言;选择写入 cookie 后刷新生效。
This commit is contained in:
ryan
2026-08-16 16:49:16 +08:00
parent 64fbaa7ef1
commit 5a8722ff07
219 changed files with 21437 additions and 5212 deletions
@@ -32,6 +32,8 @@ import {
import type { ProxyRouteItem } from '@/lib/services/openflare';
import { ProxyRouteService } from '@/lib/services/openflare';
import { useTranslations } from 'next-intl';
import {
getRouteDomainNames,
getRouteDomainsLabel,
@@ -41,6 +43,8 @@ import {
import { ProxyRouteCreateSheet } from './components/proxy-route-create-sheet';
export function ProxyRoutesPageClient() {
const t = useTranslations('proxyRoutes');
const tc = useTranslations('common');
const router = useRouter();
const [routes, setRoutes] = useState<ProxyRouteItem[]>([]);
const [loading, setLoading] = useState(true);
@@ -55,13 +59,13 @@ export function ProxyRoutesPageClient() {
const data = await ProxyRouteService.list();
setRoutes(data);
} catch (error) {
toast.error('规则列表加载失败', {
description: error instanceof Error ? error.message : '未知错误',
toast.error(t('loadListFailed'), {
description: error instanceof Error ? error.message : t('unknownError'),
});
} finally {
setLoading(false);
}
}, []);
}, [t]);
useEffect(() => {
void fetchRoutes();
@@ -95,12 +99,12 @@ export function ProxyRoutesPageClient() {
setDeleting(true);
try {
await ProxyRouteService.deleteById(deleteTarget.id);
toast.success('网站已删除');
toast.success(t('siteDeleted'));
setDeleteTarget(null);
await fetchRoutes();
} catch (error) {
toast.error('删除失败', {
description: error instanceof Error ? error.message : '未知错误',
toast.error(t('deleteFailed'), {
description: error instanceof Error ? error.message : t('unknownError'),
});
} finally {
setDeleting(false);
@@ -112,7 +116,7 @@ export function ProxyRoutesPageClient() {
<div className='flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between'>
<div className='flex items-center gap-2'>
<Route className='size-5 text-primary' />
<h1 className='text-2xl font-semibold tracking-tight'>规则配置</h1>
<h1 className='text-2xl font-semibold tracking-tight'>{t('title')}</h1>
</div>
<div className='flex flex-wrap gap-2'>
<Button
@@ -123,7 +127,7 @@ export function ProxyRoutesPageClient() {
disabled={loading}
>
<RefreshCw className={`size-3 ${loading ? 'animate-spin' : ''}`} />
刷新
{t('refresh')}
</Button>
<Button
size='sm'
@@ -131,7 +135,7 @@ export function ProxyRoutesPageClient() {
onClick={() => setIsCreateOpen(true)}
>
<Plus className='size-3.5' />
新建规则
{t('createRule')}
</Button>
</div>
</div>
@@ -139,11 +143,11 @@ export function ProxyRoutesPageClient() {
<Card className='border-border/40 shadow-sm'>
<CardHeader className='pb-3'>
<div className='flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between'>
<CardTitle className='text-sm font-semibold'>规则列表</CardTitle>
<CardTitle className='text-sm font-semibold'>{t('listTitle')}</CardTitle>
<Input
value={keyword}
onChange={(event) => setKeyword(event.target.value)}
placeholder='搜索站点、域名或上游...'
placeholder={t('searchPlaceholder')}
className='h-8 max-w-sm text-xs'
/>
</div>
@@ -158,23 +162,21 @@ export function ProxyRoutesPageClient() {
) : filteredRoutes.length === 0 ? (
<div className='flex flex-col items-center justify-center gap-2 py-12 text-center'>
<p className='text-sm font-medium'>
{routes.length === 0 ? '暂无网站' : '没有匹配结果'}
{routes.length === 0 ? t('emptyTitle') : t('noMatches')}
</p>
<p className='text-xs text-muted-foreground'>
{routes.length === 0
? '先创建一个网站,再进入配置子页面继续补齐 HTTPS、缓存和限流。'
: '试试调整搜索词,或者清空筛选条件。'}
{routes.length === 0 ? t('emptyDesc') : t('noMatchesDesc')}
</p>
</div>
) : (
<Table>
<TableHeader>
<TableRow>
<TableHead>站点名称</TableHead>
<TableHead>域名</TableHead>
<TableHead>状态</TableHead>
<TableHead>上游</TableHead>
<TableHead className='text-right'>操作</TableHead>
<TableHead>{t('siteName')}</TableHead>
<TableHead>{t('domain')}</TableHead>
<TableHead>{t('status')}</TableHead>
<TableHead>{t('upstream')}</TableHead>
<TableHead className='text-right'>{t('actions')}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
@@ -185,21 +187,21 @@ export function ProxyRoutesPageClient() {
</TableCell>
<TableCell
className='max-w-[220px] truncate'
title={getRouteDomainsLabel(route)}
title={getRouteDomainsLabel(route, t)}
>
{getRoutePrimaryDomain(route) ||
getRouteDomainsLabel(route)}
getRouteDomainsLabel(route, t)}
</TableCell>
<TableCell>
<Badge variant={route.enabled ? 'default' : 'secondary'}>
{route.enabled ? '已启用' : '已停用'}
{route.enabled ? t('enabled') : t('disabled')}
</Badge>
</TableCell>
<TableCell
className='max-w-[280px] truncate'
title={getUpstreamSummary(route)}
title={getUpstreamSummary(route, t)}
>
{getUpstreamSummary(route)}
{getUpstreamSummary(route, t)}
</TableCell>
<TableCell className='text-right'>
<div className='flex justify-end gap-2'>
@@ -210,7 +212,7 @@ export function ProxyRoutesPageClient() {
asChild
>
<Link href={`/proxy-routes/detail?id=${route.id}`}>
配置
{t('configure')}
</Link>
</Button>
<Button
@@ -235,7 +237,7 @@ export function ProxyRoutesPageClient() {
open={isCreateOpen}
onOpenChange={setIsCreateOpen}
onCreated={(route) => {
toast.success('网站已创建');
toast.success(t('siteCreated'));
void fetchRoutes();
router.push(`/proxy-routes/detail?id=${route.id}&section=domains`);
}}
@@ -251,15 +253,15 @@ export function ProxyRoutesPageClient() {
>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>确认删除网站</AlertDialogTitle>
<AlertDialogTitle>{t('deleteSiteTitle')}</AlertDialogTitle>
<AlertDialogDescription>
{deleteTarget
? `确认删除网站 ${deleteTarget.site_name} 吗?这会删除该站点下的全部域名与配置。`
? t('deleteSiteDesc', { name: deleteTarget.site_name })
: null}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={deleting}>取消</AlertDialogCancel>
<AlertDialogCancel disabled={deleting}>{tc('cancel')}</AlertDialogCancel>
<AlertDialogAction
className='bg-destructive text-white hover:bg-destructive/90'
disabled={deleting}
@@ -268,7 +270,7 @@ export function ProxyRoutesPageClient() {
void handleDelete();
}}
>
{deleting ? '删除中...' : '删除'}
{deleting ? t('deleting') : tc('delete')}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>