mirror of
https://github.com/NanmiCoder/claude-code-haha.git
synced 2026-10-10 03:43:11 +08:00
fix(desktop): label the custom provider preset in the active locale
The custom preset showed the catalog's bare English "Custom" in every language and prefilled it as the config name. It now reads "Custom API" (自定义模型 API, etc.) on the chip and in the prefilled name.
This commit is contained in:
@@ -2392,7 +2392,7 @@ describe('Settings > Providers tab', () => {
|
||||
fireEvent.click(addButton)
|
||||
|
||||
const dialog = screen.getByRole('dialog')
|
||||
expect(within(dialog).getByLabelText(/Name/i)).toHaveValue('Custom')
|
||||
expect(within(dialog).getByLabelText(/Name/i)).toHaveValue('Custom API')
|
||||
expect(within(dialog).getByRole('textbox', { name: /Base URL/i })).toBeEnabled()
|
||||
|
||||
const baseUrlInfo = within(dialog).getByRole('button', { name: 'Base URL help' })
|
||||
|
||||
@@ -1442,6 +1442,7 @@ Row 9, all 8 cells: continuing from straight down, turning left through lower-le
|
||||
'settings.providers.regionChina': 'China mainland',
|
||||
'settings.providers.regionGlobal': 'Global',
|
||||
'settings.providers.regionCustom': 'Custom',
|
||||
'settings.providers.customPreset': 'Custom API',
|
||||
'settings.providers.apiKey': 'API Key',
|
||||
'settings.providers.apiKeyKeep': 'API Key (leave blank to keep current)',
|
||||
'settings.providers.showApiKey': 'Show API Key',
|
||||
|
||||
@@ -1443,6 +1443,7 @@ export const jp: Record<TranslationKey, string> = {
|
||||
'settings.providers.regionChina': '中国本土',
|
||||
'settings.providers.regionGlobal': 'グローバル',
|
||||
'settings.providers.regionCustom': 'カスタム',
|
||||
'settings.providers.customPreset': 'カスタム API',
|
||||
'settings.providers.apiKey': 'API キー',
|
||||
'settings.providers.apiKeyKeep': 'API キー(空欄のままにすると現在の値を保持)',
|
||||
'settings.providers.showApiKey': 'API キーを表示',
|
||||
|
||||
@@ -1445,6 +1445,7 @@ export const kr: Record<TranslationKey, string> = {
|
||||
'settings.providers.regionChina': '중국 본토',
|
||||
'settings.providers.regionGlobal': '글로벌',
|
||||
'settings.providers.regionCustom': '사용자 지정',
|
||||
'settings.providers.customPreset': '사용자 지정 API',
|
||||
'settings.providers.apiKey': 'API 키',
|
||||
'settings.providers.apiKeyKeep': 'API 키 (비워 두면 현재 값 유지)',
|
||||
'settings.providers.showApiKey': 'API 키 표시',
|
||||
|
||||
@@ -1442,6 +1442,7 @@ export const zh: Record<TranslationKey, string> = {
|
||||
'settings.providers.regionChina': '中國大陸',
|
||||
'settings.providers.regionGlobal': '海外',
|
||||
'settings.providers.regionCustom': '自訂',
|
||||
'settings.providers.customPreset': '自訂模型 API',
|
||||
'settings.providers.apiKey': 'API 金鑰',
|
||||
'settings.providers.apiKeyKeep': 'API 金鑰(留空保持不變)',
|
||||
'settings.providers.showApiKey': '顯示 API 金鑰',
|
||||
|
||||
@@ -1441,6 +1441,7 @@ export const zh: Record<TranslationKey, string> = {
|
||||
'settings.providers.regionChina': '中国大陆',
|
||||
'settings.providers.regionGlobal': '海外',
|
||||
'settings.providers.regionCustom': '自定义',
|
||||
'settings.providers.customPreset': '自定义模型 API',
|
||||
'settings.providers.apiKey': 'API 密钥',
|
||||
'settings.providers.apiKeyKeep': 'API 密钥(留空保持不变)',
|
||||
'settings.providers.showApiKey': '显示 API 密钥',
|
||||
|
||||
@@ -237,7 +237,19 @@ describe('retired sponsor providers', () => {
|
||||
expect(dialog.queryByRole('button', { name: provider.name })).not.toBeInTheDocument()
|
||||
}
|
||||
expect(dialog.getByRole('button', { name: 'Atlas Cloud' })).toBeInTheDocument()
|
||||
expect(dialog.getByRole('button', { name: 'Custom' })).toBeInTheDocument()
|
||||
expect(dialog.getByRole('button', { name: 'Custom API' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('labels the custom preset in the active locale and prefills that label as the name', async () => {
|
||||
useSettingsStore.setState({ locale: 'zh' })
|
||||
render(<ProviderSettings />)
|
||||
await screen.findByTestId(`provider-${savedProviders[0]!.id}`)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /添加模型/ }))
|
||||
const dialog = within(screen.getByRole('dialog'))
|
||||
expect(dialog.queryByRole('button', { name: 'Custom' })).not.toBeInTheDocument()
|
||||
fireEvent.click(dialog.getByRole('button', { name: '自定义模型 API' }))
|
||||
expect(dialog.getByLabelText(/配置名称/)).toHaveValue('自定义模型 API')
|
||||
})
|
||||
|
||||
it.each(savedProviders)('edits and saves an existing $presetId provider without losing its connection', async (provider) => {
|
||||
|
||||
@@ -1173,6 +1173,10 @@ function ProviderFormModal({ open, onClose, mode, provider, presets, browserMode
|
||||
const initialPreset = provider
|
||||
? availablePresets.find((p) => p.id === provider.presetId) ?? fallbackPreset
|
||||
: selectablePresets[0] ?? fallbackPreset
|
||||
// The custom preset's catalog name is a bare English "Custom"; show a localized
|
||||
// label that says what it is for.
|
||||
const presetLabel = (preset: ProviderPreset) =>
|
||||
preset.id === 'custom' ? t('settings.providers.customPreset') : preset.name
|
||||
const initialModels = stripModel1mMarkers(provider?.models ?? initialPreset.defaultModels)
|
||||
const initialImageGeneration = provider
|
||||
? provider.imageGeneration
|
||||
@@ -1187,7 +1191,7 @@ function ProviderFormModal({ open, onClose, mode, provider, presets, browserMode
|
||||
)
|
||||
|
||||
const [selectedPreset, setSelectedPreset] = useState<ProviderPreset>(initialPreset)
|
||||
const [name, setName] = useState(provider?.name ?? initialPreset.name)
|
||||
const [name, setName] = useState(provider?.name ?? presetLabel(initialPreset))
|
||||
const [baseUrl, setBaseUrl] = useState(provider?.baseUrl ?? initialPreset.baseUrl)
|
||||
// A preset that decides the protocol per model owns this field: the picked value
|
||||
// is only the fallback for models no rule matches, so a record carrying a stale
|
||||
@@ -1349,7 +1353,7 @@ function ProviderFormModal({ open, onClose, mode, provider, presets, browserMode
|
||||
settingsJsonUserEditedRef.current = false
|
||||
setSelectedPreset(preset)
|
||||
setCompatibility(compatibilityForm())
|
||||
setName(preset.name)
|
||||
setName(presetLabel(preset))
|
||||
setBaseUrl(preset.baseUrl)
|
||||
setImageGeneration({
|
||||
enabled: Boolean(preset.defaultImageGeneration),
|
||||
@@ -1687,14 +1691,14 @@ function ProviderFormModal({ open, onClose, mode, provider, presets, browserMode
|
||||
const renderPresetButton = (preset: ProviderPreset) => (
|
||||
<SettingsPill
|
||||
key={preset.id}
|
||||
aria-label={preset.name}
|
||||
aria-label={presetLabel(preset)}
|
||||
className="relative"
|
||||
tone="terracotta"
|
||||
selected={selectedPreset.id === preset.id}
|
||||
onClick={() => handlePresetChange(preset)}
|
||||
>
|
||||
{preset.id === 'aruhub' && <img src={aruhubLogo} alt="" className="size-4 rounded-[var(--radius-sm)] object-contain" />}
|
||||
{preset.name}
|
||||
{presetLabel(preset)}
|
||||
{preset.id === 'aruhub' && <Star size={12} className="fill-[var(--color-warning)] text-[var(--color-warning)]" aria-label={t('settings.providers.sponsor')} />}
|
||||
{preset.isNew && (
|
||||
<Badge tone="warning" size="xs" className="absolute -right-1 -top-2">
|
||||
|
||||
Reference in New Issue
Block a user