i18n: complete internationalization for provider and usage query panels

- Add 45+ new translation keys for usage query and usage script features
- Fix duplicate provider object in translation files that caused missing translations
- Remove all hardcoded Chinese text and defaultValue fallbacks from components
- Add proper translations for:
  * Usage footer (query status, plan usage display)
  * Usage script modal (script editor, validation, test controls)
  * Provider forms (basic fields, endpoints, model selectors)
  * Provider dialogs (add/edit hints and titles)

Modified 16 files:
- 2 translation files (zh.json, en.json)
- 14 component files (removed defaultValue, added t() calls)

All UI text now properly supports Chinese/English switching.
This commit is contained in:
Jason
2025-10-19 11:55:46 +08:00
parent bae6a1cf55
commit eb6948a562
16 changed files with 176 additions and 125 deletions

View File

@@ -135,8 +135,8 @@ export function AddProviderDialog({
const submitLabel =
appType === "claude"
? t("provider.addClaudeProvider", { defaultValue: "添加 Claude 供应商" })
: t("provider.addCodexProvider", { defaultValue: "添加 Codex 供应商" });
? t("provider.addClaudeProvider")
: t("provider.addCodexProvider");
return (
<Dialog open={open} onOpenChange={onOpenChange}>
@@ -144,16 +144,14 @@ export function AddProviderDialog({
<DialogHeader>
<DialogTitle>{submitLabel}</DialogTitle>
<DialogDescription>
{t("provider.addDescription", {
defaultValue: "填写信息后即可在列表中快速切换供应商。",
})}
{t("provider.addProviderHint")}
</DialogDescription>
</DialogHeader>
<div className="flex-1 overflow-y-auto px-6 py-4">
<ProviderForm
appType={appType}
submitLabel={t("common.add", { defaultValue: "添加" })}
submitLabel={t("common.add")}
onSubmit={handleSubmit}
onCancel={() => onOpenChange(false)}
showButtons={false}
@@ -162,11 +160,11 @@ export function AddProviderDialog({
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
{t("common.cancel", { defaultValue: "取消" })}
{t("common.cancel")}
</Button>
<Button type="submit" form="provider-form">
<Plus className="h-4 w-4" />
{t("common.add", { defaultValue: "添加" })}
{t("common.add")}
</Button>
</DialogFooter>
</DialogContent>

View File

@@ -66,19 +66,17 @@ export function EditProviderDialog({
<DialogContent className="max-w-2xl max-h-[90vh] flex flex-col">
<DialogHeader>
<DialogTitle>
{t("provider.editProvider", { defaultValue: "编辑供应商" })}
{t("provider.editProvider")}
</DialogTitle>
<DialogDescription>
{t("provider.editDescription", {
defaultValue: "更新配置后将立即应用到当前供应商。",
})}
{t("provider.editProviderHint")}
</DialogDescription>
</DialogHeader>
<div className="flex-1 overflow-y-auto px-6 py-4">
<ProviderForm
appType={appType}
submitLabel={t("common.save", { defaultValue: "保存" })}
submitLabel={t("common.save")}
onSubmit={handleSubmit}
onCancel={() => onOpenChange(false)}
initialData={{
@@ -92,11 +90,11 @@ export function EditProviderDialog({
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
{t("common.cancel", { defaultValue: "取消" })}
{t("common.cancel")}
</Button>
<Button type="submit" form="provider-form">
<Save className="h-4 w-4" />
{t("common.save", { defaultValue: "保存" })}
{t("common.save")}
</Button>
</DialogFooter>
</DialogContent>

View File

@@ -35,25 +35,25 @@ export function ProviderActions({
{isCurrent ? (
<>
<Check className="h-4 w-4" />
{t("provider.inUse", { defaultValue: "已启用" })}
{t("provider.inUse")}
</>
) : (
<>
<Play className="h-4 w-4" />
{t("provider.enable", { defaultValue: "启用" })}
{t("provider.enable")}
</>
)}
</Button>
<Button size="sm" variant="outline" onClick={onEdit}>
{t("common.edit", { defaultValue: "编辑" })}
{t("common.edit")}
</Button>
<Button
size="sm"
variant="outline"
onClick={onConfigureUsage}
title={t("provider.configureUsage", { defaultValue: "配置用量查询" })}
title={t("provider.configureUsage")}
>
<BarChart3 className="h-4 w-4" />
</Button>

View File

@@ -104,7 +104,7 @@ export function ProviderCard({
"mt-1 flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-muted-foreground transition-colors hover:border-muted hover:text-foreground",
dragHandleProps?.isDragging && "border-primary text-primary",
)}
aria-label={t("provider.dragHandle", { defaultValue: "拖拽排序" })}
aria-label={t("provider.dragHandle")}
{...(dragHandleProps?.attributes ?? {})}
{...(dragHandleProps?.listeners ?? {})}
>
@@ -118,7 +118,7 @@ export function ProviderCard({
</h3>
{isCurrent && (
<span className="rounded-full bg-green-500/10 px-2 py-0.5 text-xs font-medium text-green-500 dark:text-green-400">
{t("provider.currentlyUsing", { defaultValue: "当前使用" })}
{t("provider.currentlyUsing")}
</span>
)}
</div>

View File

@@ -15,16 +15,14 @@ export function ProviderEmptyState({ onCreate }: ProviderEmptyStateProps) {
<Users className="h-7 w-7 text-muted-foreground" />
</div>
<h3 className="text-lg font-semibold">
{t("provider.noProviders", { defaultValue: "暂无供应商" })}
{t("provider.noProviders")}
</h3>
<p className="mt-2 max-w-sm text-sm text-muted-foreground">
{t("provider.noProvidersDescription", {
defaultValue: "开始添加一个供应商以快速完成切换。",
})}
{t("provider.noProvidersDescription")}
</p>
{onCreate && (
<Button className="mt-6" onClick={onCreate}>
{t("provider.addProvider", { defaultValue: "添加供应商" })}
{t("provider.addProvider")}
</Button>
)}
</div>

View File

@@ -25,14 +25,12 @@ export function BasicFormFields({ form }: BasicFormFieldsProps) {
render={({ field }) => (
<FormItem>
<FormLabel>
{t("provider.name", { defaultValue: "供应商名称" })}
{t("provider.name")}
</FormLabel>
<FormControl>
<Input
{...field}
placeholder={t("provider.namePlaceholder", {
defaultValue: "例如Claude 官方",
})}
placeholder={t("provider.namePlaceholder")}
/>
</FormControl>
<FormMessage />
@@ -46,7 +44,7 @@ export function BasicFormFields({ form }: BasicFormFieldsProps) {
render={({ field }) => (
<FormItem>
<FormLabel>
{t("provider.websiteUrl", { defaultValue: "官网链接" })}
{t("provider.websiteUrl")}
</FormLabel>
<FormControl>
<Input {...field} placeholder="https://" />

View File

@@ -137,15 +137,11 @@ export function ClaudeFormFields({
{shouldShowSpeedTest && (
<EndpointField
id="baseUrl"
label={t("providerForm.apiEndpoint", { defaultValue: "API 端点" })}
label={t("providerForm.apiEndpoint")}
value={baseUrl}
onChange={onBaseUrlChange}
placeholder={t("providerForm.apiEndpointPlaceholder", {
defaultValue: "https://api.example.com",
})}
hint={t("providerForm.apiHint", {
defaultValue: "API 端点地址用于连接服务器",
})}
placeholder={t("providerForm.apiEndpointPlaceholder")}
hint={t("providerForm.apiHint")}
onManageClick={() => onEndpointModalToggle(true)}
/>
)}

View File

@@ -68,15 +68,11 @@ export function CodexFormFields({
{shouldShowSpeedTest && (
<EndpointField
id="codexBaseUrl"
label={t("codexConfig.apiUrlLabel", { defaultValue: "API 端点" })}
label={t("codexConfig.apiUrlLabel")}
value={codexBaseUrl}
onChange={onBaseUrlChange}
placeholder={t("providerForm.codexApiEndpointPlaceholder", {
defaultValue: "https://api.example.com/v1",
})}
hint={t("providerForm.codexApiHint", {
defaultValue: "Codex API 端点地址",
})}
placeholder={t("providerForm.codexApiEndpointPlaceholder")}
hint={t("providerForm.codexApiHint")}
onManageClick={() => onEndpointModalToggle(true)}
/>
)}

View File

@@ -51,7 +51,7 @@ export function CommonConfigEditor({
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label htmlFor="settingsConfig">
{t("provider.configJson", { defaultValue: "配置 JSON" })}
{t("provider.configJson")}
</Label>
<div className="flex items-center gap-2">
<label className="inline-flex items-center gap-2 text-sm text-muted-foreground cursor-pointer">

View File

@@ -554,7 +554,7 @@ export function ProviderForm({
{showButtons && (
<div className="flex justify-end gap-2">
<Button variant="outline" type="button" onClick={onCancel}>
{t("common.cancel", { defaultValue: "取消" })}
{t("common.cancel")}
</Button>
<Button type="submit">{submitLabel}</Button>
</div>

View File

@@ -28,7 +28,7 @@ export function ProviderPresetSelector({
return (
<div className="space-y-3">
<FormLabel>
{t("providerPreset.label", { defaultValue: "预设供应商" })}
{t("providerPreset.label")}
</FormLabel>
<div className="flex flex-wrap gap-2">
{/* 自定义按钮 */}
@@ -41,7 +41,7 @@ export function ProviderPresetSelector({
: "bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700"
}`}
>
{t("providerPreset.custom", { defaultValue: "自定义配置" })}
{t("providerPreset.custom")}
</button>
{/* 预设按钮 */}