fix(i18n): use English runtime text and localize system UI

This commit is contained in:
Arthur Koba
2026-10-25 19:44:15 +03:00
parent ada0550571
commit 65a96670d5
289 changed files with 8092 additions and 3426 deletions
@@ -40,6 +40,8 @@ export function AuthSourceModal({
onClose: () => void;
onChanged: () => Promise<void>;
}) {
const rt = useTranslations('runtime');
const t = useTranslations('settings.authSourceModal');
const [form, setForm] = useState<AuthSourceRequest>(emptyForm);
const [saving, setSaving] = useState(false);
@@ -108,7 +110,7 @@ export function AuthSourceModal({
onChange={(e) =>
setForm((prev) => ({ ...prev, name: e.target.value }))
}
placeholder='例如: github'
placeholder={rt('for_example_github_1061e2e4')}
/>
</div>
<div className='space-y-2'>
@@ -118,7 +120,7 @@ export function AuthSourceModal({
onChange={(e) =>
setForm((prev) => ({ ...prev, display_name: e.target.value }))
}
placeholder='例如: GitHub 登录'
placeholder={rt('for_example_github_login_1e0c113c')}
/>
</div>
<div className='space-y-2'>
@@ -169,7 +171,7 @@ export function AuthSourceModal({
onChange={(e) =>
setForm((prev) => ({ ...prev, icon_url: e.target.value }))
}
placeholder='https://... 或留空'
placeholder={rt('https_or_leave_empty_a0d86d9b')}
/>
</div>
<div className='flex items-center justify-between rounded-xl border border-dashed p-3 md:col-span-2 bg-muted/10'>
@@ -60,6 +60,8 @@ export function OperationTab({
configs,
systemConfigsQuery,
}: OperationTabProps) {
const rt = useTranslations('runtime');
const queryClient = useQueryClient();
const t = useTranslations('settings.operation');
@@ -108,7 +110,9 @@ export function OperationTab({
}
const config = businessConfigs[field.key];
if (!config) {
throw new Error(`缺少配置项: ${field.key}`);
throw new Error(
rt('missing_configuration_value0_31b43fa6', { value0: field.key }),
);
}
await services.adminSystemConfig.updateSystemConfig(field.key, {
value: String(num),
@@ -131,7 +135,9 @@ export function OperationTab({
mutationFn: async (newValue: string) => {
const config = configs['file_access_whitelist'];
if (!config) {
throw new Error('缺少配置项: file_access_whitelist');
throw new Error(
rt('missing_configuration_file_access_whitelist_6dd80936'),
);
}
await services.adminSystemConfig.updateSystemConfig(
'file_access_whitelist',
@@ -207,6 +207,8 @@ interface OtherTabProps {
}
export function OtherTab({ configs }: OtherTabProps) {
const rt = useTranslations('runtime');
const queryClient = useQueryClient();
const t = useTranslations('settings.other');
const tNav = useTranslations('layout.nav');
@@ -237,7 +239,9 @@ export function OtherTab({ configs }: OtherTabProps) {
value: JSON.stringify(newConfig),
description:
currentCfg?.description ||
'目录显示配置(JSON 字符串,格式为 {url: enabled})',
rt.raw(
'directory_visibility_configuration_json_string_format_url_8e3c0671',
),
},
);
},
@@ -336,7 +340,7 @@ export function OtherTab({ configs }: OtherTabProps) {
<div className='text-xs text-muted-foreground leading-relaxed'>
<span className='font-semibold text-foreground'>
{t('securityTipTitle')}
</span>
</span>{' '}
{t('securityTipDesc')}
</div>
</div>
@@ -101,6 +101,8 @@ interface SecurityTabProps {
}
export function SecurityTab({ configs, systemConfigsQuery }: SecurityTabProps) {
const rt = useTranslations('runtime');
const queryClient = useQueryClient();
const t = useTranslations('settings.security');
const tCommon = useTranslations('common');
@@ -154,7 +156,9 @@ export function SecurityTab({ configs, systemConfigsQuery }: SecurityTabProps) {
mutationFn: async (value: string) => {
const config = configs['login_session_ttl_hours'];
if (!config) {
throw new Error('缺少配置项: login_session_ttl_hours');
throw new Error(
rt('missing_configuration_login_session_ttl_hours_d6f433c2'),
);
}
await services.adminSystemConfig.updateSystemConfig(
'login_session_ttl_hours',
@@ -203,7 +207,9 @@ export function SecurityTab({ configs, systemConfigsQuery }: SecurityTabProps) {
mutationFn: async ({ key, value }: { key: string; value: boolean }) => {
const config = configs[key];
if (!config) {
throw new Error(`缺少配置项: ${key}`);
throw new Error(
rt('missing_configuration_value0_31b43fa6', { value0: key }),
);
}
await services.adminSystemConfig.updateSystemConfig(key, {
value: value ? 'true' : 'false',
@@ -39,6 +39,8 @@ interface SystemTabProps {
}
export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
const rt = useTranslations('runtime');
const queryClient = useQueryClient();
const t = useTranslations('settings.system');
const [serverAddress, setServerAddress] = useState('');
@@ -75,7 +77,9 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
mutationFn: async ({ key, value }: { key: string; value: boolean }) => {
const config = configs[key];
if (!config) {
throw new Error(`缺少配置项: ${key}`);
throw new Error(
rt('missing_configuration_value0_31b43fa6', { value0: key }),
);
}
await services.adminSystemConfig.updateSystemConfig(key, {
value: value ? 'true' : 'false',
@@ -101,11 +105,13 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
await Promise.all([
services.adminSystemConfig.updateSystemConfig('server_address', {
value: serverAddress,
description: currentAddrCfg?.description || '服务器地址',
description:
currentAddrCfg?.description || rt('server_address_d3716cc5'),
}),
services.adminSystemConfig.updateSystemConfig('site_name', {
value: siteName,
description: currentSiteCfg?.description || '系统平台的展示名称',
description:
currentSiteCfg?.description || rt('platform_display_name_4b656edf'),
}),
]);
},
@@ -249,7 +255,7 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
type='text'
value={siteName}
onChange={(e) => setSiteName(e.target.value)}
placeholder='例如: OpenFlare'
placeholder={rt('for_example_openflare_28e07341')}
className='border-dashed bg-card text-xs'
/>
<p className='text-[11px] leading-relaxed text-muted-foreground'>
@@ -281,7 +287,7 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
type='url'
value={serverAddress}
onChange={(e) => setServerAddress(e.target.value)}
placeholder='例如: https://example.com'
placeholder={rt('for_example_https_example_com_9cf31711')}
className='border-dashed bg-card text-xs'
/>
<p className='text-[11px] leading-relaxed text-muted-foreground'>
@@ -313,7 +319,9 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
</div>
<Switch
aria-label='允许搜索引擎抓取与收录'
aria-label={rt(
'allow_search_engines_to_crawl_and_index_59eff8b5',
)}
checked={indexingEnabled}
disabled={
updateConfigMutation.isPending || systemConfigsQuery.isPending
@@ -383,7 +391,7 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
type='text'
value={smtpHost}
onChange={(e) => setSmtpHost(e.target.value)}
placeholder='例如: smtp.example.com'
placeholder={rt('for_example_smtp_example_com_834569b4')}
className='bg-card border-dashed text-xs'
/>
</div>
@@ -397,7 +405,7 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
type='number'
value={smtpPort}
onChange={(e) => setSmtpPort(e.target.value)}
placeholder='例如: 587 或 465'
placeholder={rt('for_example_587_or_465_1bd015a5')}
className='bg-card border-dashed text-xs'
/>
</div>
@@ -414,7 +422,7 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
type='text'
value={smtpUsername}
onChange={(e) => setSmtpUsername(e.target.value)}
placeholder='例如: sender@example.com'
placeholder={rt('for_example_sender_example_com_1795f7c6')}
className='bg-card border-dashed text-xs'
/>
</div>
@@ -498,7 +506,7 @@ export function SystemTab({ configs, systemConfigsQuery }: SystemTabProps) {
required
value={smtpTestTo}
onChange={(e) => setSmtpTestTo(e.target.value)}
placeholder='例如: receiver@example.com'
placeholder={rt('for_example_receiver_example_com_ade0ff8b')}
className='bg-card border-dashed text-xs'
disabled={testSmtpMutation.isPending}
/>
@@ -36,9 +36,13 @@ import {
import services from '@/lib/services';
import type { Template } from '@/lib/services/admin/types';
import { toast } from 'sonner';
import { useTranslations } from 'next-intl';
import { useLocale, useTranslations } from 'next-intl';
import { localizeTemplateMetadata } from '@/i18n/builtin-metadata';
export function TemplatesManager() {
const rt = useTranslations('runtime');
const locale = useLocale();
const queryClient = useQueryClient();
const t = useTranslations('settings.templates');
const [modalOpen, setModalOpen] = useState(false);
@@ -191,7 +195,13 @@ export function TemplatesManager() {
<div className='space-y-1.5'>
<div className='flex items-center gap-2 flex-wrap'>
<span className='font-semibold text-sm text-foreground'>
{tmpl.name}
{localizeTemplateMetadata(
tmpl.key,
tmpl.is_system,
'name',
tmpl.name,
locale,
)}
</span>
<span
className={`text-[10px] px-2 py-0.5 rounded-full border font-medium ${
@@ -215,7 +225,13 @@ export function TemplatesManager() {
</div>
{tmpl.description && (
<p className='text-xs text-muted-foreground/80 leading-relaxed max-w-xl'>
{tmpl.description}
{localizeTemplateMetadata(
tmpl.key,
tmpl.is_system,
'description',
tmpl.description,
locale,
)}
</p>
)}
</div>
@@ -226,6 +242,7 @@ export function TemplatesManager() {
size='icon'
className='size-8 text-muted-foreground hover:text-primary hover:bg-primary/10 rounded-lg transition-colors'
onClick={() => handleOpenEdit(tmpl)}
aria-label={t('editTemplate')}
>
<Pencil className='size-4' />
</Button>
@@ -238,6 +255,7 @@ export function TemplatesManager() {
tmpl.is_system || deleteTemplateMutation.isPending
}
onClick={() => setDeleteTarget(tmpl)}
aria-label={t('deleteTemplateTitle')}
>
<Trash2 className='size-4' />
</Button>
@@ -286,7 +304,7 @@ export function TemplatesManager() {
required
value={key}
onChange={(e) => setKey(e.target.value)}
placeholder='例如: login_email'
placeholder={rt('for_example_login_email_c7212e1f')}
className='bg-card border-dashed text-xs'
disabled={!!selectedTemplate}
/>
@@ -303,9 +321,17 @@ export function TemplatesManager() {
id='tmpl_name'
type='text'
required
value={name}
value={localizeTemplateMetadata(
key,
!!selectedTemplate?.is_system,
'name',
name,
locale,
)}
onChange={(e) => setName(e.target.value)}
placeholder='例如: 登录验证码邮件'
placeholder={rt(
'for_example_login_verification_email_9d28f166',
)}
className='bg-card border-dashed text-xs'
/>
<p className='text-[10px] text-muted-foreground leading-normal'>
@@ -340,7 +366,9 @@ export function TemplatesManager() {
type='text'
value={subject}
onChange={(e) => setSubject(e.target.value)}
placeholder='例如: OpenFlare 登录验证码'
placeholder={rt(
'for_example_openflare_login_verification_code_0925e8d4',
)}
className='bg-card border-dashed text-xs'
/>
<p className='text-[10px] text-muted-foreground leading-normal'>
@@ -359,9 +387,17 @@ export function TemplatesManager() {
<Input
id='tmpl_description'
type='text'
value={description}
value={localizeTemplateMetadata(
key,
!!selectedTemplate?.is_system,
'description',
description,
locale,
)}
onChange={(e) => setDescription(e.target.value)}
placeholder='例如: 包含变量:{{.Code}},5分钟内有效'
placeholder={rt.raw(
'for_example_your_code_is_code_valid_44cf273f',
)}
className='bg-card border-dashed text-xs'
/>
</div>
@@ -375,7 +411,9 @@ export function TemplatesManager() {
required
value={content}
onChange={(e) => setContent(e.target.value)}
placeholder='<h3>正文标题</h3><p>内容段落,可用变量 {{.Code}}</p>'
placeholder={rt.raw(
'h3_message_title_h3_p_message_content_20c91d04',
)}
rows={8}
className='bg-card border-dashed text-xs font-mono'
/>