feat: choose auto update description and i18n

pull/22133/head
Joel 10 months ago
parent baff25c160
commit dc5e974a78

@ -1,9 +1,12 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback, useMemo } from 'react'
import type { AutoUpdateConfig } from './types' import { AUTO_UPDATE_STRATEGY, type AutoUpdateConfig } from './types'
import Label from '../label' import Label from '../label'
import StrategyPicker from './strategy-picker' import StrategyPicker from './strategy-picker'
import { useTranslation } from 'react-i18next'
const i18nPrefix = 'plugin.autoUpdate'
type Props = { type Props = {
payload: AutoUpdateConfig payload: AutoUpdateConfig
@ -14,7 +17,18 @@ const AutoUpdateSetting: FC<Props> = ({
payload, payload,
onChange, onChange,
}) => { }) => {
const { t } = useTranslation()
const { strategy_setting } = payload const { strategy_setting } = payload
const strategyDescription = useMemo(() => {
switch (strategy_setting) {
case AUTO_UPDATE_STRATEGY.fixOnly:
return t(`${i18nPrefix}.strategy.fixOnly.selectedDescription`)
case AUTO_UPDATE_STRATEGY.latest:
return t(`${i18nPrefix}.strategy.latest.selectedDescription`)
default:
return ''
}
}, [strategy_setting, t])
const handleChange = useCallback((key: keyof AutoUpdateConfig) => { const handleChange = useCallback((key: keyof AutoUpdateConfig) => {
return (value: AutoUpdateConfig[keyof AutoUpdateConfig]) => { return (value: AutoUpdateConfig[keyof AutoUpdateConfig]) => {
onChange({ onChange({
@ -32,15 +46,19 @@ const AutoUpdateSetting: FC<Props> = ({
<div className='space-y-4'> <div className='space-y-4'>
<div className='flex items-center justify-between'> <div className='flex items-center justify-between'>
<Label label='Automatic updates' /> <Label label={t(`${i18nPrefix}.automaticUpdates`)} description={strategyDescription} />
<StrategyPicker value={strategy_setting} onChange={handleChange('strategy_setting')} /> <StrategyPicker value={strategy_setting} onChange={handleChange('strategy_setting')} />
</div> </div>
<div className='flex items-center justify-between'> {strategy_setting !== AUTO_UPDATE_STRATEGY.disabled && (
<Label label='Update time' /> <>
</div> <div className='flex items-center justify-between'>
<div className='flex items-center'> <Label label={t(`${i18nPrefix}.updateTime`)} />
<Label label='Specify plugins to update' /> </div>
</div> <div className='flex items-center'>
<Label label={t(`${i18nPrefix}.specifyPluginsToUpdate`)} />
</div>
</>
)}
</div> </div>
</div> </div>
) )

@ -114,6 +114,9 @@ const translation = {
noone: 'No one', noone: 'No one',
}, },
autoUpdate: { autoUpdate: {
automaticUpdates: 'Automatic updates',
updateTime: 'Update time',
specifyPluginsToUpdate: 'Specify plugins to update',
strategy: { strategy: {
disabled: { disabled: {
name: 'Disabled', name: 'Disabled',
@ -122,10 +125,12 @@ const translation = {
fixOnly: { fixOnly: {
name: 'Fix Only', name: 'Fix Only',
description: 'Auto-update for patch versions only (e.g., 1.0.1 → 1.0.2). Minor version changes won\'t trigger updates.', description: 'Auto-update for patch versions only (e.g., 1.0.1 → 1.0.2). Minor version changes won\'t trigger updates.',
selectedDescription: 'Auto-update for patch versions only',
}, },
latest: { latest: {
name: 'Latest', name: 'Latest',
description: 'Always update to latest version', description: 'Always update to latest version',
selectedDescription: 'Always update to latest version',
}, },
}, },
}, },

@ -113,6 +113,27 @@ const translation = {
admins: '管理员', admins: '管理员',
noone: '无人', noone: '无人',
}, },
autoUpdate: {
automaticUpdates: '自动更新',
updateTime: '更新时间',
specifyPluginsToUpdate: '指定要更新的插件',
strategy: {
disabled: {
name: '禁用',
description: '插件将不会自动更新',
},
fixOnly: {
name: '仅修复',
description: '仅自动更新补丁版本例如1.0.1 → 1.0.2)。次要版本更改不会触发更新。',
selectedDescription: '仅自动更新补丁版本',
},
latest: {
name: '最新',
description: '始终更新到最新版本',
selectedDescription: '始终更新到最新版本',
},
},
},
pluginInfoModal: { pluginInfoModal: {
title: '插件信息', title: '插件信息',
repository: '仓库', repository: '仓库',

Loading…
Cancel
Save